0
votes

I need to split an image in windows of 32x32 in matlab.

I then need to get the average intensity value of images within that window and just display it. I do not need to apply a mean filter to the image.

Here is my algorithm:

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

This is what I have tried:

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

However this just applies a filter to my image. Also tried this:

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

But this code returns 0 for the average intensity of each window.

Can anyone please suggest a way of doing this?

1

1 Answers

0
votes

If you want to get the mean intensity values of the image in 32x32 blocks you can use blkproc. Here is an example;

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

The next block over would be a(1:32,33:64) which would have mean value in a(1,2), etc.