Issues concerning ginput() and true image size

10 Ansichten (letzte 30 Tage)
David Thibodeaux
David Thibodeaux am 25 Jun. 2015
Kommentiert: Image Analyst am 26 Jun. 2015
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.

Akzeptierte Antwort

Image Analyst
Image Analyst am 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 Kommentare
David Thibodeaux
David Thibodeaux am 25 Jun. 2015
Because I am not the legendary Image Analyst! You are the best. Thanks.
Image Analyst
Image Analyst am 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().

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Exploration finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by