How can I randomly select 1000 small matrix like 11X11 from 7081X7811 matrix size?

1 visualización (últimos 30 días)
I have 7081X7811 size of matrix which have image pixel values, want to randomly select small matrix of size 11X11.
Right now, I am reading one small matrix like:
[A, R] = geotiffread('...tif'); %reading .tif image
%(200,1414) this center for below matrix
i0 = 200;
j0 = 1414; %center of small 11X11 matrix
[row, col] = size(A);
A_small = A((i0-5):(i0+5),(j0-5):(j0+5));
can you guys please help me in this?

Respuesta aceptada

Voss
Voss el 15 de Mzo. de 2022
[A, R] = geotiffread('...tif'); %reading .tif image
[row, col] = size(A); % row = 7081, col = 7811
N_small = 1000;
small_size = [11 11];
min_row = (small_size(1)+1)/2; % min_row = 6
max_row = row-min_row+1; % max_row = 7076
min_col = (small_size(2)+1)/2; % min_col = 6
max_col = col-min_col+1; % max_col = 7806
% A_small is a matrix of size 11-by-11-by-1000, each slice of
% which will be a random 11-by-11 selection from A:
A_small = zeros(small_size(1),small_size(2),N_small);
for kk = 1:N_small
% max_row-min_row+1 = 7071
% -> randi returns a random integer between 1 and 7071
% -> i0 is a random integer between 6 and 7076
i0 = randi(max_row-min_row+1)+min_row-1;
% max_col-min_col+1 = 7801
% -> randi returns a random integer between 1 and 7801
% -> j0 is a random integer between 6 and 7806
j0 = randi(max_col-min_col+1)+min_col-1;
% select from A the 11-by-11 matrix centered at i0,j0
% and assign it to the kk-th slice of A_small
A_small(:,:,kk) = A(i0-min_row+1:i0+min_row-1,j0-min_col+1:j0+min_col-1);
end
  6 comentarios
Rahul Shah
Rahul Shah el 18 de Mzo. de 2022
Thanks for reply,
I will let you know by trying this.
Voss
Voss el 18 de Mzo. de 2022
You're welcome! Yes, please let me know if it works, because I didn't run it (I don't have the tif image).

Iniciar sesión para comentar.

Más respuestas (1)

David Hill
David Hill el 15 de Mzo. de 2022
r=randi(7070,1000,1);
c=randi(7800,1000,1);
for k=1:1000
newMatrix(:,:,k)=yourMatrix(r(k):r(k)+11,c(k):c(k)+11);
end
  1 comentario
Torsten
Torsten el 15 de Mzo. de 2022
I think
r=randi(7071,1000,1);
c=randi(7801,1000,1);
for k=1:1000
newMatrix(:,:,k)=yourMatrix(r(k):r(k)+10,c(k):c(k)+10);
end
instead of
r=randi(7070,1000,1);
c=randi(7800,1000,1);
for k=1:1000
newMatrix(:,:,k)=yourMatrix(r(k):r(k)+11,c(k):c(k)+11);
end

Iniciar sesión para comentar.

Categorías

Más información sobre Images en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by