I have an image of 256*256.I have to divide the image into sub blocks of size W * W,where W=3,4,.....27 according to the given overlapping rules below:
if W<8 thn no overlapping of blocks
if 8<=W<=13 thn 50% overlapping of blocks
if W>13 thn 75% overlapping of blocks
how to implement it in matlab,particularly in 2nd and in 3rd rule
Asked
Active
Viewed 1,666 times
3

user1085661
- 31
- 2
1 Answers
2
The quickest and simplest way of achieving something like what you're interested in is as follows:
function blocks = DivideImage(im, W)
if W <= 7
step = W;
elseif W <= 13
step = round(0.25 * W);
else
step = round(0.125 * W);
end
startPos = 0:step:size(im,1)-W;
blocks = cell(numel(startPos), numel(startPos));
for i = 1:numel(startPos)
for j = 1:numel(startPos)
blocks{i,j} = im(startPos(i)+(1:W), startPos(j)+(1:W));
end
end
Note that when W
doesn't divide exactly into size(im,1)
then it will drop some of the points from the right and bottom edges, so you will want to look again at how it's setting the values of startPos
.

Nzbuu
- 5,241
- 1
- 29
- 51