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.
4 件のコメント
回答 (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!