Issues concerning ginput() and true image size

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.

 Respuesta aceptada

Image Analyst
Image Analyst el 25 de Jun. de 2015
Instead of all that, why can't you simply do this
[x,y] = ginput(4);
mask = poly2mask(x, y, rowsInImage, columnsInImage);

2 comentarios

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Exploration en Centro de ayuda y File Exchange.

Preguntada:

el 25 de Jun. de 2015

Comentada:

el 26 de Jun. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by