问题
I am new in matlab GUI. I want to drawing lines by dragging the mouse. I found this issue but I want save new image with drawn lines. If i run this line, it will show me the same image.
imshow(im);
How can I get new image with drawn lines and for example show it?
回答1:
You can also grab the image data directly in the Command Prompt. Once you draw all of your lines on your figure window, you can use getframe
, which takes a snapshot of the current frame in focus. In this case, this should be your image with the drawn lines. When you call getframe
, this will give you a structure with an element called cdata
. This will give you an RGB array of what was seen in the figure (without the menu bars... just the figure data itself).
Example:
im = imread('cameraman.tif');
imshow(im);
h = getframe;
out = h.cdata;
figure;
imshow(out); %// Should give you the same image as the figure
回答2:
You can use print to print the figure to some file. Not sure if you want to have exact reproduction of your line and image. In this case the best way probably would be to store the coordinates and properties of the line and use that to draw it on the image when you want to display it again later.
来源:https://stackoverflow.com/questions/23898746/keep-new-image-when-drawing-lines-by-dragging-the-mouse-in-matlab