how can i split a 400*400 matrix into smaller one

2 Ansichten (letzte 30 Tage)
alexandra khabbaz
alexandra khabbaz am 20 Feb. 2020
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?

Akzeptierte Antwort

Matt J
Matt J am 20 Feb. 2020
Bearbeitet: Matt J am 20 Feb. 2020
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 Kommentare
alexandra khabbaz
alexandra khabbaz am 21 Feb. 2020
i have a folder with 1000 images, i need to call tham out, resise them from 452*400 to 400*400 all of them;
then i shoud devide each one into 100, 40*40 matrix and correlate each submatrix with it's exat same in all the other images, so ishoud get 100 correlation plots. it's really difficult for me to do so since i'm so new to matlab
alexandra khabbaz
alexandra khabbaz am 21 Feb. 2020
i started with this:
it worked for th first image but i dont know how to call all the other ones
nb=1000;
d4=zeros(1,nb);
image = imread('image1.tif');
a=size(image);
b=401;
im=image(2:b,:);
[m,n]=size(im);
C = mat2cell(im,[40 40 40 40 40 40 40 40 40 40],[40 40 40 40 40 40 40 40 40 40])

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Stijn Haenen
Stijn Haenen am 20 Feb. 2020
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

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by