i want to divide 256*256 image into 8*8 blocks and store the 8*8 blocks in the matrix or 2d array something.
7 views (last 30 days)
Show older comments
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 Comment
Azzi Abdelmalek
on 15 Feb 2014
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
Answers (3)
Matt Tearle
on 14 Feb 2014
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{:});
0 Comments
Image Analyst
on 14 Feb 2014
See code examples in the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_split_an_image_into_non-overlapping_blocks.3F
0 Comments
Azzi Abdelmalek
on 14 Feb 2014
Edited: Azzi Abdelmalek
on 14 Feb 2014
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}
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!