drawrectangle, drawcircle, drawellipse and drawpolyon draw region of interest at wrong position.

11 ビュー (過去 30 日間)
OkinawaDolphin
OkinawaDolphin 2021 年 2 月 1 日
回答済み: MosGeo 2021 年 10 月 5 日
When I try to draw an interactive rectangle on a GUI with an image, the rectangle is never drawn where I want it to be. In fact, it is drawn with a big offset in y direction. How can I draw an interactive rectangle, circle, ellipse or polygon at the right position?
  4 件のコメント
Image Analyst
Image Analyst 2021 年 2 月 1 日
Does this correctly report the coordinates:
rgbImage = imread('peppers.png');
h = imshow(rgbImage);
axis('on', 'image');
title('Drag out a rectangle', 'FontSize', 15);
ROI = drawrectangle('Color', 'r')
x1 = ROI.Position(1);
x2 = x1 + ROI.Position(3) - 1;
y1 = ROI.Position(2);
y2 = y1 + ROI.Position(4) - 1;
caption = sprintf('x1 = %.1f, x2 = %.1f, y1 = %.1f, y2 = %.1f',...
x1, x2, y1, y2)
title(caption, 'FontSize', 15);
OkinawaDolphin
OkinawaDolphin 2021 年 2 月 8 日
The positions are reported correctly.

サインインしてコメントする。

回答 (2 件)

Christian Wrobel
Christian Wrobel 2021 年 2 月 5 日
I had the same Problem, when I was using the AppDesigner (Matlab 2019a). I used a GridLayout to organize the axes and some surrounding UI-Objects within a tab. I've found out, that the padding of the GridLayout of the Tab was causing the Offset (Parent of axes). I changed the padding to [0,0,0,0] and the offset was gone. When I increased the padding of GridLayout the offset got even worse. Hope, this may help you.
Best Christian
  1 件のコメント
OkinawaDolphin
OkinawaDolphin 2021 年 2 月 8 日
I do not have any GridLayout on my GUI. In fact, drawrectangle and similar functions appear to work arbitrarily. As long as I do not start App Designer these functions work fine. Once I start App Designer the offset occurs, regardless of the method to start my app.

サインインしてコメントする。


MosGeo
MosGeo 2021 年 10 月 5 日
A little late to the party but here is the anwer:
It is a bug in Matlab. I had it happen to me in 2021a. Issue was reported to Mathworks and they were able to reproduce it.
Bug:
The bug occurs when you have any control in uifigure that has a negative y position.
Workaround:
Workaround: make sure all your controls are inside the UIFigure completely.

Community Treasure Hunt

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

Start Hunting!

Translated by