How can I stop image stretching using imshow in the new App designer?

22 ビュー (過去 30 日間)
Shaun Ward
Shaun Ward 2016 年 11 月 5 日
コメント済み: Michal Mucek 2021 年 4 月 16 日
I am using the new App Designer and the "imshow" function to display a greyscale image. When I resize the app the image is stretched. How can I ensure the aspect ratio of the image is maintained? Thanks, Shaun

回答 (2 件)

Micke Malmström
Micke Malmström 2017 年 9 月 7 日
Have you tried variations of "axis"? Like
axis(app.UIAxes,'equal')
  1 件のコメント
Michal Mucek
Michal Mucek 2021 年 4 月 16 日
I had the same issue and this solution worked for me. Thanks!

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


Chris Portal
Chris Portal 2016 年 11 月 6 日
There are a few ways to do this, depending on the complexity of your app...
1) The simplest would be to turn off the auto resize option in App Designer. Select the UI figure in App Designer's design view, and uncheck the Resize components when app is resized option. The downside is you will lose the convenient auto resizing of your components when the app window is resized.
2) If you'd like to keep the auto resizing of your components, you could try adding the following line to your App Designer code after you display your image. Assuming the UI axes in your app has been named "UIAxes":
set(app.UIAxes, 'Units', 'Pixels')
3) If neither of the above options are acceptable, you would need to implement a SizeChangedFcn in App Designer by right clicking on the UI figure and going to callbacks. This would allow you to have full control of how every component is resized, but would require you to code up the logic manually.
Hope this helps!
  2 件のコメント
Shaun Ward
Shaun Ward 2016 年 11 月 7 日
Hi Chris, Thanks for the suggestions. However: 1 - if I enlarge my app the image stays the same size and I end up with a lot of unused space 2 - Undoing change in item 1 and setting the units to pixels leaves me with my original problem. The images become stretched in the direction I expand the app. 3. I'll need to check this one! I never needed to think about resizing issues with GUIDE (using imshow) as the ratio of my image always remained true to the original file. Many thanks, Shaun
Chris Portal
Chris Portal 2016 年 11 月 19 日
Sorry to hear Shaun. I took a quick peek at GUIDE. By default, the figure GUIDE creates is set to not allow resizing.
If you enable figure resizing though, you get the same results as option 1 above where you end up with lots of unused space. If you're seeing something different in this case, it might help to see some of your GUIDE code to see how you're calling IMSHOW, or perhaps seeing a listing of axes property/value configurations.
Hope you're able to get things working!

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

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by