在Matlab中将图像分成块

时间:2016-03-21 19:26:43

标签: matlab image-processing

我有来自图像的数据集,每个图像昏暗是240x180,我想在每个图像上进行一些处理但是在将每个图像分成子图像(块)之后,每个块必须具有20x20的这个尺寸所以我应该有108个从每个图像块,我写了这段代码,但我不知道为什么结果的大小只包含原始图像的84个块,它必须有108个块,并且循环内的条件是正确的。

Img=imread('imagefile.extension'); % read image 240x180
[r c]=size(Img);  % r=180 , c=240
bs=20; % Each Block Size (20x20)

nob=(r/bs)*(c/bs); %The total number of 20x20 Blocks = 108

% Dividing the image into 20x20 Blocks
BNo=0;
for i=1:(r/bs)
for j=1:(c/bs)
Block(:,:,BNo+j)=Img((bs*(i-1)+1:bs*(i-1)+bs),(bs*(j-1)+1:bs*(j-1)+bs));
end
BNo=BNo+(r/bs);
end

0 个答案:

没有答案
相关问题