reading multiple images from a folder?

I have about 88 image of 10 patients, number of images for each patient is not equal. I want to read images for each patient from 2 different folders and do some operations then save the results in third folder. How to do this process in a loop? and how to save the results with respect to images' names (Ex: image1: Adel_No_Post1.bmp, image2: Adel_No_Frangi1 ...
how to save the result, result_image: Adel_No_Filtered1)
%folder path E:\Aneurysms_CBIR\Aneu_Post_Contrast
Post_Im=imread('E:\Aneurysms_CBIR\Aneu_Post_Contrast\Adel_No_Post1.bmp');
% folder path E:\Aneurysms_CBIR\Aneu_Frangi_Images
Frangi_Im=imread('E:\Aneurysms_CBIR\Aneu_Frangi_Images\Adel_No_Frangi1.bmp');
% do some operations
h = fspecial('gaussian', [3 3], 0.5);
imf=imfilter(Frangi_Im, h);
imsub=Post_Im-imf;
%save result with name " Adel_No_Filtered1" to a new folder, path:E:\Aneurysms_CBIR\Aneu_Filtered
imwrite(imsub, ['E:\Aneurysms_CBIR\Aneu_Filtered\ Adel_No_Filtered1' '.bmp'], 'bmp');

 Respuesta aceptada

Walter Roberson
Walter Roberson el 17 de Jun. de 2015

0 votos

One thing you did not define for us is how to match file names to individual patients. Or does it not matter, that each number before the .bmp in on directory corresponds to one file in the second directory that has the same number and you just need to pair them?

13 comentarios

Nisreen Sulayman
Nisreen Sulayman el 17 de Jun. de 2015
Editada: Nisreen Sulayman el 17 de Jun. de 2015
I have 88 images in a folder (F1) for 10 patients AND I have another 88 images in a second Folder (F2) for the same patients
I want to read the images from both folders ... do some operations and save the result in a new folder with a new variable name. The new variable name should match parts of the images:
Ex: image1 from first folder: Adel_No_Post1.bmp should underwent some operations with image1 from second folder (for the same patinet) image1: Adel_No_Frangi1 I should save the result for this patient in name related to patient name like: result_Image=Adel_No_Filtered1
************** Yes, the number is important ... It indecates how many images for each patient I have.
Nisreen Sulayman
Nisreen Sulayman el 17 de Jun. de 2015
Editada: Nisreen Sulayman el 17 de Jun. de 2015
Mr. Roberson,
Thank you for your answer,
BUT
I don't have the same number of images for each patient.
First patinet has 6 images, three ones in each folder
Second patiebt has 14 images, seven ones in each folder
and so one...
Nisreen Sulayman
Nisreen Sulayman el 17 de Jun. de 2015
Editada: Nisreen Sulayman el 18 de Jun. de 2015
Would you Please ...
How to read the names of the88 image and save their names in a cell array like this:
names_Post={'Adel_Post1','Adel_Post2','Adel_Post3','Dalal_Post','Fatma_Post1','Fatma_Post2', ...};
Walter Roberson
Walter Roberson el 18 de Jun. de 2015
Editada: Walter Roberson el 24 de Jun. de 2015
dinfo = dir('*.bmp');
numfiles = length(dinfo);
names_Post = cell(numfiles,1);
for K = 1 : numfiles
thisfile = dinfo(K).name;
[pathstr, basestr, ext] = fileparts(thisfile);
names_Post{K} = basestr;
end
Walter Roberson
Walter Roberson el 18 de Jun. de 2015
How do you know that Adel_No_Post1.bmp goes with Adel_No_Frangi1.bmp ? Is the patient name the "Adel_No" part, and for the first directory the images for each patient end in _Post* whereas in the second directory the images for each patient end in _Fragni* ? Or is the patient name the part before the first underscore, "Adel" and the "No_Post" and "No_Fragi" are the constant parts?
Nisreen Sulayman
Nisreen Sulayman el 23 de Jun. de 2015
You right Mr. Roberson ...
at the first directory the images for each patient end in _Post* whereas in the second directory the images for each patient end in _Fragni*
and the number indicates how many images for each patient are there.
Nisreen Sulayman
Nisreen Sulayman el 23 de Jun. de 2015
Editada: Walter Roberson el 24 de Jun. de 2015
Thank you for answering ...
What is wrong in "Selecting only the largest structure" code
filePattern = fullfile('E:\Aneurysms_CBIR\Aneurysms\Aneu_Frangi_Images', '*.bmp');
bmpFiles = dir(filePattern);
names = {bmpFiles.name};
for i = 1 : length(names)
% do some processing
bw{i}=im2bw(imf{i}); % convert imgae to binary
%Select only the largest structure\component
L{i} = bwlabel(bw{i});
Props{i} = regionprops(L{i}, 'Area');
Area{i} = [Props(:).Area{i}];
LabelNo{i} = find(Area{i} == max(Area{i}));
%bw = L == LabelNo;
bw_v{i} = L{i} == LabelNo{i};
imwrite(bw_v{i},['E:\Aneurysms_CBIR\Aneurysms\Aneu_Vessel_tree_Images\' names{i} '_CusF.bmp'])
end
MatLab give the following error message
Improper index matrix reference.
Area{i} = [Props(:).Area{i}];
Nisreen Sulayman
Nisreen Sulayman el 23 de Jun. de 2015
How can I know when you comment on the question??
Image Analyst
Image Analyst el 23 de Jun. de 2015
Does it not send you emails when someone Answers or Comments on your post?
Walter Roberson
Walter Roberson el 24 de Jun. de 2015
I have heard that email is not sent for Comments.
Area{i} = [Props(:).Area];
Nisreen Sulayman
Nisreen Sulayman el 24 de Jun. de 2015
where is the variable {i} in the input statement?
Area{i} = [Props{i}.Area];

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Images en Centro de ayuda y File Exchange.

Preguntada:

el 16 de Jun. de 2015

Comentada:

el 24 de Jun. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by