Dividing image into blocks and calculating mean values
1 次查看(过去 30 天)
显示 更早的评论
i have 256*256 image. i've converted into 4*4 blocks and also converted into 16*1 linear array. now i need code to calculate mean value of 1 to 8 rows, then 9 to 16 rows,... like this.. please send suitable code. i am using the code given below.
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;
end
row=row+4;
B(:,nn+1) = mean(tv(:,nn*8+1:(nn+1)*8),2);
end
disp(i)
disp(j)
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;
end
row=row+4;
B(:,nn+1) = mean(tv(:,nn*8+1:(nn+1)*8),2);
end
disp(i)
disp(j)
0 个评论
回答(2 个)
Image Analyst
2016-2-10
The first 8 rows of a 4x4 block you converted into a 16*1 array is essentially the left half of the 4x4 block. In other words, a 4x2 block. This mean can be done with blockproc(). See my attached demos for several ways to use blockproc. One of them takes the means in blocks and you just need to change the block size in the demo to 4 rows and 2 columns. The whole thing should just be about 2 to 4 lines of code.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Computer Vision with Simulink 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!