Info

This question is closed. Reopen it to edit or answer.

I have 256*256 image. I had converted into 4*4 blocks. Now I have 64 blocks. And also I had converted each 4X4 into 16X1 linear array. Now I have 256 linear arrays, each have 16*1. I want to calculate mean value of first 8 arrays, then next 8 array

1 view (last 30 days)
I=imread('cameraman.tif');
I=double(I);
Im=size(I);
%find the size of the image
[nr nc nd]=size(I);
% Divide into blocks
disp(nr);
disp(nc);
% Divide into blocks
m=64;
n=64;
row=1;
column=1;
i=1;
j=1;
nn=0;
for i=1:4:nr-3
for j=1:4:nc-3
block=I(i:i+3,j:j+3);
disp(block)
%convert 4X4 into 16X1 column vector
tv=reshape(block,16,1);
disp(tv)
column=column+4;
% R = blkproc(tv,[1 8],@(x) mean(x(:)))
end
row=row+4;
end
%B=mean(tv,[])
%B=sepblockfun(I,[4,2],'mean');
disp(i)
disp(j)
R = blkproc(tv,[1 8],@(x) mean(x(:)))

Answers (1)

Walter Roberson
Walter Roberson on 11 Feb 2016
by_blocks = mat2cell(YourImage, 4 * repmat(1,64), 4 * repmat(1,64), size(YourImage, 3));
linear_by_blocks = cellfun(@(B) B(:), by_blocks, 'Uniform', 0);
means = arrayfun(@(idx) mean(horzcat(linear_by_blocks{idx:idx+7}),2), 1:8:numel(linear_by_blocks), 'Uniform', 0);

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!