近デジ画像処理めも

…-trim オプションは「角のピクセルと同じ色」を除去する…-fuzz というオプション…パラメータをいじると除去の度合いが変化します(大きくなると除去する範囲が広がる)。
…せっかくなので(-level オプションで)レベル補正…
さらに固定幅の余白を付けたい場合は -border …


1)画像全体を縮小します。…とりあえず64×64に縮小
2)境界を認識するために隣り合ったピクセルの明るさの差をとります。…真ん中2分の1だけを取って、縦の差分は全部加算しておきます。縦方向の境界認識でも同様の操作をしています。
3)「このへんに本文の境界がありそうだ」という元々の知識(=ベイズ統計学でいう事前情報)を確率関数化して、先ほどのピクセルの明るさの差に掛けあわせます。確率関数は本文の上下左右にそれぞれ1つずつの4つ用意します。
4)確率関数を掛けあわせた明暗の変化が最も大きい点が境界として選ばれます。

キャニーエッジ検出

Canny Edge Detectionのアルゴリズムは次の手順。
STEP1:ガウシアンフィルタで平滑化
STEP2:エッジ強度(Sobelフィルタ)と勾配方向(4方向に量子化)を計算
STEP3:細線化処理(Non-maximum Suppression)
STEP4:ヒステリシス閾処理(Hysteresis Threshold)
 :
二つしきい値(LT, HT)を与えて以下の条件でエッジどうか判定
1. HTより大きいエッジ強度の画素はエッジ
2. LHより小さいエッジ強度の画素は非エッジ
3. LH以上HT以下のエッジ強度の画素のうちエッジに結合してる画素はエッジ

Sobel(ゾーベル)フィルタ

Canny does use two thresholds (upper and lower):
 :
Canny recommended a upper:lower ratio between 2:1 and 3:1.

LT, HT、Sobelフィルタのアパーチャサイズを変更したときの違いを出してくださっている。

各種微分フィルタの違い

OpenCVのcanny

  • canny(thresh1,thresh2[,aperture_size = 3]) → cvmat

Canny algorithm for edge detection.

  • C: void cvCanny(const CvArr* image, CvArr* edges, double threshold1, double threshold2, int aperture_size=3 )

apertureSize – aperture size for the Sobel() operator.

OpenCVのprobabilistic Hough transform

  • hough_line_probabilistic(rho, theta, threshold, min_length, max_gap)
  • hough_lines(:probabilistic, rho, theta, threshold, min_length, max_gap) → cvseq(include CvTwoPoints)
  • rho - Distance resolution in pixel-related units.
  • theta - Angle resolution measured in radians.
  • threshold - Threshold parameter. A line is returned by the function if the corresponding accumulator value is greater than threshold.
  • min_length - The minimum line length.
  • max_gap - The maximum gap between line segments lieing on the same line to treat them as the single line segment (i.e. to join them).
  • http://www.ruby-doc.org/gems/docs/o/opencv-0.0.6/OpenCV/CvMat.html#method-i-hough_lines_probabilistic