MATLAB Answers

How do I save the coordinates that I find freehand

1 view (last 30 days)
Agnese Chini
Agnese Chini on 24 Sep 2021
Commented: Agnese Chini on 25 Sep 2021
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

Accepted Answer

DGM
DGM on 24 Sep 2021
Edited: DGM on 24 Sep 2021
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])
Your usage will be different. I simply put the images in a cell array. You'll be reading them from disk instead.
  4 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!