Using roipoly on plots
Show older comments
Is the roipoly command only usable on image files? I need to select a region of interest (possibly several) on a contourf plot of data. After trying to use the roipoly command on one of my plots it generates an error saying an image must be present in the current figure. If this is the case and there is no way to use roipoly on plots, is there an alternate command for selecting region of interest? I had previously used data cursor but roipoly then seemed like a preferable option.
8 Comments
Adam
on 7 Jul 2017
roipoly only works on image matrix data - i.e. numeric types. If there is no underlying matrix then it cannot work. A contour plot doesn't have the same type of structure that can be indexed into as you would an image.
You can use
doc imroi
to draw on an axes, though to be useful you still need to be able to interpret it in terms of the thing you drew it on so it is also usually used with images where you can turn it into a logical mask.
Aaron Smith
on 7 Jul 2017
Adam
on 7 Jul 2017
imroi
should work fine then I would think (or one of its sister functions like imrect if you wanted something more constrained).
Aaron Smith
on 7 Jul 2017
Edited: Aaron Smith
on 7 Jul 2017
Aaron Smith
on 7 Jul 2017
Adam
on 7 Jul 2017
Actually imroi is the abstract base class. impoly is the one to actually create an instance of, but you can do it on a blank axes if you wish, it doesn't need an image.
I'm not sure what you mean by 'file types' though. Files should not have anything to do with the process as you are working on an axes.
figure; hAxes = gca
hR = impoly( hAxes )
will allow you to simply draw a polygon on an axes (or, as far as I am aware, on top of anything that happens to be on those axes).
Aaron Smith
on 7 Jul 2017
Adam
on 11 Jul 2017
You can by-pass createMask, which is basically just a wrapper function and go straight to the function that it calls,
doc poly2mask
by using the points defined my imrect or impoly. This function needs to be given an image size (to create the mask of that size), but does not need an image itself e.g.
hPoly = impoly( hAxes );
...
polyPos = getPosition( hPoly );
x = polyPos(:,1); y = polyPos(:,2);
imSize = [100 200];
binaryMask = poly2mask( x, y, imSize(1), imSize(2) );
Answers (0)
Categories
Find more on ROI-Based Processing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!