How can I repeat the same algorithm from different folders?

2 views (last 30 days)
Agnese Chini on 1 Oct 2021
Commented: Image Analyst on 1 Oct 2021
Hi, I have this algorithm which works perfectly. However, it only reads one folder at a time and graphs me only one curve at a time (1 FOLDER= 1 PLOT AS RESULT OF THE ANALYSIS). I would like to be able to read 4 other folders, do the same operations and then graph all five curves in the same graph.
This is the algorithm that only reads one folder at a time:
%this is for the destination of the folder
srcFile = dir('C:\Users\agnes\Pictures\POST PROCESSING 4\PP4 TGC-MED RD 20\*.dcm');
pathname = ('C:\Users\agnes\Pictures\POST PROCESSING 4\PP4 TGC-MED RD 20\');
%All the operations below must be repeated for each folder. Stored in different variables if you like.
% The important thing is that the same curves that I find individually (by changing the destination of the folder)
% I can graph them together at the end
numberofimages = 21; %I define the number of the image for each folder
numberofroi = 6; %each image has to be crop 6 times
%Work on the reference images
imshow(I)
R = nan(numberofroi,4);
for nr = 1:numberofroi
h = drawrectangle(gca); wait(h);
R(nr,:)=h.Position;
end
for ni = 1:numberofimages
for nr = 1:numberofroi
filename=(num2str(ni));
info=dicominfo(strcat(pathname,filename));
end
end
%I need this operation for each folder
rvalue = [-9; -6; -3; 3; 6; 9];
hold on
%In the command below I have plotted the curve of only the first result
%I need to plot all the curves in the same plot
The five folder to analyze are:
C:\Users\agnes\Pictures\POST PROCESSING 4\PP4 TGC-MED RD 20\
C:\Users\agnes\Pictures\POST PROCESSING 4\PP4 TGC-MED RD 40\
C:\Users\agnes\Pictures\POST PROCESSING 4\PP4 TGC-MED RD 60\
C:\Users\agnes\Pictures\POST PROCESSING 4\PP4 TGC-MED RD 80\
C:\Users\agnes\Pictures\POST PROCESSING 4\PP4 TGC-MED RD 100\
Agnese Chini on 1 Oct 2021
Aniway your program does not read now the reference image, I think because It does not recognise the destination. Even if I put inside dicomread something like that

Image Analyst on 1 Oct 2021
To get a list of all dcm files in all subfolders below some top level folder, use the "star star" wildcard in the dir() function.
topLevelFolder = 'C:\Users\agnes\Pictures\POST PROCESSING 4\PP4 TGC-MED RD 20\';
filePattern = fullfile(topLevelFolder, '**\*.dcm')
fileList = dir(filePattern)
% Loop over them.
numFiles = length(fileList);
for k = 1 : numFiles
thisFileName = fullfile(fileList(k).folder, fileList(k).name);
fprintf('File #%d of %d :\n "%s"\n', k, numFiles, thisFileName);
% Optional : Get size info if desired:
d = dir(thisFileName);
fprintf(' It is %d bytes.\n', d.bytes);
% Now call imread() or whatever you want to do.
end
Image Analyst on 1 Oct 2021
Then you do not have any DCM files under that folder. Try the root folder:
topLevelFolder = 'C:\'
It might take a while to scan your whole hard disk though.

Categories

Find more on Graphics Performance in Help Center and File Exchange

R2020b

Community Treasure Hunt

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

Start Hunting!