How to Select GUI axes?

6 次查看(过去 30 天)
Christopher Saltonstall
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

回答(1 个)

Walter Roberson
Walter Roberson 2020-7-18
ginput() is only for traditional figures. It always uses gcf() but gcf() never finds uifigures.
  2 个评论
Christopher Saltonstall
Is there another function that I can use to select points on a figure in a GUI?
Walter Roberson
Walter Roberson 2020-7-18
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Develop uifigure-Based Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by