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');
采纳的回答
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 个评论
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.
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...
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', ...};
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
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?
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.
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}];
How can I know when you comment on the question??
Does it not send you emails when someone Answers or Comments on your post?
I have heard that email is not sent for Comments.
Area{i} = [Props(:).Area];
where is the variable {i} in the input statement?
Area{i} = [Props{i}.Area];
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Images 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
