Transform a 2D plot into a black and white image

조회 수: 5 (최근 30일)
Boris Huljak
Boris Huljak 2018년 3월 23일
댓글: Boris Huljak 2018년 3월 26일
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
jonas
jonas 2018년 3월 23일
편집: jonas 2018년 3월 23일
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 2018년 3월 26일
Sorry if I was not clear enough.
Your code helped me indeed ! Thank you very much.

댓글을 달려면 로그인하십시오.

답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by