Issues concerning ginput() and true image size

10 views (last 30 days)
I've been working on a method for a user to specify a custom ROI for data analysis. This consists of the use of ginput(4) to select the four vertices, and a few image processing steps to basically turn those coordinates into a binary mask of the polygon's inner pixels. I am quite close to finalizing my solution, and here is the fucntion below (Note that it's being used in GUIDE):
function [x,y,indices] = PolygonROI(hObject, eventdata, handles)
ROI = figure;
imagesc(handles.meanim)
truesize(ROI,size(handles.meanim))
[x,y] = ginput(4);
x = round(x); y = round(y);
imagesc(handles.meanim*0)
truesize(ROI,size(handles.meanim))
line([x;x(1)],[y;y(1)],'Color',[1 1 1])
dat = getframe;
im = logical(round(rgb2gray(dat.cdata)/256));
indices = imfill(im,'holes');
guidata(hObject,handles);
Here's my final issue: As you can see, I use the command truesize() to prevent my getframe() from displaying the data in the wrong scaling. My input image is 128x128, and all image plots seem to plot at the wrong scale unless I do this. My final binary output image is close, but not exactly right! It comes out about 1-2 pixels off my target size every time (130x129, etc.). How can I improve this code? Am I making this harder than it needs to be?
Thanks for the help.

Accepted Answer

Image Analyst
Image Analyst on 25 Jun 2015
Instead of all that, why can't you simply do this
[x,y] = ginput(4);
mask = poly2mask(x, y, rowsInImage, columnsInImage);
  2 Comments
David Thibodeaux
David Thibodeaux on 25 Jun 2015
Because I am not the legendary Image Analyst! You are the best. Thanks.
Image Analyst
Image Analyst on 26 Jun 2015
My preference would be to use roipolyold() rather than ginput(). It will give you a dotted line polygon that makes it easy for the user to see where the final polygon edges will be. Please give that a try instead of ginput().

Sign in to comment.

More Answers (0)

Categories

Find more on Data Exploration 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!