Who do I read different images from my disk?
Show older comments
My program have to read an image has a reference, then take 7 frehand ROIs of it, and then with the same coordinates crop the same 7 ROIs to the other 20 images from the same folder. The images are dicom, so insted of imread for reading them I have to use dicomread as a function (this is the ony difference)
I = dicomread('REFERENCEIMMAGE')
% define these somehow
numberofimages = numel(21); % I have 21 image
numberofroi = 7; %in each images I have to perform 7 ROIs with the same coordinates
% show the reference image
imshow(I)
% use imcrop to get rectangle coordinates
R = zeros(numberofroi,4);
for nr = 1:numberofroi
[~,R(nr,:)] = imcrop(gca);
end
% crop corresponding ROIs from each non-reference image
roibasket = cell(numberofroi,numberofimages);
for ni = 1:numberofimages
for nr = 1:numberofroi
thisimage = strcat('C:\Users\agnes\Pictures\pp4 tgc-med rd20\ni.dcm'); % I don't know how to read from my disk
roibasket{nr,ni} = imcrop(thisimage,R(nr,:));
end
end
% after I have to perform the mean of the ROIs
7 Comments
Walter Roberson
on 25 Sep 2021
strcat('C:\Users\agnes\Pictures\pp4 tgc-med rd20\ni.dcm')
for nr = 1, what file name do you need to read from?
HelpAStudent
on 25 Sep 2021
Walter Roberson
on 25 Sep 2021
Edited: Walter Roberson
on 25 Sep 2021
So for nr = 1, 'C:\Users\agnes\Pictures\pp4 tgc-med rd20\ni.dcm' should become... what.... 'C:\Users\agnes\Pictures1\pp4 tgc-med rd20\ni.dcm' ?? 'C:\Users\agnes\Pictures\pp4 tgc-med rd20\ni0001.dcm' ?
Exact file name as an example would help.
HelpAStudent
on 25 Sep 2021
Walter Roberson
on 25 Sep 2021
numberofimages = numel(21); % I have 21 image
21 is a scalar. The number of elements in a scalar is 1.
I first read the latest picture named as '21' as a image reference
No you do not, You read
I = dicomread('REFERENCEIMMAGE')
That does not have a number anywhere in its name.
thisimage = strcat('C:\Users\agnes\Pictures\pp4 tgc-med rd20\ni.dcm');
Okay, imagine for a moment that is going to construct a valid file name for the purpose.
roibasket{nr,ni} = imcrop(thisimage,R(nr,:));
You are trying to imcrop() a file name without having used dicomread() to read the content of the file.
and then I start a loop for make the crop of the 7 ROIs in the other 20 images
You construct the file name within the loop. Is there a different file name for each of the 7 ROIs? Or should you be constructing the file name and reading its content before the ROI loop?
Is not just one file, but 20 files, named as 1, 2, 3, 4, and so on.
So the first one would be named 'C:\Users\agnes\Pictures\pp4 tgc-med rd20\ni.dcm\1' and the second one would be named 'C:\Users\agnes\Pictures\pp4 tgc-med rd20\ni.dcm\2' ? Or the first one would be named 'C:\Users\agnes\Pictures\pp4 tgc-med rd20\1.dcm' and the second one would be named 'C:\Users\agnes\Pictures\pp4 tgc-med rd20\2.dcm' ? Or the first one would be named 'C:\Users\agnes\Pictures\pp4 tgc-med rd20\ni1.dcm' and the second one would be named 'C:\Users\agnes\Pictures\pp4 tgc-med rd20\ni2.dcm' ?
HelpAStudent
on 25 Sep 2021
Walter Roberson
on 25 Sep 2021
I suspect that the .dcm is part of the file name.
info=dicominfo(strcat(pathname,filename));
You do not use info so there is no point assigning to it.
srcFile = dir('C:\Users\agnes\Pictures\pp4 tgc-med rd20\*.dcm');
You do not use that, so no point in assigning to it.
filename=(num2str(ni));
I suspect that there is a ".dcm" as part of the name, but that you have not configured to show extensions. I could be wrong about that.
Accepted Answer
More Answers (0)
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!