Save ROI Object and load it later again
Mostrar comentarios más antiguos
I have several pictures where the User defines different ROI-Objects. The user can switch between the currently displayed picture (Only one image is displayed at a time). Now I want to store each ROI-Object corresponding to each picture and load them when the User comes back to the picture with the corresponding ROI-Object. To be clear: The (re)loaded ROI-Object needs to be still customizable.
I saved each handle to the corresponding ROI-Object but now I don't have a clue how to show the ROI-Object again. How can I do this?
2 comentarios
Adam
el 10 de Jul. de 2018
What is an 'ROI-object'? An imroi or something else?
Image Analyst
el 29 de Oct. de 2021
@Adam, drawpolygon() returns a variable that they call roi but is actually a variable of the "polygon" class.
The old imroi class from the Image Processing Toolbox is not recommended anymore, according to the help.
Respuestas (1)
Image Analyst
el 10 de Jul. de 2018
Simply use save() to save your variable into a .mat file
save('roi.mat', 'yourROIVariable');
To recall:
s = load('roi.mat');
yourROIVariable = s.yourROIVariable;
6 comentarios
hedgehog
el 29 de Oct. de 2021
Possibly this is not what SturmGhost meant. I have the same problem and like to use drawpolygon() to select an area in a plot. The desired shape is somewhat intricate. It would be nice to be able to apply modifications later. So there is need for a function to draw a polygon (or some other roi) on an image or plot with the option to start with an existing one. This could be saved and loaded as shown above.
Image Analyst
el 29 de Oct. de 2021
@hedgehog each time you call
thisROI = drawpolygon();
it will return an ROI object. You can save it, or an array of them, in a .mat file like I showed. You can then recall all of them from the mat file later and use them again.
It doesn't matter whether you start with none, one or more in your existing program session, or with one or more that you recalled from a .mat file. Bottom line is each time you call drawpolygon you will get a new ROI object. You can collect a whole bunch of them if you want.
I'm not sure you can pass an existing object into drawpolygon() and modify it. If you can, I'm not seeing that in the help. I'd just delete it (any you don't want) and ask the user to draw it again.
If you want the outlines of lots of polygons you drew, you can get the position properties of each of them and create a binary image (mask) with that polygon. Then OR all the masks together to get a mask of the entire group. You can get boundaries of the regions with bwboundaries().
hedgehog
el 30 de Oct. de 2021
Thanks Image Analyst,
that is what I had assumed. Yet it does not please me much. Indeed it is possibly to modify a polygon with drawpolygon(). However the new vertices are just visible in the figure. Can they be accessed somehow?
% display the standard deviation
S = std(sobotpresData,1,3);
imagesc(S)
caxis([0 500])
title('standard deviation / Pa')
colorbar
% load existing polygon
load('h.mat')
vertices=h.Position;
% draw the existing polygon - it can be modified and extended but - how can the
% new polygon data be used?
ho = drawpolygon('Position',vertices,'Color','r');
save('h.mat','ho')
h =
Polygon with properties:
Position: [3×2 double]
Label: ''
Show all properties
>> ho
ho =
Polygon with properties:
Position: [3×2 double]
Label: ''
Color: [1 0 0]
Parent: [1×1 Axes]
Visible: on
Selected: 0
even though 2 more vertices were added
Looks like I have to:
-take a consumer attitude and try to like what is offered
or
- write an alternative to drawpolygon() by myself.
Image Analyst
el 30 de Oct. de 2021
I'm not sure what the code you posted is supposed to demonstrate. Anyway, it does not run.
When I try to save my ROI from drawellipse, it says it must be a text scalar. Here is my code. Do you know what to do?
Code:
file2Open = fullfile('LabeltheSkeleton.png');
image1 = imread('LabeltheSkeleton.png');
leftClavicleROI = drawellipse('Position', [100, 300]);
save('leftClavicleROI.mat', leftClavicleROI);
variable1 = load('leftClavicleROI.mat');
Error Message:
Error using save
Must be a text scalar.
Error in TestingFinalProjectParts (line 14)
save('leftClavicleROI.mat', leftClavicleROI);
DGM
el 3 de Nov. de 2021
You need to pass the name of the variable, not the variable itself.
save('leftClavicleROI.mat', 'leftClavicleROI');
Categorías
Más información sobre ROI-Based Processing en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!