App designer - problem with plotting on axes, on top of an image

조회 수: 24(최근 30일)
Hi folks, I'm trying to place a crosshair plot (using "+" and "o") on top of an image in the app designer. Currently, the crosshair is diplayed in the wrong position, and too small.
Is there a way to fix this please? app.Image is my UIAxes name property.
function ROI(app, index1, index2)
hold (app.Image, "on")
plot(app.Image, index1, index2, app.innerMarkerStyle, 'MarkerSize', app.CrosshairThickness.Value, 'Color', app.crossHairColour);
plot(app.Image, index1, index2, app.outerMarkerStyle, 'MarkerSize', app.CrosshairThickness.Value, 'Color', app.crossHairColour);
function DisplayImage(app)
app.currentImage = fullfile(app.imageFolder(app.imageNumber).folder, app.imageFolder(app.imageNumber).name);
app.Image.Position = [0 0 app.UIFigure.Position(3:4)];
app.img = imread(app.currentImage);
function DisplayCrosshairs(app)
I = imshow(app.currentImage, "Parent", app.Image);
axis(app.Image, "tight");
app.Image.XLim = [0 I.XData(2)];
app.Image.YLim = [0 I.YData(2)];
app.Width = app.Image.XLim;
app.Height = app.Image.YLim;
quarterHeight = app.Height(1)+range(app.Height)*0.25;
halfHeight = app.Height(1)+range(app.Height)*0.5;
threeQuarterHeight = app.Height(1)+range(app.Height)*0.75;
quarterWidth = app.Width(1)+range(app.Width)*0.25;
halfWidth = app.Width(1)+range(app.Width)*0.5;
threeQuarterWidth = app.Width(1)+range(app.Width)*0.75;
checkMatrix = [app.TopLeft.Value app.TopMiddle.Value app.TopRight.Value app.CentreLeft.Value app.CentreMiddle.Value app.CentreRight.Value app.BottomLeft.Value app.BottomMiddle.Value app.BottomRight.Value];
app.numSamplesPerImage = sum(checkMatrix, 1:9);
if checkMatrix(1) == 1
ROI(app, quarterHeight, quarterWidth);
elseif checkMatrix(2) == 1
ROI(app, quarterHeight, halfWidth);
elseif checkMatrix(3) == 1
ROI(app, quarterHeight, threeQuarterWidth);
elseif checkMatrix(4) == 1
ROI(app, halfHeight, quarterWidth);
elseif checkMatrix(5) == 1
ROI(app, halfHeight, halfWidth);
elseif checkMatrix(6) == 1
ROI(app, halfHeight, threeQuarterWidth);
elseif checkMatrix(7) == 1
ROI(app, threeQuarterHeight, quarterWidth);
elseif checkMatrix(8) == 1
ROI(app, threeQuarterHeight, halfWidth);
elseif checkMatrix(9) == 1
ROI(app, threeQuarterHeight, threeQuarterWidth);
msgbox('Please select a quadrant for the crosshair to be displayed in');
function startupFcn(app)
title(app.Image, []);
xlabel(app.Image, []);
ylabel(app.Image, []);
app.Image.XAxis.TickLabels = {};
app.Image.YAxis.TickLabels = {};
app.UIFigure.WindowState = 'maximized';
app.Counts = [zeros(8, 1)];
app.Percentages = [zeros(8, 1)];
app.CokeTable.Data = [app.Counts, app.Percentages];
app.CokeTable.Position = [73 -1 168 265];
app.tallyOrder = [1];
app.innerMarkerStyle = '+';
app.outerMarkerStyle = 'o';
app.crossHairColour = 'w';
  댓글 수: 8
Adam Danz
Adam Danz 2021년 4월 1일
The axes aren't on so I can't see the axis limits. From my previous comment, " If the axes are not on, turn them on before taking the screenshot, using axis(app.UIAxes, 'on'), "
I don't see where you addressed the other 3 requests in that comment. It's really hard to help without that info.

댓글을 달려면 로그인하십시오.

채택된 답변

Adam Danz
Adam Danz 2021년 4월 1일
편집: Adam Danz 2021년 4월 1일
Here's the problem (see arrow)
function DisplayImage(app)
app.currentImage = fullfile(app.imageFolder(app.imageNumber).folder, app.imageFolder(app.imageNumber).name);
app.Image.Position = [0 0 app.UIFigure.Position(3:4)]; % <-------- PROBLEM
app.img = imread(app.currentImage);
app.Image is the handle to the uiaxes (Image is a misleading variable name). The axes are a child of a PANEL, not the figure, and the panel is not the same size as the figure.
So you're setting the axis size to the same size as the FIGURE, not the panel. It's clear that the axis extends off the right edge of the figure if you compare the image outside of Matlab and the image that displays in your app.
To fix it, use the panel size to define the axis size rather than the figure size.
Secondly, you're not correctly specifying the position of the crosshairs in the plotting function. See comment below.
  댓글 수: 4
Adam Danz
Adam Danz 2021년 4월 2일
편집: Adam Danz 2021년 4월 2일
Hmmm.... do you mean the axes is zoomed into the image? axis(h,'tight') would fix that and that's the default behavior for imshow. Are you zooming into the image or changing the axis limits?
If you turn the axes on, you will be able to directly see the axis border!
corn_gray = imread('corn.tif',3);
axis(gca, 'on') % <-- replace gca with you axis handle

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by