【问题标题】:Find the mean value in image window在图像窗口中查找平均值
【发布时间】:2014-04-19 02:18:00
【问题描述】:

我需要在 matlab 的 32x32 窗口中分割图像。

然后我需要获取该窗口内图像的平均强度值并显示它。我不需要对图像应用均值滤波器。

这是我的算法:

Split image into window sizes of 32x32
  if mean intensity of pixels in 32x32window > 200
    split 32x32 window into 8x8 windows.
  end 

这是我尝试过的:

kernel = ones(32)/32^2; % Create averaging window.
output = conv2(grayImage, kernel, 'same'); % Get means
mean=mean(mean(output);
display (mean)

但是,这只是对我的图像应用过滤器。也试过这个:

window_size = 16; 
wsz = window_size-1;
mp = round(window_size/2);

img = rgb2gray(input_image); %%// Gray level values
x1 = zeros(size(img)); %%// Row values for the maximum pixel in the 16x16 window
y1 = zeros(size(img)); %%// Column values for the maximum pixel in the 16x16 window

img1 = img;
for k1= 1:size(img,1)-wsz
    for k2= 1:size(img,2)-wsz
        window_data = img(k1:k1+wsz,k2:k2+wsz);        
        val = round(mean(window_data(:)));
        display(val);
    end
end

但此代码返回 0 表示每个窗口的平均强度。

任何人都可以建议一种方法吗?

【问题讨论】:

    标签: matlab image-processing


    【解决方案1】:

    如果您想获得 32x32 块中图像的平均强度值,您可以使用blkproc。这是一个例子;

    a = rand(256);
    f = @(x) mean(mean(x))
    
    f = 
    
        @(x)mean(mean(x))
    
    a = blkproc(a,[32 32],f);
    a = rand(256);
    f = @(x) mean(mean(x))
    
    f = 
    
        @(x)mean(mean(x))
    
    a2 = blkproc(a,[32 32],f);
    a2(1,1) % mean first block
    
    ans =
    
        0.4956
    
    m = mean(mean(a(1:32,1:32))) % mean first block
    
    m =
    
        0.4956
    

    下一个块将是a(1:32,33:64),其平均值为a(1,2),等等。

    【讨论】:

      猜你喜欢
      • 2021-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 2018-02-11
      • 2014-04-24
      • 2020-03-29
      • 1970-01-01
      相关资源
      最近更新 更多