Rasterize an alpha shape, export to bitmap

I build an alpha shape from some points (example given in code) and want to export the shape to a raster graphics format. I need the shape only, not the plot markings (axis, scales ect).
I need only the resulting triangle on white ground as a bitmap. Scale needs to be 1 unit = 1 pixel.
x = [0 10 20 30 30 30 15];
y = [0 0 0 0 15 30 15];
shape = alphaShape (x',y');
plot (shape, 'FaceColor', 'black');
I have not found anything on how to export shapes or how to rasterize them. Is there any way to do that?

Antworten (1)

Jan
Jan am 22 Aug. 2017
Bearbeitet: Jan am 22 Aug. 2017

0 Stimmen

F = getframe(gca);
imwrite(F.cdata, 'YourFile.png');
This exports a screenshot of the axes' contents to a PNG file. You can create the image manually also without the alphaShape function.
d = round(linspace(1, 200, 100));
x = 200:-1:1;
M = double(bsxfun(@gt, x, d'));
M3 = cat(3, M, M, M);
imwrite(M3, 'YourFile.png');

2 Kommentare

Sir Askalot
Sir Askalot am 22 Aug. 2017
The getframe function contains parts of the axes, it only gets rid of the numbers.
Jan
Jan am 22 Aug. 2017
Bearbeitet: Jan am 22 Aug. 2017
This let the axes vanish:
set(gca, 'Visible', 'off');
drawnow;

Melden Sie sich an, um zu kommentieren.

Kategorien

Gefragt:

am 22 Aug. 2017

Bearbeitet:

Jan
am 22 Aug. 2017

Community Treasure Hunt

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

Start Hunting!

Translated by