How can I save ROI parameters from DrawFreehand and load it onto another image?

조회 수: 7 (최근 30일)
I'm working on a programme that analyses the contents within an ROI (such as Mean Grey Intensity). The images i want to measure are not clear enough to draw an ROI, but I have an image that is the same size (160x160px) and I would like to draw the ROI on that image and then display that ROI on the other images. I have the images uploaded in "axes" in the app designer. Any help is appreciated.
  댓글 수: 2
Image Analyst
Image Analyst 2021년 2월 20일
Don't you have the variable from drawfreehand()? How did it disappear? Did it go out of scope? If so, save it to a .mat file. Show us how you call it.
Sami Case
Sami Case 2021년 2월 20일
I do have the variable from drawfreehand(), but i am not sure how to call it? Its not disappearing, it shows on the image that I draw it on. However, I'm not sure how to display the saved ROI onto another image. I'm new to all of this, also, so please excuse my ignorance.
To draw and save it, I use:
h = drawfreehand(app.UIAxes_Green);
save('roi.mat', 'h');

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

채택된 답변

Image Analyst
Image Analyst 2021년 2월 20일
Here is what I do:
% User draws curve on image here.
hFH = drawfreehand();
% Get the xy coordinates of where they drew.
xy = hFH.Position
% get rid of imfreehand remnant.
delete(hFH);
% Overlay what they drew onto the image.
hold on; % Keep image, and direction of y axis.
xCoordinates = xy(:, 1);
yCoordinates = xy(:, 2);
plot(xCoordinates, yCoordinates, 'r.', 'LineWidth', 2, 'MarkerSize', 12);
caption = sprintf('Original Grayscale Image.\nPoints may not lie on adjacent pixels, depends on your speed of drawing!');
title(caption, 'FontSize', fontSize);
See attached full demo. Once you have xCoordinates and yCoordinates, you can save them and apply them to other images, for example by using them to create a mask with poly2mask().
  댓글 수: 2
Sami Case
Sami Case 2021년 2월 23일
I've been able to work on this and create a mask with poly2mask(). But I'm not sure how to display that mask over another image?
Image Analyst
Image Analyst 2021년 2월 23일
If you want to create a new RGB image with the mask displayed "burned" into the image, see imoverlay. Otherwise if you want it in the overlay, see these links:

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by