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

7 次查看(过去 30 天)
i am actually working for coloring a grayscale image.
  2 个评论
Walter Roberson
Walter Roberson 2011-7-19
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

请先登录,再进行评论。

采纳的回答

Jan
Jan 2011-7-19
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 个评论
ankita taparia
ankita taparia 2011-7-20
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?

请先登录,再进行评论。

更多回答(2 个)

Sean de Wolski
Sean de Wolski 2011-7-19
doc imfilter
doc conv2
doc blkproc
  1 个评论
ankita taparia
ankita taparia 2011-7-20
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.

请先登录,再进行评论。


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