How to select every 10 images corresponding to one image?

Suppose we have two folders A and B , both contain images.
Let folder A have 6 images:a1,a2,...,a6
folder B have 60 images: b1,b2,...,b60.
I want to select 10 images in B for each image in A, in the following way
for a1 select b1,b2,...,b10
for a2 select b11,b12,...,b20
.
.
.
for a6 select b51,b52,...,b60

 Respuesta aceptada

%Select image folder A
A_dir = uigetdir();
%Select image folder B
B_dir = uigetdir();
%Identify files of interest
A_files=dir(fullfile(A_dir,'*.tif')); %Here, I am assuming the images are TIFF files and all file types are the same. Change this to .png, .jpg, or .bpm...etc if needed.
B_files=dir(fullfile(B_dir,'*.tif')); % * is a wildcard
%Load images
for i = 1:length(A_files)
A_image = imread([A_dir,filesep,A_files(i).name]);
if i == 1
for ii = 1:10
B_images(ii,:,:) = imread([B_dir,filesep,B_files(ii).name]);
end
else
for ii = 1:10
B_images(ii,:,:) = imread([B_dir,filesep,B_files((i-1)*10+(ii-1).name]);
end
end
end

4 comentarios

Ammy
Ammy el 20 de Sept. de 2021
@Kevin Holly Thank you very much , sorry but I'm getting the following error
Error: File:.... Line: 19 Column: 77
Unexpected MATLAB operator.
Ammy
Ammy el 20 de Sept. de 2021
That has been resolved by (ii-1)).name
Now how to save the required output in the following form
A=<6×11 cell> which is
<256×256 uint8> <256×256 uint8> <256×256 uint8> ... <256×256 uint8>
(Assume the size of image is 256×256.
First column contain image A and other 10 columns contain corresponding 10 images B
Kevin Holly
Kevin Holly el 21 de Sept. de 2021
Editada: Kevin Holly el 21 de Sept. de 2021
%Load images
A = [];
for i = 1:length(A_files)
A_image = imread([A_dir,filesep,A_files(i).name]);
if i == 1
for ii = 1:10
B_images(ii,:,:) = imread([B_dir,filesep,B_files(ii).name]);
A = [A; {A_image} {B_images(ii,:,:)}]
end
else
for ii = 1:10
B_images(ii,:,:) = imread([B_dir,filesep,B_files((i-1)*10+(ii-1)).name]);
A = [A; {A_image} {B_images(ii,:,:)}]
end
end
end
Ammy
Ammy el 21 de Sept. de 2021
Thank you very much.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Preguntada:

el 20 de Sept. de 2021

Comentada:

el 21 de Sept. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by