2014-04-05 2 views
1

으로 변환합니다. 여기가 저의 첫 번째 질문이며 일부 줄임표가있는 matlab에 줄거리가 있습니다. 이 그림을 이진 이미지로 변환하고 싶습니다. 누군가 나를 도울 수 있습니까? 타원과줄임표가있는 플롯을 MATLAB의 이진 이미지

이미지가 여기에 표시됩니다 -

enter image description here

감사합니다 사전에 어떤 도움을!

답변

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) 

확장 기능을 사용하여 출력

enter image description here

샘플 케이스 2

당신은 진 골격을 수행 할 수 있습니다 에지 폭을 으로 유지하려면이 예제의 경우와 같이 bwmorph을 사용하십시오.

코드

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; 

출력

enter image description here