From 5ecda002221e6639796e214960ec5485366ae3aa Mon Sep 17 00:00:00 2001 From: Nicola Vigano <nicola.vigano@esrf.fr> Date: Wed, 6 May 2015 17:22:55 +0200 Subject: [PATCH] GUI: Added simple function for efficiently collect point coordinates by clicking in the image Signed-off-by: Nicola Vigano <nicola.vigano@esrf.fr> --- zUtil_GUI/gtGuiCollectPointsFromImage.m | 36 +++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 zUtil_GUI/gtGuiCollectPointsFromImage.m diff --git a/zUtil_GUI/gtGuiCollectPointsFromImage.m b/zUtil_GUI/gtGuiCollectPointsFromImage.m new file mode 100755 index 00000000..880f747d --- /dev/null +++ b/zUtil_GUI/gtGuiCollectPointsFromImage.m @@ -0,0 +1,36 @@ +function points = gtGuiCollectPointsFromImage(map) + f = figure(); + ax = axes('parent', f); + map = (map - min(map(:))) ./ (max(map(:)) - min(map(:))); + im = imagesc(map, 'parent', ax); + + cm = uicontextmenu('Parent', f, 'Callback', @(src, evt)save_clicked_point()); + set(im, 'UIContextMenu', cm); + uimenu(cm, 'Label', 'Add point..', 'Callback', @(src, evt)add_current_point()); + uimenu(cm, 'Label', 'Exit', 'Callback', @(src, evt)get_finally_out()); + + point = zeros(1, 2); + + points = zeros(0, 2); + + get_out = false; + + while(~get_out) + pause(0.001); + end + + close(f); + + function save_clicked_point() + point = get(ax, 'CurrentPoint'); + point = round(point(1, 1:2)); + end + + function add_current_point() + points(end+1, :) = point; + end + + function get_finally_out() + get_out = true; + end +end -- GitLab