how to traverse an image in 2x2 block wise wayand then check suitable conditions?

i am actually working for coloring a grayscale image.

2 Kommentare

Please ask one question only and edit it, if you want to add useful information.
duplicate with more information is at http://www.mathworks.com/matlabcentral/answers/11904-how-to-divide-an-image-into-2x2-blocks-and-then-work-on-each-block-seperately-pixel-by-pixel

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

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);

1 Kommentar

Will this work for any image? Actually , i want to traverse the image into 2x2 block manner and then on each of those blocks i need to theck that among the 4 pixels , if a single pixel is colored then the rest 3 are given value of the colored one and if more than one are colored then an average of them is to be given to all 4 pixels... getting me?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

doc imfilter
doc conv2
doc blkproc

1 Kommentar

Thanks a lot but i have tried with blockproc.. This command does not allowes me to extract each block separately and then work on it individually.

Melden Sie sich an, um zu kommentieren.

This is the code which i got from some where, have tried this out but it only wokrs for 2x2 blocks..:-
[row , col] =size(img);
blocksize =2;
nob = (row/blocksize) * (col /blocksize);
kk=0; for i=1:(row/blocksize) for j=1:(col/blocksize) Block(:,:,kk+j)=img((blocksize*(i-1)+1:blocksize*(i-1)+blocksize),(blocksize*(j-1)+1:blocksize*(j-1)+blocksize)); end kk=kk+(row/blocksize); end
% Accessing individual Blocks % for p =1 : nob % figure % imshow(Block(:,:,p)); % end

Community Treasure Hunt

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

Start Hunting!

Translated by