Who do I read different images from my disk?

조회 수: 1 (최근 30일)
HelpAStudent
HelpAStudent 2021년 9월 25일
댓글: Walter Roberson 2021년 9월 25일
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
HelpAStudent
HelpAStudent 2021년 9월 25일
I tried to change my program like this:
srcFile = dir('C:\Users\agnes\Pictures\pp4 tgc-med rd20\*.dcm');
pathname = ('C:\Users\agnes\Pictures\pp4 tgc-med rd20\');
% define these image
numberofimages = 21;
numberofroi = 2;
% show the reference image
I=dicomread('21');
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
filename=(num2str(ni));
pileofimages=dicomread(strcat(pathname,filename));
info=dicominfo(strcat(pathname,filename));
roibasket{nr,ni} = imcrop(pileofimages,R(nr,:));
end
end
% show the cropped image regions for demonstration
montage(roibasket.','size',[numberofroi numberofimages])
And the file name are just the number, you can see that in the open folder on the left. I don't know if this program works, can you help me check it?
Walter Roberson
Walter Roberson 2021년 9월 25일
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.

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

채택된 답변

Walter Roberson
Walter Roberson 2021년 9월 25일
projectdir = 'C:\Users\agnes\Pictures\pp4 tgc-med rd20';
thisimage_name = fullfile(projectdir, ni + ".dcm");
thisimage = dicomread(thisimage_name);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Explore and Edit Images with Image Viewer App에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by