情報の大半は、コードのコメントであるが、ここでは簡単な概要です:
私は形態的フィルタを使用して、いくつかの予備的な画像のクリーニングをしました(私はガウスフィルタまたは類似したばかりのように効果的な証明すると確信しています)
私のアプローチは、行情報を使って行を見つける方法でした。単一の列を取り、ピクセル値をプロットすることを考えてください。線(または黒いテキスト)は、この形式で簡単に表示する必要があります。だから私は行全体の平均を取って、そのプロファイルを使って行を見つけるのを助けました。行が横切っているので、すべての値が低くなり、強いピークが生成されます。文字には白いスペースが多いので、行の平均にはより多くの白いピクセルが含まれているため、ピークは明確に定義されません
最後に、このプロファイルの2つの最大ピーク)は線でなければなりません。
は残念ながら、私は2つのパラメータのいくつかの実証分析(推測とチェック)を行なったし、彼らは変更
st_size
画像のクリーニングに使用する構造要素の大きさが必要な場合があります。すべての画像がほぼ同じサイズであれば、これは変更する必要はありません。自動的に決定されませんが、これは設定されたサイズのスムージングフィルタを使用する場合と変わりません。したがって、多くの問題が発生しないようにしてください。
mask_thresh
ピークを検出する値。これは他の画像に問題を引き起こす可能性があります。基準は、それがbot_lin_loc
よりも低いが、手書きのテキストセクションのピークよりも高いことであった。私は単に最大ピークこれはアルゴリズムで最も弱いリンクであり、あなたの側でより多くのチューニングを必要とするかもしれないの1/3それを作った
im = imread('http://i.stack.imgur.com/1mO1S.jpg');
gim = rgb2gray(im);
[im_h,im_w] = size(gim);
%this is a quick attempt to remove background noise, the goal is to remove
%all the letters, and what you are left with is background
st_size = 10;
st = strel('disk',10);
im_background = imdilate(gim,st);
%now we take the difference between our background and original image
im_foreground = abs(im_background-gim);
%reduce the image to a row average to find lines
rowavg = mean(im_foreground,2);
%peak threshold (unfortunately this was determined empircally,I'm not sure
%if it could easily be automated)
mask_thresh = max(rowavg)/3;
masked = rowavg > mask_thresh;
%finds the peaks using the values over the threshold (this is sort of like
%non-maxima suppression)
potential_peak_idx = find(masked);
[~,peak_loc] = findpeaks(double(masked));
%at this point we assume the two "lines" closest to the bottom of the image
%are the lines that outline the text
bot_lin_loc = peak_loc(end);
top_lin_loc = peak_loc(end-1);
%% plots results
figure(1)
subplot(2,2,1); imshow(gim); title('bw input image');
subplot(2,2,2); imshow(im_background); title('background image');
subplot(2,2,3); imshow(im_foreground); title('foreground image');
subplot(2,2,4);
imshow(im);
hold on
line([0,im_w],[top_lin_loc, top_lin_loc],'color','g')
line([0,im_w],[bot_lin_loc, bot_lin_loc],'color','r')
plot(rowavg,(1:1:numel(rowavg)),'color','b')
hold off
title('annotated image');
figure(2)
plot(rowavg); title('row average')
hold on
grid on
scatter(peak_loc,rowavg(peak_loc))
line([0,im_h],[mask_thresh, mask_thresh],'color','g')
hold off
legend('rowavg profile','peaks','peak threshold')
%this is just a large version of subplot 4
figure(3)
imshow(im);
hold on
line([0,im_w],[top_lin_loc, top_lin_loc],'color','g')
line([0,im_w],[bot_lin_loc, bot_lin_loc],'color','r')
plot(rowavg,(1:1:numel(rowavg)),'color','b')
hold off
legend('top loc','bot loc','row avg')
title('annotated image');
と画像処理コードので、ここでは、絵のない価値がありません結果は
[