Restore or copy IMROI / IMFREEHAND objects?

Hello!
I have a question regarding IMFREEHAND:
I need to create similar ROIs in several similar images and therefore would like to be able to save the ROI objects and reload them onto new figure objects. The ROIs must remain editable after copying because their exact position might have to be readjusted. However, whenever I close the figure in which the ROIs were created, the IMROI objects are automatically deleted.
Is there a way to achieve what I want?
With IMRECT, you can specify an initial size and position for the ROI and use this feature to save and load ROIs, but this does not seem to be possible with IMFREEHAND.
Thanks, Matthias

 Accepted Answer

I believe that is not an option for imfreehand. Let's say you did have handles like imrect or impoly - they would be practically every pixel. Then what would happen if you tried to grab a handle and move it? Just one pixel would move and the rest of the outline would stay put because you didn't grab their handles. So your new outline would look like the old one with a sharp spike sticking out of it. That doesn't seem very useful.

5 Comments

Thanks for the quick reply!
Maybe I should have been clearer - with 'readjust', I meant the position and not the shape, so no handles are necessary.
In any case, this is somewhat tangential to my main question - how can I save/reload/copy IMROI objects?
Have you tried save()?
Matthias
Matthias on 12 Oct 2012
Edited: Matthias on 12 Oct 2012
I have, and I can save the ROI object to a file, but I don't know how to 'attach' it to a figure after re-opening.
Also, it would be great to be able to do all this without saving anything to disk. I.e., I want to draw some ROIs in figure 1, then store them in some variable, close figure 1, open figure 2, and load the ROIs into that new figure.
You can save anything you want in a cell. Make a cell array so you have one row per image. Then start tossing stuff in there. Think of a cell like a bucket. You can throw anything you want into each bucket. The handles into one bucket, an array into another, a string into another. Then everything is saved in the cell array variable.
for k = 1 : numberOfImages
ca{k,1} = handleToROI;
ca{k,2} = fullFileName;
ca{k,3} = whatever;
end
But how can I re-load this information and have the saved ROI be displayed in a new figure, such that it is still interactive? Saving the information works fine. I also have no trouble saving and loading information extracted from the ROI object (say, the coordinates of the boundary), but I don't know how to load the object itself and apply it to some new image such that it appears as if I had just drawn it in that image using imfreehand.

Sign in to comment.

More Answers (2)

Matthias
Matthias on 15 Oct 2012
I'm still very much interested in finding a solution for my problem.
I don't know anything about the relationship between the imroi objects and the figure they were drawn in, so I cannot tell if my question is completely impossible, or if there might be a way to make it work. If somebody knows that the former is true, let me know, that would also be helpful!

3 Comments

Hello Matthias, I have the same problem with IMFREEHAND and I don't find any solution. So I'm very interested in your solution if you have one, did you?
@Matthias Did you find a solution? I had exactly the same question.

Sign in to comment.

The new drawfreehand ROI supports save/load. You can save the entire figure and reload it, or you can save the ROI into a mat file and reload the ROI later.
When reloading the ROI, you need to set the Parent property of the ROI to the new axes.
https://www.mathworks.com/help/images/ref/drawfreehand.html

Community Treasure Hunt

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

Start Hunting!