Clear Filters
Clear Filters

Transform a 2D plot into a black and white image

6 views (last 30 days)
Hello.
I want to do something and i can not really think of any method to do it.
Here is the idea, I want to be able to transform a 2D closed shape plot ( like a square, a circle, a triangle,... ) into a 2D image, with the "interior" of the closed shape filled with white pixel, and the exterior of the shape with black pixels.
Do you think it is feasible, and if yes, by which means ?
Thank you very much !
  2 Comments
jonas
jonas on 23 Mar 2018
Edited: jonas on 23 Mar 2018
Not sure exactly what you want as output, but I made you an image of a white square on a black background. Change data in fill to obtain any arbitrary shape
figure;
fill([-.5 .5 .5 -.5],[-.5 -.5 .5 .5],'w')
axis([-1 1 -1 1])
set(gca,'visible','off')
set(gcf,'color',[0 0 0])
F = getframe(gcf);
figure;
imshow(F.cdata)
Boris Huljak
Boris Huljak on 26 Mar 2018
Sorry if I was not clear enough.
Your code helped me indeed ! Thank you very much.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!