How to save the required output?

조회 수: 1 (최근 30일)
Ammy
Ammy 2021년 9월 21일
댓글: DGM 2021년 9월 21일
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
The code is as;
%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'));
B_files=dir(fullfile(B_dir,'*.tif')); % *
%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
Now how to save the required output in the following form
A=<6×11 cell> which is in the form
<256×256 uint8> <256×256 uint8> <256×256 uint8> ... <256×256 uint8>
First column contain image A and other 10 columns contain corresponding 10 images B

채택된 답변

DGM
DGM 2021년 9월 21일
Something like this:
%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'));
B_files=dir(fullfile(B_dir,'*.tif'));
nfiles = [numel(A_files) numel(B_files)];
%Load images
imagearray = cell(nfiles(1),nfiles(2)/nfiles(1) + 1);
for ax = 1:nfiles(1)
imagearray{ax,1} = imread([A_dir,filesep,A_files(ax).name]);
for bx = 1:nfiles(2)/nfiles(1)
imagearray{ax,bx+1} = imread([B_dir,filesep,B_files((ax-1)*10 + bx).name]);
end
end
  댓글 수: 2
Ammy
Ammy 2021년 9월 21일
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Would you please help me in this regard, The above error occur while accepting the answer
DGM
DGM 2021년 9월 21일
Hmm. The site is flaky sometimes. I have a slow connection and run into a lot of bogus errors because of scripts timing out or breaking. In that particular experience, it often works to leave the page and then naturally navigate back to it in a few minutes. That said, if the answer satisfactorily helped you, then don't worry too much about it if you still can't accept the answer.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by