how to divide the rgb(color) image to 8X8 blocks using for loop or any other technique

답변 (1개)

Jan
Jan 2013년 9월 26일
편집: Jan 2013년 9월 26일
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.

태그

질문:

2013년 9월 26일

편집:

Jan
2013년 9월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by