How do I save the coordinates that I find freehand

5 views (last 30 days)
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
%the files are named to the corresponding number. For example the first image is named as "1"
figure; imshow(I);

Accepted Answer

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
% use imcrop to get rectangle coordinates
R = zeros(numberofroi,4);
for nr = 1:numberofroi
[~,R(nr,:)] = imcrop(gca);
% 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,:));
% 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.

Sign in to comment.

More Answers (0)


Find more on DICOM Format 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!