![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/748979/image.png)
How do I save the coordinates that I find freehand
조회 수: 4 (최근 30일)
이전 댓글 표시
Hi there, i'm almost new in Matlab and I have a really big question:
I have 21 images. Taking the last of these images as a reference: I have to find 7 freehand square roi on the image (maybe with impixel or imcrop function). Save the coordinates and use the same coordinates to crop the ROIs in the same positions as the reference image.
For now I have only been able to start a loop that read the 21 images. The format of the images is dicom, but It changes just the imread function with dicomread
srcFile = dir('DIR\*.dcm');
%change with DIR the file destination
pathname = ('DIR\');
for i=1:21
filename=(num2str(i));
%the files are named to the corresponding number. For example the first image is named as "1"
I=dicomread(strcat(pathname,filename));
info=dicominfo(strcat(pathname,filename));
figure; imshow(I);
end
댓글 수: 0
채택된 답변
DGM
2021년 9월 24일
편집: DGM
2021년 9월 24일
An example:
% generate some example test images
% you don't need to do any of this
inpict = repmat(double(imread('cameraman.tif')),[1 1 3]); % grayscale reference image
% colored example images in a cell array
A = uint8(inpict.*permute([1 0.3 0.8],[1 3 2]));
B = uint8(inpict.*permute([0.85 0.51 0],[1 3 2]));
C = uint8(inpict.*permute([0 0.68 0.45],[1 3 2]));
D = uint8(inpict.*permute([0 0.63 0.86],[1 3 2]));
pileofimages = {A B C D};
inpict = uint8(inpict);
% define these somehow
numberofimages = numel(pileofimages); % you'll have to know how many images you have
numberofroi = 2;
% show the reference image
imshow(inpict)
% 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 = pileofimages{ni}; % you'll read from disk instead
roibasket{nr,ni} = imcrop(thisimage,R(nr,:));
end
end
% show the cropped image regions for demonstration
montage(roibasket.','size',[numberofroi numberofimages])
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/748979/image.png)
Your usage will be different. I simply put the images in a cell array. You'll be reading them from disk instead.
댓글 수: 4
DGM
2021년 9월 25일
In the example, I set numberofroi = 2. Set it to 7, and set numberofimages to 21.
In order to verify that the same ROI location is the same in each image, do something similar to the example. Test the routine on copies of the same image so that colocation is visually and quantitatively identifiable (e.g. using immse()).
If you want the mean for the extracted images,
% transposed to match description
roimeans = cell2mat(cellfun(@mean2,roibasket,'uniform',false)).'
That basically gives the global mean for each image.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 3-D Volumetric Image Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!