How to create simple shapes in Matlab and save them as bitmap images.
이전 댓글 표시
Is there a way for matlab code to generate simple 2d designs of simple shapes. Colour is not important. I need a way to generate basic shapes (e.g a circle -- see attachment 3mm.bmp) where I can control size and dimensions.
Is there also a way to have a gradient in the image (i.e. one side of the circle is white and becomes darker as you go across the circle with the end being black -- see attachment graded.bmp).
Thanks.
답변 (2개)
Image Analyst
2015년 4월 23일
1 개 추천
Yes. You can use functions like imrect(), impoly(), roipoly(), rectangle(), imfreehand(), roipolyold(), poly2mask(), rbbox(), etc. To do the gradient is a little trickier but I'd recommend just drawing a ramp in your image and then using your shape as a mask - basically multiply your shape image by your ramp image. I don't have any code to do masked gradient shapes but I have attached some demos of some of the other functions if you need them.
Mike Garrity
2015년 4월 23일
Maybe this will be enough to get you started:
%%Create Objects
figure('Position',[100 100 512 512],'Color','white')
axes('Position',[0 0 1 1])
xlim([1 512]);
ylim([1 512]);
h = patch;
axis off
colormap(gray)
%%Set Coordinates
t = linspace(0,2*pi,120);
h.XData = 256 + 128*cos(t);
h.YData = 256 + 128*sin(t);
h.FaceVertexCData = h.XData;
h.FaceColor = 'interp';
%%Save Image
img = getframe(gcf);
imwrite(img.cdata,'circle.png')

카테고리
도움말 센터 및 File Exchange에서 Image Arithmetic에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!