How do I create a matrix that has as values ​​the averages of variables found in loops?

1 Ansicht (letzte 30 Tage)
My program analyzes a reference image: named '21', then cut out two ROIs from this image and save their coordinates. Then to the remaining images cut out the same number of ROIs at the same coordinates.
At the end of the program I will have 2*21=42 ROIs.
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])
For these ROIs I have to compute the mean and save the result in a 21*2 matrix, who can I do that?

Akzeptierte Antwort

Matt J
Matt J am 25 Sep. 2021
Bearbeitet: Matt J am 25 Sep. 2021
If that's all you want to do, you shouldn't be saving the coordinates of the ROIs. You should just create a binary mask BW of each ROI and stack your images in a 3D stack A and do
sum(A.*BW,[1,2])./sum(BW,[1,2]);
  5 Kommentare
Matt J
Matt J am 25 Sep. 2021
Yes. Drawrectangle provides a more direct way to get both the roi box boundaries and a binary mask for it.
HelpAStudent
HelpAStudent am 25 Sep. 2021
Thank you very much for helping. From the obtained matrix is ​​there a way to know when the values ​​repeat?
For example, if in the first column and first row I have the value x, when does it appear in another position?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by