How to Select GUI axes?
6 views (last 30 days)
Show older comments
Hello,
I am trying to create a GUI where I load an image and then select points on the image using ginput. However, when I run the callback that contains the ginput line it opens a new window to select points in. In the ginput documentationm it says that I need to set the current axes to the plot that I want to select points in. How do I do this (see line 26)?
Thanks
classdef CameraCalGUI_v1 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
UIAxes matlab.ui.control.UIAxes
LoadCalImageButton matlab.ui.control.Button
UITable matlab.ui.control.Table
SelectPointsButton matlab.ui.control.Button
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: LoadCalImageButton
function LoadCalImageButtonPushed(app, event)
path = '';
[filename, filepath] = uigetfile([path '*.tif']);
imag = imread([filepath '\' filename]);
imshow(imag(:,:,1:3),'Parent',app.UIAxes);
end
% Button pushed function: SelectPointsButton
function SelectPointsButtonPushed(app, event)
set(app.UIFigure,'currentaxes')
[xi, yi, ~] = ginput(1);
app.UITable.Data = [app.UITable.Data; xi, yi];
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'UI Figure';
% Create LoadCalImageButton
app.LoadCalImageButton = uibutton(app.UIFigure, 'push');
app.LoadCalImageButton.ButtonPushedFcn = createCallbackFcn(app, @LoadCalImageButtonPushed, true);
app.LoadCalImageButton.Position = [70 410 100 22];
app.LoadCalImageButton.Text = 'Load Cal Image';
% Create UIAxes
app.UIAxes = uiaxes(app.UIFigure);
title(app.UIAxes, 'Calibration Image')
xlabel(app.UIAxes, 'X')
ylabel(app.UIAxes, 'Y')
app.UIAxes.Position = [217 97 396 344];
% Create UITable
app.UITable = uitable(app.UIFigure);
app.UITable.ColumnName = {'X'; 'Y'};
app.UITable.RowName = {};
app.UITable.Position = [33 131 174 204];
% Create SelectPointsButton
app.SelectPointsButton = uibutton(app.UIFigure, 'push');
app.SelectPointsButton.ButtonPushedFcn = createCallbackFcn(app, @SelectPointsButtonPushed, true);
app.SelectPointsButton.Position = [70 365 100 22];
app.SelectPointsButton.Text = 'Select Points';
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = CameraCalGUI_v1
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end
0 Comments
Answers (1)
Walter Roberson
on 18 Jul 2020
ginput() is only for traditional figures. It always uses gcf() but gcf() never finds uifigures.
2 Comments
Walter Roberson
on 18 Jul 2020
Not that I know of, but there might be something that could be adapted in the File Exchange.
For a single point, since you are not expecting to draw the points as you go, then use axes CurrentPoint property as described by one of the answers linked to above.
Perhaps use one of the roi functions such as https://www.mathworks.com/help/images/ref/images.roi.crosshair.html
See Also
Categories
Find more on Develop uifigure-Based Apps 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!