Matlab-8x8窗口并寻找均值 [英] Matlab - 8x8 window and finding mean
问题描述
说我有一个图像矩阵,我想做以下事情:
Say I have a matrix of an image, and I want to do the following:
- 在矩阵上滑动
8x8
窗口 - 计算矩阵中每个像素的平均值
如果我是Matlab编码的新手,那么如何在matlab
中做到这一点.
How can I do that in matlab
, provided that I'm kind of new to coding in matlab.
谢谢.
推荐答案
You can also use nlfilter
:
fun = @(x) mean(x(:));
ans= nlfilter(img,[8 8],fun);
但是,正如@ s.bandara所建议的,conv2
的计算速度快得多,...用于计算均值...
请注意,将conv2
与valid
一起使用时,矩阵大小将发生变化.
But as @s.bandara suggested, the conv2
is much faster for just calculating the mean...
Note that the matrix size will change when using the conv2
with valid
.
nlfilter
经过时间为0.433989秒.
nlfilter
Elapsed time is 0.433989 seconds.
conv2
经过时间为0.000803秒.
conv2
Elapsed time is 0.000803 seconds.
因此很明显,对于寻找均值的任务,conv2
要快得多.
So it is pretty obvious that for the task of finding the mean, conv2
is much much faster.
这篇关于Matlab-8x8窗口并寻找均值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!