Matlab曲线拟合线槽字母与图像处理

时间:2018-02-28 11:02:11

标签: matlab image-processing curve-fitting

对于一个项目,我试图制作一个参考轨迹,写一些手写字体。因此我使用.png文件作为所有字母,例如:

letter a i am trying to fit

所以我想在Matlab中做的事情是这样的:(但是比整洁而没有用油漆做)

enter image description here

意思是红线应该是整个字母的单行。

我已经尝试过使用: bwboundaries:这给了我边界,我无法真正看到这将如何给我平均"

result with bwboundaries

houghlines:不给出我想要的结果(虽然接近)

enter image description here

代码bwboundaries:

BW = imbinarize(I,'adaptive','Sensitivity',1);
BW = imcomplement(BW)
[IM_b,~,~,IM_a] = bwboundaries(BW,'holes');
for i = 1:length(IM_b)
plot(IM_b{i}(1:end,2),-IM_b{i}(1:end,1)); hold on;
end

代码houghlines:

BW = imbinarize(I,'adaptive','Sensitivity',1);
BW = imcomplement(BW)
[H,T,R] = hough(BW);
imshow(H,[],'XData',T,'YData',R,...
'InitialMagnification','fit');
xlabel('\theta'), ylabel('\rho');
axis on, axis normal, hold on;

P  = houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))));
x = T(P(:,2)); y = R(P(:,1));
plot(x,y,'s','color','white');

lines = houghlines(BW,T,R,P,'FillGap',2,'MinLength',25);
figure, imshow(I), hold on
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');

% Plot beginnings and ends of lines
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');

% Determine the endpoints of the longest line segment
len = norm(lines(k).point1 - lines(k).point2);
if ( len > max_len)
max_len = len;
xy_long = xy;
end
end

0 个答案:

没有答案