i want to divide 256*256 image into 8*8 blocks and store the 8*8 blocks in the matrix or 2d array something.

조회 수: 3 (최근 30일)
i tried mat2cell and subplot to split the image. and using imshow function i can display the image. bt i want to store the displayed image in an array. see this is the code i used it
ca=mat2cell(a,8*ones(1,size(a,1)/8),8*ones(1,size(a,2)/8),3); p=1; for c=1:size(ca,1) for r=1:size(ca,2) subplot(8,8,p); imshow(ca{r,c}); p=p+1 end end
the imshow() prints the image on the screen bt i want to store it in a array so that i can do my manipulations on my image.
  댓글 수: 1
Azzi Abdelmalek
Azzi Abdelmalek 2014년 2월 15일
vinoth, don't edit your question after it was correctly answered. And ca=mat2cell(a,8*ones(1,size(a,1)/8),8*ones(1,size(a,2)/8),3) is not your code, it is Matt's answer. You should accept it and post a new question if you want. You can also comment his answer if you need more details

댓글을 달려면 로그인하십시오.

답변 (3개)

Matt Tearle
Matt Tearle 2014년 2월 14일
Your question isn't quite clear because an image is already a matrix/2D array. (Actually, a true-color image is a 3D array.) So you need to figure out how you want these 1024 8-by-8 blocks stored. Do you want an 8-by-8-by-1024 array? Or some other arrangement? It probably depends on what you want to do. If you want to compare or average the blocks pixel-by-pixel, then 8x8x1024 is probably the best arrangement.
Anyway, if you have mat2cell working to get the blocks as cell elements, you can use cat to concatenate them along whichever dimension you like:
x = magic(32);
xcell = mat2cell(x,repmat(8,[1 4]),repmat(8,[1 4]));
x3d = cat(3,xcell{:});

Image Analyst
Image Analyst 2014년 2월 14일

Azzi Abdelmalek
Azzi Abdelmalek 2014년 2월 14일
편집: Azzi Abdelmalek 2014년 2월 14일
Im=rand(256,256); %Example
ii=1:8:256
[a,b]=ndgrid(ii,ii)
M=arrayfun(@(x,y) Im(x:x+7,y:y+7),a,b,'un',0)
% Example block [6,3]
M{6,3}

Community Treasure Hunt

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

Start Hunting!

Translated by