转换用省略号阴谋在MATLAB二进制图像(Convert a plot with ellipses

2019-10-19 18:22发布

这是我在这里的第一个问题和我在MATLAB情节,一些椭圆。 我想这个情节转换为二进制图像。 有人能帮我吗?

与椭圆的图像显示在这里 -

在此先感谢您的帮助!

Answer 1:

%%// ---- Your Plot done until this point

%%// Remove frames
set(gca, 'visible', 'off')
set(gcf, 'color', 'w');

%%// Get the figure as a uint8 variable
im = export_fig;

%//  Output binary image
BW = ~im2bw(uint8(255.*im2double(im)),0.99);

注意:您需要得到export_fig和相关的功能在这里 。

样品箱1

h = figure()
plot(1:10);

%%// ---- Your Plot done until this point

%%// Remove frames
set(gca, 'visible', 'off')
set(gcf, 'color', 'w');

%%// Get the figure as a uint8 variable
im = export_fig;

%//  Output binary image
BW = ~im2bw(uint8(255.*im2double(im)),0.99);

figure,imshow(BW)

产量

样本案例2具有扩展功能

可以用执行二进制骨架bwmorph ,保持边缘宽度为1 ,这是在此情况下样品进行。

figure,
hold on

x1=-2;y1 = 0;x2=2;y2=0;
e = 0.6;
[x,y] = ellipse1(x1,y1,x2,y2,e);
plot(x,y,'b-')

x1=-15;y1 = 4;x2=-5;y2=3;
e = 0.95;
[x,y] = ellipse1(x1,y1,x2,y2,e);
plot(x,y,'b-');

%%// Remove frames
set(gca, 'visible', 'off')
set(gcf, 'color', 'w');

%%// Get the figure as a uint8 variable
im = export_fig;

%//  Output binary image
BW = ~im2bw(uint8(255.*im2double(im)),0.99);

%%// Remove
BW = bwmorph(BW,'skel',Inf);

figure,imshow(BW)

相关联的功能 ( 源 )

function [x,y] = ellipse1(x1,y1,x2,y2,e)

a = 1/2*sqrt((x2-x1)^2+(y2-y1)^2);
b = a*sqrt(1-e^2);
t = linspace(0,2*pi);
X = a*cos(t);
Y = b*sin(t);
w = atan2(y2-y1,x2-x1);
x = (x1+x2)/2 + X*cos(w) - Y*sin(w);
y = (y1+y2)/2 + X*sin(w) + Y*cos(w);

return;

产量



Answer 2:

你可以先抓住人物,那么它的“CDATA”的框架。 一个例子是这里给出: http://tipstrickshowtos.blogspot.com/2010/03/saving-image-of-matlab-figure.html



文章来源: Convert a plot with ellipses to binary image in MATLAB