How do I display an image in App Designer and plot lines on top?

133 Ansichten (letzte 30 Tage)
I am working on an app using app designer. I need to create a few line objects inside an image. And I need to turn those lines on/off, change color, etc. Can you help?

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 10 Jan. 2020
To display your image in the app, use the "imshow" function, with its "Parent" property set to the target axes:
Next, use the "plot" function to plot your lines on the same axes as the image. Use the "hold" on/off commands before and after plotting to make sure your image doesn't disappear:
If you want your lines to be interactive rather than static, you can use a Line object, which allows the user to click/drag/edit the line _after _the app is run:
I have created a short example in an MLAPP file attached below. Here is the app's StartupFcn:
%display image on axes
img = imread('cameraman.tif');
%remove title and axes labels
%plot two diagonal lines on image
imgHeight = size(img,1);
imgWidth = size(img,2);
%add interactive Line object
'Position',[10 150; 150 200]);
Finally, if you want to change your lines' visibility and color, save a handle to the lines when plotting them. You can then alter the "Visible" and "Color" properties elsewhere in your code:
If you need to access these lines outside the StartupFcn, save the handles as properties of the class and access them using the "app.line1Handle" syntax in other functions.

Weitere Antworten (0)


Mehr zu Develop uifigure-Based Apps finden Sie in Help Center und File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by