代码之家  ›  专栏  ›  技术社区  ›  Topi Anachname

将alpha形状导出/光栅化为位图

  •  0
  • Topi Anachname  · 技术社区  · 9 年前

    我只需要在白色地面上生成的三角形作为位图。

    x = [0 10 20 30 30 30 15];
    y = [0 0 0 0 15 30 15];
    
    shape = alphaShape (x',y');
    
    plot (shape, 'FaceColor', 'black');
    

    alpha shape plotted

    我没有找到任何关于如何导出形状或如何光栅化它们的内容。有什么办法吗?

    1 回复  |  直到 9 年前
        1
  •  0
  •   Yvon    9 年前

    在你的代码之后运行以下代码。

    imgwidth = max(1, ceil(max(x) - min(x)));
    imgheight = max(1, ceil(max(y) - min(y)));
    ax = gca;
    ax.Visible = 'off';
    ax.XTickMode = 'manual';
    ax.YTickMode = 'manual';
    ax.ZTickMode = 'manual';
    ax.XLimMode = 'manual';
    ax.YLimMode = 'manual';
    ax.ZLimMode = 'manual';
    ax.Position = ax.OuterPosition;
    af = gcf;
    figpos = getpixelposition(af);
    resolution=get(0, 'ScreenPixelsPerInch');
    set(af, 'paperunits','inches', ....
        'papersize',[imgwidth imgheight]/resolution, ....
        'paperposition',[0 0 [imgwidth imgheight]/resolution]);
    print(af,'out.png','-dpng',['-r',num2str(resolution)],'-opengl')
    

    完成的事情:

    • 关闭轴和记号。
    • 最小化/删除实际内容周围的填充空间。

    未完成的事情:

    • 保证纵横比。(不过应该行得通)

    example screenshot

    Mathworks - Save Figure at Specific Size and Resolution

    MATLAB Central - saving a figure at a set resolution

    Mathworks - print

    Mathworks - Save Figure with Minimal White Space

    推荐文章