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

7 vues (au cours des 30 derniers jours)
i am actually working for coloring a grayscale image.
  2 commentaires
Jan
Jan le 19 Juil 2011
Please ask one question only and edit it, if you want to add useful information.
Walter Roberson
Walter Roberson le 19 Juil 2011
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

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 19 Juil 2011
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 commentaire
ankita taparia
ankita taparia le 20 Juil 2011
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?

Connectez-vous pour commenter.

Plus de réponses (2)

Sean de Wolski
Sean de Wolski le 19 Juil 2011
doc imfilter
doc conv2
doc blkproc
  1 commentaire
ankita taparia
ankita taparia le 20 Juil 2011
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.

Connectez-vous pour commenter.


ankita taparia
ankita taparia le 20 Juil 2011
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