how to divide the rgb(color) image to 8X8 blocks using for loop or any other technique
이전 댓글 표시
i simply want to divide the given image(color) into blocks
답변 (1개)
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.
카테고리
도움말 센터 및 File Exchange에서 Neighborhood and Block Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!