how to divide the rgb(color) image to 8X8 blocks using for loop or any other technique
1 view (last 30 days)
Show older comments
i simply want to divide the given image(color) into blocks
0 Comments
Answers (1)
Jan
on 26 Sep 2013
Edited: Jan
on 26 Sep 2013
img = rand(1024, 768, 3); % RGB image
siz = size(img);
Block = reshape(img, 8, siz(1)/8, 8, siz(2)/8, siz(3));
Block = permute(Block, [2,4,5,1,3]);
Now you have the block at position i, j as:
Block(:, :, :, i, j);
When you want it as cell array. mat2cell helps, but a simple FOR loop does it also:
sizeBlock = size(Block);
C = cell(sizeBlock(4:5));
for ix = 1:sizeBlock(4)
for iy = 1:sizeBlock(5)
C{ix, iy} = Block(:, :, :, ix, iy);
end
end
If the dimension lengths are not multiple by 8, you have to define, what should happen with the margin.
Please note: While I appreciate this forum without doubt, I want to stress, that an internet search engine can find such solutions much faster. E.g.: https://www.google.com/search?q=Matlab+image+to+block , with took 0.26 seconds to find 10 million matching pages. Even if only 1000 of them will be matching the problem exactly enough, it is worth to perform some web research before asking the forum.
0 Comments
See Also
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!