how to divide the rgb(color) image to 8X8 blocks using for loop or any other technique
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
i simply want to divide the given image(color) into blocks
0 Commenti
Risposte (1)
Jan
il 26 Set 2013
Modificato: Jan
il 26 Set 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 Commenti
Vedere anche
Categorie
Scopri di più su Convert Image Type in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!