这是我在这里的第一个问题,我在matlab中有一个带有一些省略号的情节。我想将此图转换为二进制图像。 有人能帮助我吗?
带有省略号的图像显示在这里 -
提前感谢您的帮助!
答案 0 :(得分:2)
<强>代码强>
%%// ---- 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);
注意:您需要从here获取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)
相关功能(source)
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;
<强>输出强>
答案 1 :(得分:0)
你可以先抓住图的框架,然后抓住它的&#34; cdata&#34;。这里给出一个例子:http://tipstrickshowtos.blogspot.com/2010/03/saving-image-of-matlab-figure.html