Image displayed in GUI is tilted and not straight
1 次查看(过去 30 天)
显示 更早的评论
Hey,
I have displayed an image in GUI and at the start it is displayed fine. (MATLAB app designer)
After some number of running it started to be displayed titlted:
And this is the code that I used:
global im;
[rawname, rawpath] = uigetfile({'*.Jpg'},'Select Image Data');
fullname = [rawpath rawname];
ax = app.UIAxes1;
im = imread(fullname);
[~, ~, c] = size(im);
if c ~= 1
im = rgb2gray(im);
end
im = imresize(im,[256 256]);
imshow(im, 'parent', ax);
Is there some code that I need to add in order for the image to be displayed straight and not tilted always?
Thank you.
回答(1 个)
Walter Roberson
2022-5-30
You initialize each of your UIAxes with a CameraPosition.
When you call imshow(), passing in the axes (which is done properly), imshow() calls image(), and image puts the image up on the screen. At that point, the default axes view of [0 90] is in effect, which is what we would expect. But.. (at least while debugging), as soon as image() returns to imshow(), the axes View property has changed to -135 89.94140625 . There is no explicit call that is setting the View: it is magically changing upon return from image()
Eventually you get to the view(ax, 2) ... and nothing happens when that is called: ax.View stays exactly the same as above.
But if you put a breakpoint in at the view(ax,2) call and run to there, then the view(ax,2) call does work properly... and when it does, the axes CameraPosition changes dramatically to about [150 150 2100] replacing the [0.5 0.5 9] that you initialized the UIaxes to.
The work-around appears to be to add
drawnow()
before the view(ax,2) command.
5 个评论
Walter Roberson
2022-5-30
UIAxes3 and UIAxes5 are already being displayed as 3D meshes. UIAxes3 looks like s surface plot instead of a mesh because the edges are close together due to the mesh being 367 by 181 and the Position not being much larger -- the edges pretty much touch in that window.
The Position properties of UIAxes3 and UIAxes4 stay the same during execution -- the code is not somehow making the Position larger or moving them. But UIAxes3 is getting drawn too large, drawn outside the box one would expect. Clipping appears to be on properly. UIAxes3 is getting drawn too large first, drawn down into the space one would expect for UIAxes4. Then after that, UIAxes4 is getting drawn too low down but is stopping half-way up the screen. But because UIAxes3 is drawn too big (for unknown reasons yet), UIAxes4 is getting drawn part way over top of UIAxes3's plot.
I think you are having problems with the CameraPosition that you are setting when the axes are created. I think you should not be setting those, and instead leaving them on automatic mode.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!