File Exchange

image thumbnail

ginput2.m v3.1 (Nov 2009)

Same as GINPUT but with ZOOM, PAN and (optionally) PLOT and image SCALE/GEOREFERENCE!

16 Downloads

Updated 12 Nov 2009

View License

Do you still use GINPUT to graphically select points on current axes with the mouse? Try this one!

With GINPUT2 you can also:
1. ZOOM: in, out (double-click)!
2. PAN: when dragging!
3. DELETE: last selected point!
4. PLOT: while selecting! (optional, just input the line style!)
5. SCALE or GEOREFERENCE images! (optional, just input: true)

So, besides of selecting points in a more precise way (zooming) you can DIGITIZE(!!!) lines with the last two options, by simply using:
>> ginput2(true,'.k')

Enjoy it!
Bug reports and comments will be very appreciated!

Cite As

Carlos Adrian Vargas Aguilera (2020). ginput2.m v3.1 (Nov 2009) (https://www.mathworks.com/matlabcentral/fileexchange/20645-ginput2-m-v3-1-nov-2009), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (16)

I found another bug regarding the pan and zoom.
Solved applying the previous changes and changing this block (line 533 and on):

% Checks if ZOOM IN with PAN:
if ismember(button,ZOOMIN) && ~outside
% Dragging rectangle:
undoPtrFig = gcf;
setptr(undoPtrFig,'closedhand')
rbbox
ydrag = get(gca,'CurrentPoint');
x_ini = ydrag(1,1);
y_ini = ydrag(1,2);
xdrag = ydrag(1,1)-x;
ydrag = ydrag(1,2)-y;
% Do the PANNING:
%if any(abs([xdrag ydrag])>eps*1000000)
if or(and(abs(xdrag) > .1,abs(ydrag) < .1),and(abs(ydrag) > .1,abs(xdrag) < 0.1))
% Only PAN (dragging):
lim(1:4) = lim(1:4) - [xdrag xdrag ydrag ydrag];
axis(lim)
else
% PAN (centers the last point) and ZOOM in:
setptr(undoPtrFig,'glassplus')
% lim = [x+diff(lim(1:2))/2*[-1 1] y+diff(lim(3:4))/2*[-1 1]];
% axis(lim)
% zoom(2)
lim(1:4) = [min(x,x_ini) max(x,x_ini) min(y,y_ini) max(y,y_ini)];
axis(lim)
end
continue
end

Luca Amerio

DThere are several bugs in 2017b.
For example line 611 should be

if all((lim~=zlim(1:4)))

line 586 should be

if iscell(hlastaxes), hlastaxes = [hlastaxes{:}]; end

Despite this, the lines plotted still originate always from the first point (resulting in a "fan" rather than a poly-line). I still haven't found the source of this bug, but the code clearly needs to be updated to most recent versions (it looks as it has been abandoned about 10 years ago)

MaLo

Andrew, I had the same issue in Matlab 2017b and did not have it in Matlab 2012a which I have to use at work.
I deactivated the rezoom part in the code as GagoX described, because I found that part of the code annoying for my purpose. Coincidentally this also solved the issue you described.

Zooming works fine but I get the following error when trying to select a point with right click:

>> plot(1:10)
>> ginput2(1)

[[[[[[ right click on figure ]]]]]

Matrix dimensions must agree.

Error in ginput2 (line 611)
if all((lim~=zlim))

Zoidberg

GagoX

To deactivate the rezoom, just comment line 613

% Centers the selected point if ZOOM-IN: 29 SEP,2008
if all((lim~=zlim))
lim = [x+diff(lim(1:2))/2*[-1 1] y+diff(lim(3:4))/2*[-1 1]];
axis(lim) %Comment this line to deactivate recentering after each point selection
end

adi

needs one big improvement: when I zoom in, the image jumps every time I select a point! this is very annoying... otherwise, a very good tool

Genevieve

This looks very promising, but isn't working for me - I've tried various ways of running it, including the examples in the source, and every time I click on the plot it simply zooms in. I'm sure this isn't the expected behaviour - I can't get it to select any points at all, just zoom.

I'm using R2012a.

Sherif

Excellent work. Thank you very much.

Igor

Mehdi

Thanks for sharing such a useful code,
for my data, after running my code I get images for which I need the following action:
When selecting a part of image,I want Matlab to run my code for that area and calculate or graph other parameters for that part of image,
How can I do that?

Anilson

Anilson

I take that back. It does work on 3 dimension picture.
I apologize.

Olga Avila

This is really good!
It works perfect for me, and was exactly what I needed...
I just added a minor detail to plot a line from an input center point to the ginput point selected by the user (like a radial line). This was just to improve visualization for my needs.
Thank you very much!

Updates

1.4.0.0

v3.1 Now returns when N=1 and an "strange" KEY is pressed.

1.3.0.0

v3.0 Now allows panning while dragging. Some changes on help.

1.2.0.0

v2.1 Fixed bugs related with points delection. Added new 'keepzoom' feature.

1.1.0.0

Changed default YESERROR value and fixed a bug there. Changed behavior when N==1. Fixed bug with zoom out. Changed default selection keys. Changed default selection click mouse: from left one to the right one.

MATLAB Release Compatibility
Created with R2008b
Compatible with any release
Platform Compatibility
Windows macOS Linux