MATLAB: How to traverse an image in 2×2 block wise wayand then check suitable conditions

blockwise traversalduplicate post requiring merging

i am actually working for coloring a grayscale image.

Best Answer

Img = rand(640, 480);
Img = reshape(X, 2, 320, 2, 240);
B = permute(Img, [1, 3, 2, 4]);
for i = 1:320
for j = 1:240
aBlock = B(:, :, i, j);
...
end
end
Img2 = ipermute(Block, [1, 3, 2, 4]);
Img2 = reshape(Img2, 640, 480);