Save plot on top of an image.

1 view (last 30 days)
Ana Olivia
Ana Olivia on 16 Jun 2015
Commented: Ana Olivia on 17 Jun 2015
I need to save a graph on top of a black image. I have an image, so I want to make a plot on this image, and save it on a new image with black background and with same dimensions.
In the beginning I "paint" the image with black color, since I want both images to have the same dimensions. Then I use ginput and plot to pick the part of the image that I want. Then I open the black image using imshow(blackimage) and I use these commands:
f = getframe(gcf);
DATA = frame2im(f);
and I use imwrite to save DATA.
But I am having a problem with it because this program changes the dimensions of DATA, changes it to uint8, and the image becomes 3D. Please, can someone help me to solve this problem? What can I do to both images have the same dimensions?
Thank you for the help!
Ana Olivia
Ana Olivia on 17 Jun 2015
Yes, I want to do this. I want to select a portion of the image and everything outside the selected portion needs to be cleared to black. I tried to use roipoly, but it just works to polygons, and I want a line.
No, the plot is not constant. The user points the location (using ginput). Then the rest is set to black.

Sign in to comment.

Answers (1)

LUI PAUL on 16 Jun 2015
Edited: LUI PAUL on 16 Jun 2015
Is this what you are looking for?
uiopen('C:\black.gif',1)%first image
[x,y] = ginput% select your interest
hold on
plot((1:900),1:900)%second image,plotting on first image
note: at the time of using "ginput" you have to select area manually and hit enter.
2.insteed of plot use your own.
  1 Comment
Ana Olivia
Ana Olivia on 17 Jun 2015
I already plotted the graphic on the image with black background, but I couldn't save it. Every time I try to save the image the size of it changes. So I am searching for a way to save the modified image (image with plot).
But thanks a lot for answering me!

Sign in to comment.


Community Treasure Hunt

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

Start Hunting!

Translated by