필터 지우기
필터 지우기

How to break an image into blocks?

조회 수: 20 (최근 30일)
ahmad Al sarairah
ahmad Al sarairah 2019년 10월 9일
댓글: Rik 2022년 8월 21일
I have an image with (643x643) dimensions , and i need to split it horizontally and vertically into 100 sub images,so that each sub image is (64x64)pixels using matlab code .The sub images are blocks with (64x64) pixels ,so the height and the width of each block is equal 64
  댓글 수: 7
Hadeel
Hadeel 2022년 8월 21일
yes.sure and the code work with me but i need to disply the blocks in the screen??
Rik
Rik 2022년 8월 21일
Do you mean you want to open the image file with your system viewer? Or do you want to show the images in a Matlab figure?

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

답변 (1개)

Fabio Freschi
Fabio Freschi 2019년 10월 10일
편집: Fabio Freschi 2019년 10월 10일
Three assumprions
1) the image is a 2d matrix
2) the row/cols have 64x3, 3x64 and 3x3 blocks
3) you want 10 sub images, not 100
% A is your image
B = mat2cell(A,[64*ones(1,10) 3],[64*ones(1,10) 3]);
B is a 11x11 cell array with your sub images. You can access each of them with B{i,j}.
If the image is a 3d matrix (643x643x3), just add the third dimension to mat2cell:
B = mat2cell(A,[64*ones(1,10) 3],[64*ones(1,10) 3],3);
  댓글 수: 8
Rik
Rik 2019년 10월 13일
You need to tell Matlab how to split up your array. If I tell you to divide 10 objects in 3 groups of 3, you will ask me what to do with object 10. The code below will show you in multiple steps how to create the grouping for each dimension. Make sure to understand what each line of code does, and look at the contents of D{1} and D{2}.
A = rand(634,643);
D=cell(1,2);
for dim=1:2
D{dim}=64*ones(1,floor(size(A,dim)/64));
if sum(D{dim})~=size(A,dim)
%extend with remainder
D{dim}(end+1)=size(A,dim)-sum(D{dim});
end
end
B=mat2cell(A,D{1},D{2});
Image Analyst
Image Analyst 2019년 10월 13일
No one has actually directly asked what you want to do with the blocks. So I will, because it probably matters. What do you plan on doing with the blocks once you have them?
And again, like the others keep stressing to you, you will not have blocks all the same size if you have an image 643 pixels wide and use blocks 64 pixels wide. What are your plans for the different sized block?

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

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by