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

조회 수: 4 (최근 30일)
Teshan Rezel
Teshan Rezel 2021년 3월 30일
편집: Adam Danz 2021년 4월 2일
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);
end
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);
DisplayCrosshairs(app);
end
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);
else
msgbox('Please select a quadrant for the crosshair to be displayed in');
end
end
function startupFcn(app)
pause(1);
title(app.Image, []);
xlabel(app.Image, []);
ylabel(app.Image, []);
app.Image.XAxis.TickLabels = {};
app.Image.YAxis.TickLabels = {};
app.UIFigure.WindowState = 'maximized';
disableDefaultInteractivity(app.Image)
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';
end
  댓글 수: 8
Teshan Rezel
Teshan Rezel 2021년 3월 31일
Hi @Adam Danz, apologies for not explaining the app. The buttons next to the table currently do nothing. The wayto display an image is to select a folder with images in it via "Home->Add Image Folder". I've attached an image of the crosshairs displayed on the image below. Also, I've changed the code to display the crosshairs from an IF statement to the following:
for i = 1 : 9
if checkMatrix(i) == 1
ROI(app, positionVector{i,:});
end
end
where positionVector is defined as:
positionVector = {quarterHeight quarterWidth; quarterHeight halfWidth; quarterHeight threeQuarterWidth; halfHeight quarterWidth; halfHeight halfWidth; halfHeight threeQuarterWidth; threeQuarterHeight quarterWidth; threeQuarterHeight halfWidth; threeQuarterHeight threeQuarterWidth};
I've also attached an image with the axes turned on and the image displayed relative to them. It appears as though the position vector is not relative to the axes either.
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);
DisplayCrosshairs(app);
end
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
Teshan Rezel
Teshan Rezel 2021년 4월 1일
hi @Adam Danz, thank you for this, it works a treat! the ordering is now correct. The positioning is still a little off, since it would seem the axes, which I am indexing the crosshair positions to, are smaller than the size of the image. I'm still unsure of how to fix this. But the main issue is done, thak you! and apologies once again for taking so long, and explaining this poorly!
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);
imshow(corn_gray)
axis(gca, 'on') % <-- replace gca with you axis handle

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by