how to divide the rgb(color) image to 8X8 blocks using for loop or any other technique
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
i simply want to divide the given image(color) into blocks
0 comentarios
Respuestas (1)
Jan
el 26 de Sept. de 2013
Editada: Jan
el 26 de Sept. de 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 comentarios
Ver también
Categorías
Más información sobre Convert Image Type en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!