how can i split a 400*400 matrix into smaller one
조회 수: 2 (최근 30일)
이전 댓글 표시
i have a 400*400 matrix that i want to divid into smaller matrix 40*40.
In fact i have 1000 images that i want to do the same for all then find the corr2 between each sub matrix that is in the exact same position in each image.
any idea?
채택된 답변
Matt J
2020년 2월 20일
편집: Matt J
2020년 2월 20일
You could do it as below, with the help of mat2tiles,
I assume you have your images stacked in the form of a 400x400x1000 array (single floats).
stack=rand(400,400,1000,'single'); %example data
substacks=mat2tiles(stack,[40,40,1000]) ; %divide the data into 40x40x1000 sub-stacks
correlationResults=cell(size(substacks)); %pre-allocate the result
for i=1:10
for j=1:10
columns=reshape(substacks{i,j},40^2,[]);
correlationResults{i,j}=corr(columns);
end
end
Note that I use corr instead of corr2. It makes things easier to vectorize.
댓글 수: 2
추가 답변 (1개)
Stijn Haenen
2020년 2월 20일
what about this:
num_list=0:40:400;
data=[];
Image=zeros(400);
for a=1:numel(num_list)-1
for b=1:numel(num_list)-1
data(end+1).subimage=Image(num_list(a)+1:num_list(a+1),num_list(b)+1:num_list(b+1));
end
end
All the subimages are stored in a structure
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!