JP6108100B2 - Document image skew correction device - Google Patents

Document image skew correction device Download PDF

Info

Publication number
JP6108100B2
JP6108100B2 JP2013108627A JP2013108627A JP6108100B2 JP 6108100 B2 JP6108100 B2 JP 6108100B2 JP 2013108627 A JP2013108627 A JP 2013108627A JP 2013108627 A JP2013108627 A JP 2013108627A JP 6108100 B2 JP6108100 B2 JP 6108100B2
Authority
JP
Japan
Prior art keywords
character
pixel
pixels
image
vertical direction
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Expired - Fee Related
Application number
JP2013108627A
Other languages
Japanese (ja)
Other versions
JP2014230119A (en
Inventor
茂出木 敏雄
敏雄 茂出木
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Dai Nippon Printing Co Ltd
Original Assignee
Dai Nippon Printing Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Dai Nippon Printing Co Ltd filed Critical Dai Nippon Printing Co Ltd
Priority to JP2013108627A priority Critical patent/JP6108100B2/en
Publication of JP2014230119A publication Critical patent/JP2014230119A/en
Application granted granted Critical
Publication of JP6108100B2 publication Critical patent/JP6108100B2/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Description

本発明は、紙等の媒体を光学的に読み取って得られた文書画像の傾き補正に関し、特に、高精度に傾きを補正するための技術に関する。   The present invention relates to tilt correction of a document image obtained by optically reading a medium such as paper, and more particularly to a technique for correcting tilt with high accuracy.

電子データが存在しない印刷物を基に電子化する場合、製本形態をページ単位に分離してスキャン(光学的読取)する方法が行われるが、スキャン時に少なからず傾きが発生してしまう。わずかな傾きでも、水平な罫線は斜めになり、ランレングス符号量は増大するとともに、斜め線の画素サンプリングに伴うジャギー(エイリアシング)が発生してしまい、解像度が低い電子ディスプレイで表示したりズーム表示を行うと目立つようになる。従って、できる限り水平になるように回転補正することが望まれるが、回転角が微小量であるため手動計測は難しく、計測精度が悪い角度で回転補正をかけると逆効果になるという問題がある。   In the case of digitizing based on a printed matter in which electronic data does not exist, a method of scanning the bookbinding form in units of pages (scanning optically) is performed. However, there is a slight inclination during scanning. Even if it is slightly tilted, the horizontal ruled lines become diagonal, the run-length code amount increases, and jaggy (aliasing) occurs due to pixel sampling of the diagonal lines, which can be displayed on a low-resolution electronic display or zoom display If you do it, it will stand out. Therefore, it is desirable to correct the rotation so that it is as horizontal as possible. However, since the rotation angle is very small, manual measurement is difficult, and there is a problem that if rotation correction is performed at an angle with poor measurement accuracy, the reverse effect is obtained. .

この対策として、原稿に角度計測用のマークを付与してスキャンする方法がとられている。印刷物の製版工程では色見当合せ用のトンボが付与されているが、印刷物の段階でトリミングされ、通常の印刷物には基準マークがない。このため、文書中の罫線などを基準に補正する方法(特許文献1参照)や、マークが付与された台紙に貼ってスキャンする方法(特許文献2参照)が提案されている。   As a countermeasure against this, a method of scanning an original with an angle measurement mark is employed. In the printing plate making process, a register mark for color registration is provided, but trimming is performed at the stage of the printed material, and a normal printed material has no reference mark. For this reason, there are proposed a method of correcting a ruled line in a document as a reference (see Patent Document 1) and a method of scanning by pasting on a mount with a mark (see Patent Document 2).

また、文字部の背景に注目し、3×3画素のマスクパターンを用いて背景画像中の文字領域の孤立画素を順次背景色で塗りつぶして、文字の組版方向に細線化された線分を作成し、線分の角度を算出することにより、傾きを検出する方法(特許文献3参照)も提案されている。また、文書画像を所定の幅の矩形領域の部分画像に分割し、文字組版方向の傾き角を計算する方法(特許文献4参照)も提案されている。   In addition, paying attention to the background of the character part, using a 3x3 pixel mask pattern, the isolated pixels in the character area in the background image are sequentially painted with the background color to create a thin line segment in the character composition direction. And the method (refer patent document 3) which detects the inclination by calculating the angle of a line segment is also proposed. In addition, a method of dividing a document image into partial images of a rectangular area having a predetermined width and calculating an inclination angle in a character composition direction has been proposed (see Patent Document 4).

特開平9−83740号公報JP-A-9-83740 特許第3443141号公報Japanese Patent No. 3443141 特許第2554943号公報Japanese Patent No. 2554943 特許第3876531号公報Japanese Patent No. 38765531

しかしながら、特許文献1に記載の技術については、一般書籍の各ページにおいては罫線が全く存在しない方が一般的であるため、適用できないという問題がある。また、特許文献2に記載の技術については、台紙に貼った段階で発生する傾きは補正できないという問題がある。特許文献3に記載の技術については、3×3画素のマスクパターンの設定方法が問題で、文字のフォントやサイズが多様になると、それに応じてマスクパターンを準備しないと、細線化処理が適切に機能しなくなり、線分の角度算出が不能になるという懸念がある。特許文献4に記載の技術については、部分画像の大きさの設定方法が問題で、部分画像内に複数行の文字が配置されたり、文字幅が部分画像をはみ出すような設定をすると、傾き角を算出できなくなるという懸念がある。   However, the technique described in Patent Document 1 has a problem that it cannot be applied to each page of a general book because there is generally no ruled line at all. In addition, the technique described in Patent Document 2 has a problem that the tilt generated at the stage of pasting on the mount cannot be corrected. Regarding the technique described in Patent Document 3, there is a problem with a method of setting a mask pattern of 3 × 3 pixels. When the font and size of a character are varied, a thinning process is appropriately performed unless a mask pattern is prepared accordingly. There is a concern that it will not function and the angle of the line segment cannot be calculated. The technique described in Patent Document 4 has a problem with the method of setting the size of the partial image. If a plurality of lines of characters are arranged in the partial image or the character width is set to protrude from the partial image, the inclination angle There is a concern that it will be impossible to calculate.

そこで、本発明は、文字組版を基調とした印刷物を光学的に読み取って得られた文書画像に対して、基準線が存在しない場合であっても、高精度な傾き補正を行うことが可能な文書画像の傾き補正装置を提供することを課題とする。   Accordingly, the present invention can perform highly accurate tilt correction even when a reference line does not exist for a document image obtained by optically reading a printed matter based on character composition. It is an object of the present invention to provide a document image inclination correction apparatus.

上記課題を解決するため、本発明第1の態様では、光学的読み取りを行って得られた文書画像に対して、光学的読み取り時の傾きを補正する装置であって、前記文書画像の各画素の値としきい値を比較して二値化し、二値画像を作成する二値化手段と、前記二値画像のうち、一方の値をとる画素を文字画素、他方の値をとる画素を背景画素とし、前記二値画像に対して水平方向または垂直方向に文字画素が存在する文字画素領域を膨張させる文字画素領域膨張手段と、前記水平方向に膨張させた二値画像内の文字画素領域のエッジ部より水平方向の折れ線を複数抽出するか、前記垂直方向に膨張させた二値画像内の文字画素領域のエッジ部より垂直方向の折れ線を複数抽出するようにしているエッジ抽出手段と、前記抽出された複数の折れ線を構成する頂点座標列をもとに、各々の折れ線を直線近似し、各々の近似直線の傾き角を算出する傾き角算出手段と、前記算出された複数の折れ線の傾き角の平均値に基づいて、前記文書画像に対して回転処理を施す文書回転手段と、を備えることを特徴とする文書画像の傾き補正装置を提供する。   In order to solve the above problems, according to the first aspect of the present invention, there is provided an apparatus for correcting a tilt at the time of optical reading for a document image obtained by optical reading, wherein each pixel of the document image is corrected. Binarization means for comparing the value of the image with a threshold value to create a binary image, and among the binary image, a pixel having one value is a character pixel, and a pixel having the other value is a background. A character pixel region expansion means for expanding a character pixel region in which character pixels exist in a horizontal direction or a vertical direction with respect to the binary image, and a character pixel region in the binary image expanded in the horizontal direction. Edge extraction means for extracting a plurality of horizontal broken lines from the edge portion or extracting a plurality of vertical broken lines from the edge portion of the character pixel region in the binary image expanded in the vertical direction; Multiple extracted linestrings Based on the vertex coordinate sequence that constitutes, based on the average value of the calculated inclination angles of the plurality of polygonal lines, linear approximation of each polygonal line, and calculating the inclination angle of each approximate line There is provided a document image tilt correction device comprising: a document rotation unit that performs a rotation process on the document image.

本発明第1の態様によれば、イメージスキャナ等によりスキャニングされて得られた文書画像の各画素の値としきい値を比較して二値化して二値画像を作成し、二値画像のうち、一方の値をとる画素を文字画素、他方の値をとる画素を背景画素とし、二値画像に対して水平方向または垂直方向に文字画素が存在する文字画素領域を膨張させる文字画素領域膨張手段と、二値画像に対して水平または垂直のいずれかの方向に文字画素を膨張させ、水平方向に膨張させた二値画像内の文字画素領域のエッジ部より水平方向の折れ線を複数抽出するか、垂直方向に膨張させた二値画像内の文字画素領域のエッジ部より垂直方向の折れ線を複数抽出するようにし、抽出された複数の折れ線を構成する頂点座標列をもとに、各々の折れ線を直線近似し、各々の近似直線の傾き角を算出し、算出された全ての折れ線の傾き角の平均値に基づいて、スキャニングされた文書画像に対して回転処理を施すようにしたので、文字組版を基調とした印刷物を光学的に読み取って得られた文書画像に対して、基準線が存在しない場合であっても、高精度な傾き補正を行うことが可能となる。   According to the first aspect of the present invention, the value of each pixel of a document image obtained by scanning with an image scanner or the like is compared with a threshold value to generate a binary image, Character pixel area expansion means for expanding a character pixel area in which a character pixel exists in a horizontal direction or a vertical direction with respect to a binary image with a pixel having one value as a character pixel and a pixel having the other value as a background pixel And whether to extract multiple horizontal lines from the edge of the character pixel area in the binary image expanded in the horizontal direction and the character pixels expanded horizontally or vertically with respect to the binary image. In the binary image expanded in the vertical direction, a plurality of vertical lines are extracted from the edge of the character pixel area, and each polygonal line is formed based on the vertex coordinate sequence constituting the plurality of extracted lines. Is approximated by a straight line, Since the inclination angle of each approximate line was calculated, and the scanned document image was rotated based on the average value of the inclination angles of all the calculated polygonal lines, the character composition was used as the keynote. Even when a reference line does not exist for a document image obtained by optically reading a printed material, it is possible to perform highly accurate tilt correction.

また、本発明第2の態様では、前記二値化手段は、水平方向の全画素に占める文字画素の割合と、垂直方向の全画素に占める文字画素の割合を算出し、水平方向の全画素に占める文字画素の割合が垂直方向の全画素に占める文字画素の割合より大きい場合は横組と、垂直方向の全画素に占める文字画素の割合が水平方向の全画素に占める文字画素の割合より大きい場合は縦組と判定し、前記文字画素領域膨張手段は、前記二値化手段により横組と判定された場合、水平方向に文字画素領域を膨張させるようにし、前記二値化手段により縦組と判定された場合、垂直方向に文字画素領域を膨張させるようにしていることを特徴とする。   In the second aspect of the present invention, the binarization means calculates the ratio of the character pixels occupying all the pixels in the horizontal direction and the ratio of the character pixels occupying all the pixels in the vertical direction. If the percentage of character pixels in the vertical direction is greater than the percentage of character pixels in all vertical pixels, the percentage of character pixels in horizontal composition and the total number of vertical pixels is greater than the percentage of character pixels in the horizontal direction. If it is larger, it is determined as a vertical composition, and the character pixel area expansion means expands the character pixel area in the horizontal direction when it is determined as horizontal composition by the binarization means, and the binarization means performs the vertical composition. When it is determined as a set, the character pixel region is expanded in the vertical direction.

本発明第2の態様によれば、二値化の際、水平方向の全画素に占める文字画素の割合と、垂直方向の全画素に占める文字画素の割合を算出し、前者が後者より大きい場合は横組と、後者が前者より大きい場合は縦組と判定し、横組と判定された場合、水平方向に文字画素を膨張させるようにし、縦組と判定された場合、垂直方向に文字画素を膨張させるようにしたので、横組であるか縦組であるかを的確に判断して、それぞれに対応した補正を行うことが可能となる。   According to the second aspect of the present invention, when binarization is performed, the ratio of character pixels to all pixels in the horizontal direction and the ratio of character pixels to all pixels in the vertical direction are calculated, and the former is larger than the latter If the latter is greater than the former, it is determined to be vertical, and if it is determined to be horizontal, character pixels are expanded in the horizontal direction. If it is determined to be vertical, character pixels are determined in the vertical direction. Therefore, it is possible to accurately determine whether the set is horizontal or vertical and perform corrections corresponding to each.

また、本発明第3の態様では、前記文字画素領域膨張手段は、対象とする背景画素より水平方向にD画素(D>2)以内に文字画素が少なくとも1つ存在するか、当該背景画素より垂直方向にD画素以内に文字画素が少なくとも1つ存在する場合に、当該背景画素を文字画素に置換することにより、水平方向または垂直方向に文字画素領域を膨張させるようにしていることを特徴とする。   Further, in the third aspect of the present invention, the character pixel area expanding means has at least one character pixel within D pixels (D> 2) in the horizontal direction from the target background pixel, or from the background pixel. When at least one character pixel exists within D pixels in the vertical direction, the character pixel region is expanded in the horizontal direction or the vertical direction by replacing the background pixel with the character pixel. To do.

本発明第3の態様によれば、文字画素領域を膨張させる際、対象とする背景画素より水平方向にD画素(D>2)以内に文字画素が少なくとも1つ存在するか、垂直方向にD画素以内に文字画素が少なくとも1つ存在する場合に、その背景画素を文字画素に置換することにより、水平方向または垂直方向に膨張させるようにしたので、文字画素領域を適正に膨張させることが可能となる。   According to the third aspect of the present invention, when the character pixel region is expanded, at least one character pixel exists within D pixels (D> 2) in the horizontal direction from the target background pixel, or D in the vertical direction. When there is at least one character pixel within the pixel, the background pixel is replaced with the character pixel so that it can be expanded horizontally or vertically, so that the character pixel area can be expanded appropriately. It becomes.

また、本発明第4の態様では、前記エッジ抽出手段は、前記水平方向の折れ線を抽出するにあたり、前記水平方向に文字画素領域を膨張させた二値画像に対して垂直方向に文字画素が2個以上連続しないように補正し、前記垂直方向の折れ線を抽出するにあたり、前記垂直方向に文字画素領域を膨張させた二値画像に対して水平方向に文字画素が2個以上連続しないように補正していることを特徴とする。   In the fourth aspect of the present invention, when the edge extraction means extracts the horizontal polygonal line, the edge extraction unit has two character pixels in the vertical direction with respect to the binary image obtained by expanding the character pixel region in the horizontal direction. When extracting the polygonal line in the vertical direction, the correction is made so that two or more character pixels do not continue in the horizontal direction with respect to the binary image in which the character pixel area is expanded in the vertical direction. It is characterized by that.

本発明第4の態様によれば、水平方向の折れ線を抽出するにあたり、水平方向に文字画素領域を膨張させた二値画像に対して垂直方向に文字画素が2個以上連続しないように補正し、垂直方向の折れ線を抽出するにあたり、垂直方向に文字画素領域を膨張させた二値画像に対して水平方向に文字画素が2個以上連続しないように補正するようにしたので、的確なエッジの抽出が可能となる。   According to the fourth aspect of the present invention, in extracting a horizontal polygonal line, correction is performed so that two or more character pixels do not continue in the vertical direction with respect to a binary image in which the character pixel region is expanded in the horizontal direction. In extracting the vertical broken line, the binary image obtained by expanding the character pixel region in the vertical direction is corrected so that two or more character pixels are not consecutive in the horizontal direction. Extraction is possible.

また、本発明第5の態様では、前記エッジ抽出手段は、前記水平方向の折れ線を抽出するにあたり、前記水平方向に文字画素領域を膨張させた二値画像に対して垂直方向に文字画素が連続する箇所を抽出し、抽出箇所の開始点または終了点の画素以外を背景画素に置換することにより、垂直方向に文字画素が2個以上連続しないようにし、前記垂直方向の折れ線を抽出するにあたり、前記垂直方向に文字画素領域を膨張させた二値画像に対して水平方向に文字画素が連続する箇所を抽出し、抽出箇所の開始点または終了点の画素以外を背景画素に置換することにより、水平方向に文字画素が2個以上連続しないようにしていることを特徴とする。   In the fifth aspect of the present invention, when the edge extraction means extracts the horizontal polygonal line, the character pixels are continuous in the vertical direction with respect to the binary image obtained by expanding the character pixel region in the horizontal direction. In order to extract two or more character pixels in the vertical direction by extracting a portion to be extracted and replacing the pixels other than the start point or end point pixel of the extraction portion with a background pixel, By extracting the place where the character pixel continues in the horizontal direction with respect to the binary image in which the character pixel area is expanded in the vertical direction, by replacing the pixels other than the start point or end point pixel of the extraction place with the background pixel It is characterized in that two or more character pixels are not continued in the horizontal direction.

本発明第5の態様によれば、水平方向の折れ線を抽出するにあたり、水平方向に膨張させた文字画素領域を二値画像に対して垂直方向に文字画素が連続する箇所を抽出し、抽出箇所の開始点または終了点の画素以外を背景画素に置換することにより、垂直方向に文字画素が2個以上連続しないようにし、垂直方向の折れ線を抽出するにあたり、垂直方向に文字画素領域を膨張させた二値画像に対して水平方向に文字画素が連続する箇所を抽出し、抽出箇所の開始点または終了点の画素以外を背景画素に置換することにより、水平方向に文字画素が2個以上連続しないようにしたので、的確なエッジの抽出が可能となる。   According to the fifth aspect of the present invention, in extracting a horizontal polygonal line, a character pixel region expanded in the horizontal direction is extracted at a position where character pixels are continuous in the vertical direction with respect to the binary image, and the extracted portion By substituting the background pixels for pixels other than the start point or end point, the character pixel area is expanded in the vertical direction so that two or more character pixels do not continue in the vertical direction and the vertical broken line is extracted. Extract two or more consecutive character pixels in the horizontal direction from the binary image, and replace the pixels other than the pixel at the start or end of the extracted location with the background pixels, so that two or more character pixels continue in the horizontal direction. As a result, it is possible to accurately extract edges.

また、本発明第6の態様では、前記エッジ抽出手段は、水平方向に隣接する文字画素が垂直方向に上下M画素(M>1)以内に収まっている文字画素の座標列を前記水平方向の折れ線の頂点座標列として抽出するようにし、垂直方向に隣接する文字画素が水平方向に左右M画素以内に収まっている文字画素の座標列を前記垂直方向の折れ線の頂点座標列として抽出するようにしていることを特徴とする。   In the sixth aspect of the present invention, the edge extraction means may extract a coordinate string of character pixels in which character pixels adjacent in the horizontal direction are within vertical M pixels (M> 1) in the vertical direction. It is extracted as a vertex coordinate sequence of a polygonal line, and a coordinate sequence of character pixels in which character pixels adjacent in the vertical direction are within M pixels in the horizontal direction is extracted as a vertex coordinate sequence of the vertical polygonal line. It is characterized by.

本発明第6の態様によれば、水平方向に隣接する文字画素が垂直方向に上下M画素(M>1)以内に収まっている文字画素の座標列を水平方向の折れ線の頂点座標列として抽出し、垂直方向に隣接する文字画素が水平方向に左右M画素以内に収まっている文字画素の座標列を前記垂直方向の折れ線の頂点座標列として抽出するようにしたので、所定以上の長さをもつエッジを的確に抽出することが可能となる。   According to the sixth aspect of the present invention, a character string coordinate sequence in which character pixels adjacent in the horizontal direction are within the vertical M pixels (M> 1) in the vertical direction is extracted as the vertex coordinate sequence of the horizontal broken line. In addition, the character pixel coordinate sequence in which the character pixels adjacent in the vertical direction are within M pixels in the horizontal direction is extracted as the vertex coordinate sequence of the vertical broken line. It is possible to accurately extract the edges that have them.

また、本発明第7の態様では、前記エッジ抽出手段は、前記水平方向に文字画素領域を膨張させた二値画像に対して、垂直方向の一方から他方に向かって探索して前記水平方向の複数の折れ線を第1折れ線群として抽出するとともに、垂直方向の他方から一方に向かって探索して前記水平方向の複数の折れ線を第2折れ線群として抽出するか、または前記垂直方向に文字画素領域を膨張させた二値画像に対して、水平方向の一方から他方に向かって探索して前記垂直方向の複数の折れ線を第1折れ線群として抽出するとともに、水平方向の他方から一方に向かって探索して前記垂直方向の複数の折れ線を第2折れ線群として抽出するようにし、前記傾き角算出手段は、前記第1折れ線群および前記第2折れ線群の各々の近似直線の傾き角を算出するようにし、前記文書回転手段は、前記第1折れ線群の折れ線の傾き角の平均値と前記第2折れ線群の折れ線の傾き角の平均値のいずれか絶対値が大きい方の平均値に基づいて、前記回転処理を施すようにしていることを特徴とする。   In the seventh aspect of the present invention, the edge extraction unit searches the binary image in which the character pixel region is expanded in the horizontal direction from one side in the vertical direction to the other side, and A plurality of polygonal lines are extracted as a first polygonal line group, and a plurality of horizontal polygonal lines are extracted as a second polygonal line group by searching from the other in the vertical direction to one side, or a character pixel region in the vertical direction Is searched from one side in the horizontal direction to the other to extract the plurality of vertical lines as a first line group, and the search is performed from the other in the horizontal direction to the other. Then, the plurality of broken lines in the vertical direction are extracted as a second broken line group, and the inclination angle calculating means calculates an inclination angle of each approximate straight line of the first broken line group and the second broken line group. The document rotation means is based on the average value of the larger one of the average values of the inclination angles of the polygonal lines of the first polygonal line group and the inclination angles of the polygonal lines of the second polygonal line group. The rotation process is performed.

本発明第7の態様によれば、水平方向に文字画素領域を膨張させた二値画像に対して、垂直方向の一方から他方に向かって探索して水平方向の複数の折れ線を第1折れ線群として抽出するとともに、垂直方向の他方から一方に向かって探索して水平方向の複数の折れ線を第2折れ線群として抽出するか、または垂直方向に文字画素領域を膨張させた二値画像に対して、水平方向の一方から他方に向かって探索して垂直方向の複数の折れ線を第1折れ線群として抽出するとともに、水平方向の他方から一方に向かって探索して垂直方向の複数の折れ線を第2折れ線群として抽出するようにし、第1折れ線群および第2折れ線群の各々の近似直線の傾き角を算出し、第1折れ線群の折れ線の傾き角の平均値と第2折れ線群の折れ線の傾き角の平均値のいずれか絶対値が大きい方の平均値に基づいて、回転処理を施すようにしたので、傾きの方向がいずれであっても、的確にエッジを抽出することが可能となる。   According to the seventh aspect of the present invention, for a binary image in which a character pixel region is expanded in the horizontal direction, a search is performed from one side to the other side in the vertical direction, and a plurality of horizontal lines are displayed in the first line group. And extracting a plurality of horizontal lines as a second line group by searching from one to the other in the vertical direction, or for a binary image in which the character pixel area is expanded in the vertical direction The horizontal direction is searched from one side to the other to extract a plurality of vertical broken lines as a first broken line group, and the other horizontal direction is searched from one side to the other to search for a plurality of vertical broken lines. It is extracted as a polygonal line group, the inclination angle of each approximate line of the first polygonal line group and the second polygonal line group is calculated, the average value of the inclination angle of the polygonal line of the first polygonal line group and the inclination of the polygonal line of the second polygonal line group Corner average Based on the average value of any larger absolute value of. Thus subjected to rotation processing, be either the direction of inclination, it is possible to extract accurately edges.

また、本発明第8の態様では、前記傾き角算出手段は、前記折れ線の頂点座標列の重心を算出し、重心と各頂点座標との水平方向の平均距離と、重心と各頂点座標との垂直方向の平均距離との比率に対して逆正接(arctangent)を算出することにより前記傾き角を算出するようにしていることを特徴とする。   In the eighth aspect of the present invention, the inclination angle calculation means calculates a centroid of the vertex coordinate sequence of the broken line, and calculates an average distance in the horizontal direction between the centroid and each vertex coordinate, and the centroid and each vertex coordinate. The inclination angle is calculated by calculating an arctangent with respect to a ratio to the average distance in the vertical direction.

本発明第8の態様によれば、折れ線の頂点座標列の重心を算出し、重心と各頂点座標との水平方向の平均距離と、重心と各頂点座標との垂直方向の平均距離との比率に対して逆正接(arctangent)を算出することにより傾き角を算出するようにしたので、抽出したエッジから正確な傾き角を算出することが可能となる。   According to the eighth aspect of the present invention, the centroid of the vertex coordinate sequence of the broken line is calculated, and the ratio between the average distance in the horizontal direction between the centroid and each vertex coordinate and the average distance in the vertical direction between the centroid and each vertex coordinate Since the inclination angle is calculated by calculating the arctangent, the accurate inclination angle can be calculated from the extracted edge.

また、本発明第9の態様では、前記補正画像に対して非可逆圧縮を施して所定の形式の電子文書ファイルを作成する電子文書作成手段をさらに有することを特徴とする。   The ninth aspect of the present invention is characterized by further comprising electronic document creation means for creating an electronic document file of a predetermined format by performing irreversible compression on the corrected image.

本発明第9の態様によれば、補正画像に対して非可逆圧縮を施してPDF等の電子文書ファイルを作成するようにしたので、紙媒体から読み取って電子文書ファイルを作成する際、電子文書ファイルに貼付された画像の傾きが補正されたものとなる。   According to the ninth aspect of the present invention, the irreversible compression is performed on the corrected image to create an electronic document file such as PDF. Therefore, when creating an electronic document file by reading from a paper medium, the electronic document The inclination of the image attached to the file is corrected.

また、本発明第10の態様では、前記補正画像に対して、RGB各階調の深さを所定の深さ以下(例えば16階調以下)に低下させることにより全体の色数を所定数以下(例えば256色以下)に低下させた色数削減画像を作成し、色数削減画像に対して圧縮(ZIP等の可逆圧縮またはJPEG等の非可逆圧縮)を施して所定の形式の電子文書ファイルを作成する電子文書作成手段をさらに有することを特徴とする。   In the tenth aspect of the present invention, the depth of each gradation of RGB is reduced to a predetermined depth or less (for example, 16 gradations or less) with respect to the corrected image, thereby reducing the total number of colors to a predetermined number or less ( For example, a color-reduced image reduced to 256 colors or less) is created, and compression (reversible compression such as ZIP or irreversible compression such as JPEG) is performed on the color-reduced image to generate an electronic document file in a predetermined format. It further has electronic document creation means for creating.

本発明第10の態様によれば、補正画像に対してRGB各階調の深さを所定の深さ以下に低下させることにより全体の色数を所定数以下に低下させた色数削減画像を作成し、色数削減画像に対して圧縮を施してPDF等の電子文書ファイルを作成するようにしたので、紙媒体から読み取って電子文書ファイルを作成する際、電子文書ファイルに貼付された画像の傾きが補正されたものになるとともに、画像を伸張する際、モスキートノイズの発生を低減することが可能となる。   According to the tenth aspect of the present invention, a color-number-reduced image in which the total number of colors is reduced to a predetermined number or less by reducing the depth of each RGB gradation to a predetermined depth or less with respect to the corrected image is created. Since the electronic document file such as PDF is created by compressing the color-reduced image, the inclination of the image attached to the electronic document file is created when the electronic document file is created by reading from the paper medium. Is corrected, and generation of mosquito noise can be reduced when the image is expanded.

また、本発明第11の態様では、前記電子文書作成手段は、前記補正画像を基に特定された文字コードを非描画属性に設定し、割り付け位置を維持しながら前記電子文書ファイルに組み込むようにしていることを特徴とする。   In the eleventh aspect of the present invention, the electronic document creation means sets a character code specified based on the corrected image as a non-drawing attribute and incorporates it into the electronic document file while maintaining the assigned position. It is characterized by.

本発明第11の態様によれば、補正画像を基に特定された文字コードを非描画属性に設定し、割り付け位置を維持しながら電子文書ファイルに組み込むようにしているので、PDFファイル等の電子文書ファイルを利用する際、非描画属性に設定された文字コードを利用した全文検索が可能となる。   According to the eleventh aspect of the present invention, the character code specified based on the corrected image is set as the non-drawing attribute and is incorporated into the electronic document file while maintaining the assigned position. When using a document file, a full text search using a character code set to a non-drawing attribute is possible.

本発明によれば、文字組版を基調とした印刷物を光学的に読み取って得られた文書画像に対して、基準線が存在しない場合であっても、高精度な傾き補正を行うことが可能となる。   According to the present invention, it is possible to perform highly accurate inclination correction even when a reference line does not exist for a document image obtained by optically reading a printed matter based on character composition. Become.

本発明の一実施形態に係る文書画像の傾き補正装置のハードウェア構成図である。It is a hardware block diagram of the inclination correction apparatus of the document image which concerns on one Embodiment of this invention. 本発明の一実施形態に係る文書画像の傾き補正装置の構成を示す機能ブロック図である。1 is a functional block diagram illustrating a configuration of a document image tilt correction apparatus according to an embodiment of the present invention. FIG. 本発明の一実施形態に係る文書画像の傾き補正装置の処理概要を示すフローチャートである。It is a flowchart which shows the process outline | summary of the inclination correction apparatus of the document image which concerns on one Embodiment of this invention. 横組の場合における本発明による画像の変化の様子を示す図である。It is a figure which shows the mode of the change of the image by this invention in the case of a horizontal composition. 縦組の場合における本発明による画像の変化の様子を示す図である。It is a figure which shows the mode of the change of the image by this invention in the case of a vertical composition. 水平方向(x方向)への膨張処理の様子を示す図である。It is a figure which shows the mode of the expansion process to a horizontal direction (x direction). 水平方向(x方向)のエッジ抽出・細線化処理の様子を示す図である。It is a figure which shows the mode of the edge extraction and thinning process of a horizontal direction (x direction). 横組の場合におけるベクトル抽出と傾き角算出処理の詳細を示すフローチャートである。It is a flowchart which shows the detail of the vector extraction and inclination angle calculation process in the case of a horizontal composition. 横組の場合におけるベクトル抽出における2方向の探索の様子を示す図である。It is a figure which shows the mode of the search of 2 directions in the vector extraction in the case of a horizontal composition. 横組の場合におけるベクトル抽出処理の詳細を示すフローチャートである。It is a flowchart which shows the detail of the vector extraction process in the case of a horizontal composition. ベクトル抽出処理の具体例を示す図である。It is a figure which shows the specific example of a vector extraction process. 横組に対応した抽出ベクトルを構成する頂点(黒画素)を示す図である。It is a figure which shows the vertex (black pixel) which comprises the extraction vector corresponding to horizontal composition. 縦組の場合におけるベクトル抽出と傾き角算出処理の詳細を示すフローチャートである。It is a flowchart which shows the detail of the vector extraction and inclination angle calculation process in the case of vertical composition. 縦組の場合におけるベクトル抽出における2方向の探索の様子を示す図である。It is a figure which shows the mode of the search of 2 directions in the vector extraction in the case of a vertical composition. 縦組の場合におけるベクトル抽出処理の詳細を示すフローチャートである。It is a flowchart which shows the detail of the vector extraction process in the case of a vertical composition. 縦組の場合におけるベクトル抽出処理の具体例を示す図である。It is a figure which shows the specific example of the vector extraction process in the case of a vertical composition. 縦組に対応した抽出ベクトルを構成する頂点(黒画素)を示す図である。It is a figure which shows the vertex (black pixel) which comprises the extraction vector corresponding to a vertical composition. 横組の場合における文書画像の回転の様子を示す図である。It is a figure which shows the mode of rotation of the document image in the case of a horizontal composition. 読み取った文書画像の具体例を示す図である。It is a figure which shows the specific example of the read document image. 二値化処理、水平方向の画素膨張処理後の画像の具体例を示す図である。It is a figure which shows the specific example of the image after a binarization process and the pixel expansion process of a horizontal direction. エッジ抽出・細線化処理後の画像の具体例を示す図である。It is a figure which shows the specific example of the image after an edge extraction and thinning process. 文書画像回転処理後の画像の具体例を示す図である。It is a figure which shows the specific example of the image after a document image rotation process. 色数削減処理を説明するための図である。It is a figure for demonstrating a color number reduction process.

以下、本発明の好適な実施形態について図面を参照して詳細に説明する。
<1.装置構成>
図1は、本発明の一実施形態に係る文書画像の傾き補正装置のハードウェア構成図である。本実施形態に係る文書画像の傾き補正装置は、汎用のコンピュータで実現することができ、図1に示すように、CPU(Central Processing Unit)1と、コンピュータのメインメモリであるRAM(Random Access Memory)2と、CPU1が実行するプログラムやデータを記憶するためのハードディスク、フラッシュメモリ等の大容量の記憶装置3と、キーボード、マウス等のキー入力I/F(インターフェース)4と、データ記憶媒体等の外部装置とデータ通信するためのデータ入出力I/F(インターフェース)5と、液晶ディスプレイ等の表示デバイスである表示部6と、を備え、互いにバスを介して接続されている。また、文書画像の傾き補正装置は、データ入出力I/F5を介してイメージスキャナ7と接続されている。イメージスキャナ7は、紙等のシート状の媒体から情報を光学的に読み取り画像を出力する光学的読取装置であり、公知の様々なイメージスキャナを採用することができる。
DESCRIPTION OF EXEMPLARY EMBODIMENTS Hereinafter, preferred embodiments of the invention will be described in detail with reference to the drawings.
<1. Device configuration>
FIG. 1 is a hardware configuration diagram of a document image tilt correction apparatus according to an embodiment of the present invention. The document image tilt correction apparatus according to the present embodiment can be realized by a general-purpose computer. As shown in FIG. 1, a CPU (Central Processing Unit) 1 and a RAM (Random Access Memory) which is a main memory of the computer. ) 2, a large-capacity storage device 3 such as a hard disk or flash memory for storing programs and data executed by the CPU 1, a key input I / F (interface) 4 such as a keyboard and a mouse, a data storage medium, etc. A data input / output I / F (interface) 5 for data communication with the external device and a display unit 6 which is a display device such as a liquid crystal display are connected to each other via a bus. The document image tilt correction apparatus is connected to the image scanner 7 via the data input / output I / F 5. The image scanner 7 is an optical reading device that optically reads information from a sheet-like medium such as paper and outputs an image, and various known image scanners can be employed.

図2は、本実施形態に係る文書画像の傾き補正装置の構成を示す機能ブロック図である。図2において、10は二値化手段、20は文字画素領域膨張手段、30はエッジ抽出手段、40は傾き角算出手段、50は文書回転手段、55は電子文書作成手段、60は文書画像記憶手段、70は補正画像記憶手段である。   FIG. 2 is a functional block diagram showing the configuration of the document image tilt correction apparatus according to the present embodiment. In FIG. 2, 10 is a binarizing means, 20 is a character pixel area expanding means, 30 is an edge extracting means, 40 is an inclination angle calculating means, 50 is a document rotating means, 55 is an electronic document creating means, and 60 is a document image storage. Means 70 is a corrected image storage means.

二値化手段10は、光学的読取装置であるイメージスキャナ7により光学的に読み取られた(スキャニングされた)フルカラーまたはグレースケール階調をもつ文書画像の背景領域を背景画素(本実施形態では白画素)、文字領域を文字画素(本実施形態では黒画素)に二値化し、二値画像を作成する。ここで、文書画像とは、文字組版を基調とした印刷物が読み取られることにより得られる文字列が表現された画像である。文字画素領域膨張手段20は、二値化手段10により作成された二値画像に対して水平方向または垂直方向に文字画素領域を膨張させる。エッジ抽出手段30は、水平方向または垂直方向に膨張させた二値画像内の文字画素領域のエッジ部より水平方向または垂直方向の折れ線を複数抽出する。傾き角算出手段40は、エッジ抽出手段30により抽出された複数の折れ線を構成する頂点座標列をもとに、各々の折れ線を直線近似し、各々の近似直線の傾き角を算出する。文書回転手段50は、傾き角算出手段40により算出された全ての折れ線の傾き角の平均値に基づいて、光学的に読み取られたフルカラーまたはグレースケール階調をもつ文書画像に対して回転処理を施して補正画像を作成する。電子文書作成手段55は、補正画像に対して色数削減、圧縮を施して所定の形式の電子文書ファイルを作成する。   The binarizing means 10 converts a background region of a document image having a full color or gray scale gradation optically read (scanned) by an image scanner 7 which is an optical reading device into a background pixel (in this embodiment, a white pixel). Pixel) and character area are binarized into character pixels (black pixels in this embodiment) to create a binary image. Here, the document image is an image in which a character string obtained by reading a printed matter based on a character composition is expressed. The character pixel area expansion means 20 expands the character pixel area in the horizontal direction or the vertical direction with respect to the binary image created by the binarization means 10. The edge extracting means 30 extracts a plurality of horizontal or vertical broken lines from the edge portion of the character pixel area in the binary image expanded in the horizontal direction or the vertical direction. The inclination angle calculation means 40 linearly approximates each polygonal line based on the vertex coordinate sequence constituting the plurality of polygonal lines extracted by the edge extraction means 30, and calculates the inclination angle of each approximation straight line. The document rotation means 50 performs a rotation process on the optically read document image having a full color or gray scale gradation based on the average value of the inclination angles of all the broken lines calculated by the inclination angle calculation means 40. To create a corrected image. The electronic document creation means 55 creates an electronic document file in a predetermined format by reducing the number of colors and compressing the corrected image.

文書画像記憶手段60は、コンピュータで処理可能な文書画像を記憶した記憶手段であり、RAM2により実現される。現実には、データ入出力I/F5を介して接続されたイメージスキャナ7から、スキャニングにより得られた文書画像がバスを介してRAM2に記憶される。事前に他のイメージスキャナによりスキャニングされた文書画像を記憶装置3に格納し、記憶装置3を文書画像記憶手段60として利用するようにしても良い。最近のイメージスキャナには、紙媒体から読み取った画像を圧縮してPDF等の電子文書ファイルを作成するものもあるが、そのようなイメージスキャナを用いた場合には、作成した電子文書ファイルを記憶装置3に記憶する。補正画像記憶手段70は、文書画像に対して傾き補正を行った補正画像を記憶する記憶手段であり、記憶装置3により実現される。この際、補正画像を圧縮して所定の電子文書ファイルを作成するようにしても良い。作成する電子文書ファイルとしては、様々な形式のものが利用可能であるが、本実施形態では、汎用的なフォーマットであるPDF形式を用いている。二値化手段10、文字画素領域膨張手段20、エッジ抽出手段30、傾き角算出手段40、文書回転手段50、電子文書作成手段55は、CPU1が、記憶装置3に記憶されているプログラムを実行することにより実現される。   The document image storage unit 60 is a storage unit that stores a document image that can be processed by a computer, and is realized by the RAM 2. Actually, the document image obtained by scanning from the image scanner 7 connected via the data input / output I / F 5 is stored in the RAM 2 via the bus. A document image scanned in advance by another image scanner may be stored in the storage device 3, and the storage device 3 may be used as the document image storage unit 60. Some recent image scanners compress an image read from a paper medium and create an electronic document file such as a PDF. When such an image scanner is used, the created electronic document file is stored. Store in device 3. The corrected image storage unit 70 is a storage unit that stores a corrected image obtained by performing tilt correction on the document image, and is realized by the storage device 3. At this time, the corrected image may be compressed to create a predetermined electronic document file. Various types of electronic document files can be used, but in this embodiment, the PDF format, which is a general-purpose format, is used. The binarizing means 10, the character pixel area expanding means 20, the edge extracting means 30, the tilt angle calculating means 40, the document rotating means 50, and the electronic document creating means 55 are executed by the CPU 1 executing a program stored in the storage device 3. It is realized by doing.

図2に示した各構成手段は、現実には図1に示したように、コンピュータおよびその周辺機器等のハードウェアに専用のプログラムを搭載することにより実現される。すなわち、コンピュータが、専用のプログラムに従って各手段の内容を実行することになる。なお、本明細書において、コンピュータとは、CPU等の演算処理部を有し、データ処理が可能な装置を意味する。したがって、パーソナルコンピュータであっても良いし、ハードウェア的にイメージスキャナと一体的に構成されたものであっても良い。   Each component shown in FIG. 2 is actually realized by installing a dedicated program in hardware such as a computer and its peripheral devices as shown in FIG. That is, the computer executes the contents of each means according to a dedicated program. Note that in this specification, a computer means a device that has an arithmetic processing unit such as a CPU and is capable of data processing. Therefore, it may be a personal computer or a hardware integrated with the image scanner.

図1に示した記憶装置3には、CPU1を動作させ、コンピュータを、文書画像の傾き補正装置として機能させるための専用のプログラムが実装されている。この専用のプログラムを実行することにより、CPU1は、二値化手段10、文字画素領域膨張手段20、エッジ抽出手段30、傾き角算出手段40、文書回転手段50、電子文書作成手段55としての機能を実現することになる。また、記憶装置3は、文書画像記憶手段60、補正画像記憶手段70として機能するだけでなく、文書画像の傾き補正装置としての処理に必要な様々なデータを記憶する。   The storage device 3 shown in FIG. 1 is mounted with a dedicated program for operating the CPU 1 and causing the computer to function as a document image tilt correction device. By executing this dedicated program, the CPU 1 functions as the binarization means 10, the character pixel area expansion means 20, the edge extraction means 30, the tilt angle calculation means 40, the document rotation means 50, and the electronic document creation means 55. Will be realized. The storage device 3 not only functions as the document image storage unit 60 and the corrected image storage unit 70 but also stores various data necessary for processing as a document image inclination correction device.

<2.処理動作>
<2.1.処理概要>
次に、図1、図2に示した文書画像の傾き補正装置の処理動作について説明する。図3は、本発明の一実施形態に係る文書画像の傾き補正装置の処理概要を示すフローチャートである。まず、二値化手段10が、読み込んだ文書画像に対して二値化処理を行う(ステップS10)。次に、文字画素領域膨張手段20が、水平/垂直方向膨張処理を行う(ステップS20)。続いて、エッジ抽出手段30が、水平/垂直方向エッジ抽出・細線化処理を行う(ステップS30)。そして、エッジ抽出手段30、傾き角算出手段40が、ベクトル抽出と傾き角算出処理を行う(ステップS40)。続いて、文書回転手段50が、文書画像の回転処理を行う(ステップS50)。さらに、電子文書作成手段55が、補正画像に対して色数削減、圧縮を施して所定の形式の電子文書ファイルを作成する(ステップS60)。
<2. Processing action>
<2.1. Process Overview>
Next, the processing operation of the document image inclination correction apparatus shown in FIGS. 1 and 2 will be described. FIG. 3 is a flowchart showing an outline of processing of the document image inclination correction apparatus according to the embodiment of the present invention. First, the binarization means 10 performs binarization processing on the read document image (step S10). Next, the character pixel area expansion means 20 performs horizontal / vertical direction expansion processing (step S20). Subsequently, the edge extraction means 30 performs horizontal / vertical direction edge extraction / thinning processing (step S30). Then, the edge extraction means 30 and the inclination angle calculation means 40 perform vector extraction and inclination angle calculation processing (step S40). Subsequently, the document rotation means 50 performs a document image rotation process (step S50). Further, the electronic document creation means 55 creates an electronic document file in a predetermined format by reducing the number of colors and compressing the corrected image (step S60).

図4、図5に、処理過程における画像の変化の様子を示す。図4は横組の場合、図5は縦組の場合を示している。図4(a)、図5(a)は、光学的に読み取られた文書画像であり、四角い枠は、文字の配置が傾いていることを模式的に示したものである。図4(b)、図5(b)は、ステップS20における膨張処理後の二値画像であり、黒い部分が文字画素領域を膨張させた部分である。図4(c)、図5(c)は、ステップS30におけるエッジ抽出・細線化処理後の二値画像であり、黒い部分が文字画素領域のエッジ部分である。図4(d)、図5(d)は、ステップS50における回転処理後の補正画像であり、四角い枠は、文字の配置が水平方向に並ぶように補正されたことを模式的に示したものである。   4 and 5 show how the image changes during the processing. 4 shows the case of horizontal composition, and FIG. 5 shows the case of vertical composition. FIG. 4A and FIG. 5A are optically read document images, and the square frame schematically shows that the arrangement of characters is inclined. 4B and 5B are binary images after the expansion processing in step S20, and the black portion is a portion where the character pixel region is expanded. 4C and 5C are binary images after the edge extraction / thinning process in step S30, and the black portion is the edge portion of the character pixel region. 4D and 5D are corrected images after the rotation processing in step S50, and the square frame schematically shows that the character arrangement has been corrected to be aligned in the horizontal direction. It is.

<2.2.二値化処理>
まず、ステップS10における二値化手段10による文書画像の二値化について説明する。イメージスキャナにより紙原稿をスキャンすることにより得られた文書画像の各画素値をImage(x,y)とする。x,yは画素を特定する変数であり、0≦x≦Xs−1、0≦y≦Ys−1である。したがって、文書画像は、Xs×Ys個の画素で構成される。Image(x,y)は0〜255の整数値をとるグレースケール画像である。
<2.2. Binarization processing>
First, the binarization of the document image by the binarizing means 10 in step S10 will be described. Each pixel value of a document image obtained by scanning a paper document with an image scanner is set to Image (x, y). x and y are variables for specifying a pixel, and 0 ≦ x ≦ Xs−1 and 0 ≦ y ≦ Ys−1. Therefore, the document image is composed of Xs × Ys pixels. Image (x, y) is a gray scale image having an integer value of 0 to 255.

また、二値化後の画像である二値画像の各画素値をImageB(x,y)とする。x,yは文書画像と同様、画素を特定する変数であり、0≦x≦Xs−1、0≦y≦Ys−1である。したがって、二値画像は、文書画像と同様、Xs×Ys個の画素で構成される。   Further, each pixel value of a binary image that is an image after binarization is assumed to be ImageB (x, y). Similarly to the document image, x and y are variables for specifying pixels, and 0 ≦ x ≦ Xs−1 and 0 ≦ y ≦ Ys−1. Therefore, the binary image is composed of Xs × Ys pixels, like the document image.

二値化手段10は、事前に設定された二値化しきい値S(例えば、S=200)を用いて、Image(x,y)≧Sの場合、ImageB(x,y)=255、Image(x,y)<Sの場合、ImageB(x,y)=0とする処理を行う。これにより、0〜255のグレースケール階調をもつ文書画像は、0か255のいずれかの値をもつ二値画像に変更される。通常、紙原稿において文字は黒色で表現され、背景は紙の地色の白色であることが多いため、紙媒体上の文字領域が黒色の画素に、背景領域は白色の画素に変換される。したがって、紙媒体上の文字領域は、“0”の値を持つ黒い画素に、紙媒体上の背景領域は、“255”の値を持つ白い画素に変換される。しかし、紙媒体上で文字を白、背景を黒にした場合には、文字領域は“255”の値を持つ白い画素に、背景領域は、“0”の値を持つ黒い画素に変換される。したがって、以下においては、文字領域を文字画素である黒画素、背景領域を背景画素である白画素と変換した場合を想定して説明するが、文字領域を文字画素である白画素、背景領域を背景画素である黒画素と変換するようにしても良い。   The binarization means 10 uses a preset binarization threshold S (for example, S = 200), and when Image (x, y) ≧ S, ImageB (x, y) = 255, Image In the case of (x, y) <S, a process of setting ImageB (x, y) = 0 is performed. As a result, the document image having a gray scale gradation of 0 to 255 is changed to a binary image having a value of 0 or 255. Usually, in a paper document, characters are expressed in black, and the background is often white, which is the ground color of the paper. Therefore, the character area on the paper medium is converted into black pixels, and the background area is converted into white pixels. Accordingly, the character area on the paper medium is converted into black pixels having a value of “0”, and the background area on the paper medium is converted into white pixels having a value of “255”. However, when the character is white on the paper medium and the background is black, the character area is converted to white pixels having a value of “255” and the background area is converted to black pixels having a value of “0”. . Accordingly, in the following description, it is assumed that the character area is converted to a black pixel that is a character pixel, and the background area is converted to a white pixel that is a background pixel. You may make it convert with the black pixel which is a background pixel.

次に、二値化手段10は、二値画像を水平方向、垂直方向それぞれに走査する。そして、水平方向、垂直方向それぞれについて文字画素である黒画素の割合を算出する。続いて、水平方向の全画素に占める黒画素の割合と垂直方向の全画素に占める黒画素の割合を比較する。比較の結果、水平方向の黒画素の割合の方が大きければ、横組と判断し、垂直方向の黒画素の割合の方が大きければ、縦組と判断する。具体的には、以下の〔数式1〕に従った処理を実行し、水平方向の走査線上の黒画素の割合の最大値と、垂直方向の走査線上の黒画素の割合の最大値を比較し、横組か縦組かを判断する。   Next, the binarizing means 10 scans the binary image in the horizontal direction and the vertical direction, respectively. Then, the ratio of black pixels that are character pixels is calculated in each of the horizontal direction and the vertical direction. Subsequently, the ratio of black pixels to all pixels in the horizontal direction is compared with the ratio of black pixels to all pixels in the vertical direction. As a result of comparison, if the ratio of black pixels in the horizontal direction is larger, it is determined as horizontal composition, and if the ratio of black pixels in the vertical direction is larger, it is determined as vertical composition. Specifically, the processing according to the following [Formula 1] is executed, and the maximum value of the ratio of black pixels on the horizontal scanning line is compared with the maximum value of the ratio of black pixels on the vertical scanning line. Judge whether horizontal composition or vertical composition.

〔数式1〕
MINy{ΣxImageB(x,y)}/Xs<MINx{ΣyImageB(x,y)}/Ysの場合、横組み
MINy{ΣxImageB(x,y)}/Xs>MINx{ΣyImageB(x,y)}/Ysの場合、縦組み
[Formula 1]
MIN y {Σ x ImageB (x , y)} / Xs < For MIN x {Σ y ImageB (x , y)} / Ys, horizontally arranged MIN y {Σ x ImageB (x , y)} / Xs> MIN xy ImageB (x, y)} / Ys, vertical composition

“0”と“255”の値をとる二値画像において、黒画素の値は“0”であるため、水平方向の走査線上の黒画素の割合の最大値は、MINy{ΣxImageB(x,y)}/Xsで表現され、このMINy{ΣxImageB(x,y)}/Xsが小さい場合は、水平方向の走査線上の黒画素の割合の最大値が大きいことになる。また、垂直方向の走査線上の黒画素の割合の最大値は、MINx{ΣyImageB(x,y)}/Ysで表現され、このMINx{ΣyImageB(x,y)}/Ysが小さい場合は、垂直方向の走査線上の黒画素の割合の最大値が大きいことになる。 In the binary image taking the values “0” and “255”, the value of the black pixel is “0”, so the maximum value of the ratio of black pixels on the horizontal scanning line is MIN yx ImageB ( x, is expressed by y)} / Xs, the MIN y {Σ x ImageB (x , y)} / If Xs is small, so that a large maximum percentage of black pixels in the horizontal direction of the scanning line. The maximum value of the ratio of the black pixels in the vertical direction of the scanning line is expressed by MIN x {Σ y ImageB (x , y)} / Ys , the MIN x {Σ y ImageB (x , y)} / Ys Is small, the maximum value of the ratio of black pixels on the vertical scanning line is large.

<2.3.膨張処理>
次に、ステップS20における文字画素領域膨張手段20による水平/垂直方向膨張処理について説明する。二値化手段10により横組みと判断された場合、文字画素領域膨張手段20は、水平方向膨張処理を行う。具体的には、全ての画素(x,y)(0≦x≦Xs−1、0≦y≦Ys−1)を左上(0,0)から右下(Xs−1,Ys−1)に走査して、0≦d≦D−1(D>2、例えば、D=128)なるオフセット値を定義し、d個の画素の中でImageB(x+d,y)=0なる画素が少なくとも1つ存在する場合、ImageB(x,y)=0に置換する処理を行う。これにより、各yについて、水平方向(x方向)への膨張が行われる。この際、xが最小となる黒画素より小さい側のxにおいては、黒画素への置換を行わない。水平方向(x方向)への膨張処理の様子を図6に示す。
<2.3. Expansion processing>
Next, the horizontal / vertical expansion process performed by the character pixel area expansion unit 20 in step S20 will be described. When the binarizing means 10 determines that the writing is horizontal, the character pixel area expanding means 20 performs a horizontal expansion process. Specifically, all the pixels (x, y) (0 ≦ x ≦ Xs−1, 0 ≦ y ≦ Ys−1) are changed from the upper left (0, 0) to the lower right (Xs−1, Ys−1). By scanning, an offset value of 0 ≦ d ≦ D−1 (D> 2, for example, D = 128) is defined, and at least one pixel of ImageB (x + d, y) = 0 among the d pixels If it exists, a process of replacing with ImageB (x, y) = 0 is performed. Thereby, expansion | swelling to a horizontal direction (x direction) is performed about each y. At this time, in the x smaller than the black pixel having the smallest x, the replacement with the black pixel is not performed. FIG. 6 shows the state of expansion processing in the horizontal direction (x direction).

一方、二値化手段10により縦組みと判断された場合、文字画素領域膨張手段20は、垂直方向膨張処理を行う。具体的には、全ての画素(x,y)(0≦x≦Xs−1、0≦y≦Ys−1)を左上(0,0)から右下(Xs−1,Ys−1)に走査して、0≦d≦D−1(D>2、例えば、D=128)なるオフセット値を定義し、d個の画素の中でImageB(x,y+d)=0なる画素が少なくとも1つ存在する場合、ImageB(x,y)=0に置換する処理を行う。これにより、各xについて、垂直方向(y方向)への膨張が行われる。この際、yが最小となる黒画素より小さい側のyにおいては、黒画素への置換を行わない。   On the other hand, when the binarizing means 10 determines that the text is vertically assembled, the character pixel area expanding means 20 performs a vertical expansion process. Specifically, all the pixels (x, y) (0 ≦ x ≦ Xs−1, 0 ≦ y ≦ Ys−1) are changed from the upper left (0, 0) to the lower right (Xs−1, Ys−1). By scanning, an offset value of 0 ≦ d ≦ D−1 (D> 2, for example, D = 128) is defined, and at least one pixel of ImageB (x, y + d) = 0 among the d pixels If it exists, a process of replacing with ImageB (x, y) = 0 is performed. Thereby, the expansion in the vertical direction (y direction) is performed for each x. At this time, the replacement with the black pixel is not performed for y on the side smaller than the black pixel that minimizes y.

<2.4.エッジ抽出・細線化処理>
次に、ステップS30におけるエッジ抽出手段30による水平/垂直方向エッジ抽出・細線化処理について説明する。二値化手段10により横組みと判断された場合には、エッジ抽出手段30は、水平方向エッジ抽出・細線化処理を行う。具体的には、画素(x,y)を0≦y≦Ys−2の範囲で垂直方向に走査し、ImageB(x,y)とImageB(x,y+1)が等しくない場合、ImageB(x,y)=0に置換し、ImageB(x,y)とImageB(x,y+1)が等しい場合、ImageB(x,y)=255に置換する。すなわち、垂直方向に黒画素が連続する箇所を抽出し、抽出箇所の開始点または終了点の画素以外を白画素に置換する。これにより、垂直方向に黒画素が2個以上連続しなくなる。この処理を、水平方向の全範囲(0≦x≦Xs−1)で順次行う。水平方向(x方向)のエッジ抽出・細線化処理の様子を図7に示す。図7(a)に示した文字画素領域に対して、水平方向エッジ抽出・細線化処理を行うことにより、図7(b)に示したような黒画素で表現されたエッジが抽出されることになる。
<2.4. Edge extraction and thinning process>
Next, the horizontal / vertical direction edge extraction / thinning processing by the edge extraction means 30 in step S30 will be described. If the binarizing means 10 determines that the composition is horizontal, the edge extracting means 30 performs horizontal edge extraction / thinning processing. Specifically, when the pixel (x, y) is scanned in the vertical direction within a range of 0 ≦ y ≦ Ys−2, and ImageB (x, y) and ImageB (x, y + 1) are not equal, ImageB (x, y y) = 0, and if ImageB (x, y) and ImageB (x, y + 1) are equal, replace with ImageB (x, y) = 255. That is, a portion where black pixels continue in the vertical direction is extracted, and pixels other than the pixel at the start point or end point of the extraction portion are replaced with white pixels. Thereby, two or more black pixels do not continue in the vertical direction. This process is sequentially performed in the entire horizontal range (0 ≦ x ≦ Xs−1). FIG. 7 shows a state of edge extraction / thinning processing in the horizontal direction (x direction). By performing horizontal edge extraction / thinning processing on the character pixel area shown in FIG. 7A, edges represented by black pixels as shown in FIG. 7B are extracted. become.

一方、二値化手段10により縦組みと判断された場合には、エッジ抽出手段30は、垂直方向エッジ抽出・細線化処理を行う。具体的には、画素(x,y)を0≦x≦Xs−2の範囲で水平方向に走査し、ImageB(x,y)とImageB(x+1,y)が等しくない場合、ImageB(x,y)=0に置換し、ImageB(x,y)とImageB(x+1,y)が等しい場合、ImageB(x,y)=255に置換する。水平方向に黒画素が連続する箇所を抽出し、抽出箇所の開始点または終了点の画素以外を白画素に置換することにより、水平方向に黒画素が2個以上連続しなくなる。この処理を、垂直方向の全範囲(0≦y≦Ys−1)で順次行う。   On the other hand, when the binarizing unit 10 determines that the vertical composition is set, the edge extracting unit 30 performs vertical edge extraction / thinning processing. Specifically, when the pixel (x, y) is scanned in the horizontal direction in the range of 0 ≦ x ≦ Xs−2, and ImageB (x, y) and ImageB (x + 1, y) are not equal, ImageB (x, y y) = 0, and if ImageB (x, y) and ImageB (x + 1, y) are equal, replace with ImageB (x, y) = 255. By extracting a portion where black pixels are continuous in the horizontal direction and replacing pixels other than the pixel at the start point or end point of the extraction portion with white pixels, two or more black pixels are not continuous in the horizontal direction. This process is sequentially performed in the entire vertical range (0 ≦ y ≦ Ys−1).

<2.5.1.ベクトル抽出とベクトルの角度算出処理(横組)>
次に、ステップS40におけるエッジ抽出手段30、傾き角算出手段40によるベクトル抽出とベクトルの角度算出処理について説明する。まず、横組の文書画像に好適な処理について説明する。図8は、エッジ抽出手段30、傾き角算出手段40によるベクトル抽出とベクトルの角度算出処理を示すフローチャートである。なお、ここで、抽出するベクトルとは、傾き角を求めるためのものであり、現実に抽出するのは、後述するようにN個の頂点からなる折れ線である。N個の頂点からなる折れ線は、全体として方向と大きさ(画素数)を持つため、ここでは、ベクトルと表現する。エッジ抽出手段30は、まず、第1探索モードの初期設定を行う(ステップS101)。具体的には、初期値として角度合計A=0、平均角度A1=0、抽出ベクトル数v=0に設定する。また、探索開始画素(x,y)=(0,Ys−1)に設定する。次に、傾き角算出手段40は、対象画素(x,y)を始点とするベクトルを抽出する(ステップS102)。ステップS102におけるベクトル抽出処理については、後述する。
<2.5.1. Vector extraction and vector angle calculation processing (horizontal composition)>
Next, vector extraction and vector angle calculation processing by the edge extraction unit 30 and the inclination angle calculation unit 40 in step S40 will be described. First, processing suitable for a horizontal document image will be described. FIG. 8 is a flowchart showing vector extraction and vector angle calculation processing by the edge extraction means 30 and the inclination angle calculation means 40. Here, the vector to be extracted is for obtaining an inclination angle, and what is actually extracted is a polygonal line composed of N vertices as will be described later. Since a polygonal line composed of N vertices has a direction and a size (number of pixels) as a whole, it is expressed here as a vector. The edge extraction unit 30 first performs initial setting of the first search mode (step S101). Specifically, the initial values are set to total angle A = 0, average angle A1 = 0, and number of extraction vectors v = 0. Further, the search start pixel (x, y) = (0, Ys−1) is set. Next, the inclination angle calculation means 40 extracts a vector starting from the target pixel (x, y) (step S102). The vector extraction process in step S102 will be described later.

ステップS102において、ベクトルを抽出することができた場合には、傾き角算出手段40は、抽出したベクトルの傾き角を算出する(ステップS103)。ステップS103における傾き角算出処理については、後述する。傾き角angが算出されたら、角度合計Aに傾き角angを加算する(A←A+ang)。また、抽出ベクトル数vを1だけインクリメントする(v←v+1)。   If the vector can be extracted in step S102, the inclination angle calculation means 40 calculates the inclination angle of the extracted vector (step S103). The tilt angle calculation process in step S103 will be described later. When the inclination angle ang is calculated, the inclination angle ang is added to the total angle A (A ← A + ang). Also, the number of extracted vectors v is incremented by 1 (v ← v + 1).

続いて、水平方向の画素を特定する変数xを1だけインクリメントした(ステップS104)後、水平方向の終端を示すXs−1と比較する(ステップS105)。x≦Xs−1の場合は、水平方向の終端を超えていないことになるので、ステップS102に戻って、移動した位置の画素(x,y)を始点とし、ステップS102のベクトル抽出処理を実行する。   Subsequently, the variable x specifying the pixel in the horizontal direction is incremented by 1 (step S104), and then compared with Xs-1 indicating the end in the horizontal direction (step S105). If x ≦ Xs−1, it means that the end in the horizontal direction is not exceeded, so the process returns to step S102, and the vector extraction process in step S102 is executed with the pixel (x, y) at the moved position as the starting point. To do.

ステップS105において、x>Xs−1の場合は、水平方向の終端を超えてしまうため、水平方向の画素を特定する変数xを0とし、垂直方向の画素を特定する変数yを1だけデクリメントした(ステップS106)後、垂直方向の終端を示す“0”とyの値を比較する(ステップS107)。y≧0の場合は、垂直方向の終端を超えていないことになるので、ステップS102に戻って、移動した位置の画素(x,y)を始点とし、ステップS102のベクトル抽出処理を実行する。このようにして、ステップS102〜ステップS107の処理を繰り返し、y=Ys−1側からy=0側に向かって全画素を探索することにより、角度合計Aおよび抽出ベクトル数vが得られる。   In step S105, when x> Xs-1, the horizontal end is exceeded, so the variable x for specifying the horizontal pixel is set to 0, and the variable y for specifying the vertical pixel is decremented by 1. After (step S106), the value of “0” indicating the vertical end is compared with the value of y (step S107). If y ≧ 0, the vertical end is not exceeded, so the process returns to step S102, and the vector (x, y) at the moved position is used as the starting point, and the vector extraction process in step S102 is executed. In this way, the angle sum A and the number of extraction vectors v are obtained by repeating the processing of step S102 to step S107 and searching all pixels from the y = Ys-1 side toward the y = 0 side.

全画素についての探索が終わったら、傾き角算出手段40は、角度合計Aを抽出ベクトル数vで除算する処理を実行し、抽出ベクトルの平均角度A1(=A/v)を算出する(ステップS108)。ステップS101〜ステップS108の処理で第1探索モードが終了する。   When the search for all the pixels is completed, the inclination angle calculating means 40 executes a process of dividing the angle sum A by the number of extracted vectors v, and calculates the average angle A1 (= A / v) of the extracted vectors (step S108). ). The first search mode is terminated by the processing from step S101 to step S108.

次に、エッジ抽出手段30は、第2探索モードの初期設定を行う(ステップS109)。具体的には、初期値として角度合計A=0、平均角度A2=0、抽出ベクトル数v=0に設定する。また、探索開始画素(x,y)=(0,0)に設定する。次に、エッジ抽出手段30は、対象画素(x,y)を始点とするベクトルを抽出する(ステップS110)。ステップS110におけるベクトル抽出処理については、後述する。   Next, the edge extraction unit 30 performs initial setting of the second search mode (step S109). Specifically, the initial values are set as total angle A = 0, average angle A2 = 0, and number of extraction vectors v = 0. Further, the search start pixel (x, y) = (0, 0) is set. Next, the edge extraction means 30 extracts a vector starting from the target pixel (x, y) (step S110). The vector extraction process in step S110 will be described later.

ステップS110において、ベクトルを抽出することができた場合には、傾き角算出手段40は、抽出したベクトルの傾き角を算出する(ステップS111)。ステップS111における傾き角算出処理については、後述する。傾き角angが算出されたら、角度合計Aに傾き角angを加算する(A←A+ang)。また、抽出ベクトル数vを1だけインクリメントする(v←v+1)。   If the vector can be extracted in step S110, the inclination angle calculation means 40 calculates the inclination angle of the extracted vector (step S111). The tilt angle calculation process in step S111 will be described later. When the inclination angle ang is calculated, the inclination angle ang is added to the total angle A (A ← A + ang). Also, the number of extracted vectors v is incremented by 1 (v ← v + 1).

続いて、水平方向の画素を特定する変数xを1だけインクリメントした(ステップS112)後、水平方向の終端を示すXs−1と比較する(ステップS113)。x≦Xs−1の場合は、水平方向の終端を超えていないことになるので、ステップS110に戻って、移動した位置の画素(x,y)を始点とし、ステップS110のベクトル抽出処理を実行する。   Subsequently, the variable x specifying the pixel in the horizontal direction is incremented by 1 (step S112), and then compared with Xs-1 indicating the end in the horizontal direction (step S113). If x ≦ Xs−1, it means that the end in the horizontal direction is not exceeded, so the process returns to step S110, and the vector extraction process in step S110 is executed with the pixel (x, y) at the moved position as the starting point. To do.

ステップS113において、x>Xs−1の場合は、水平方向の終端を超えてしまうため、水平方向の画素を特定する変数xを0とし、垂直方向の画素を特定する変数yを1だけインクリメントした(ステップS114)後、垂直方向の終端を示す“Ys−1”とyの値を比較する(ステップS115)。y≦Ys−1の場合は、垂直方向の終端を超えていないことになるので、ステップS110に戻って、移動した位置の画素(x,y)を始点とし、ステップS110のベクトル抽出処理を実行する。このようにして、ステップS110〜ステップS115の処理を繰り返し、y=0側からy=Ys−1側に向かって全画素を探索することにより、角度合計Aおよび抽出ベクトル数vが得られる。   In step S113, if x> Xs-1, the horizontal end is exceeded, so the variable x for specifying the pixel in the horizontal direction is set to 0, and the variable y for specifying the pixel in the vertical direction is incremented by 1. After (Step S114), “Ys−1” indicating the end in the vertical direction is compared with the value of y (Step S115). If y ≦ Ys−1, the vertical end is not exceeded, so the process returns to step S110 and the pixel (x, y) at the moved position is used as the starting point, and the vector extraction process in step S110 is executed. To do. In this way, by repeating the processing of step S110 to step S115 and searching for all pixels from the y = 0 side toward the y = Ys−1 side, the total angle A and the number of extraction vectors v are obtained.

全画素についての探索が終わったら、傾き角算出手段40は、角度合計Aを抽出ベクトル数vで除算する処理を実行し、抽出ベクトルの平均角度A2(=A/v)を算出する(ステップS116)。ステップS109〜ステップS116の処理で第2探索モードが終了する。   When the search for all the pixels is completed, the inclination angle calculation means 40 executes a process of dividing the angle sum A by the number of extracted vectors v, and calculates the average angle A2 (= A / v) of the extracted vectors (step S116). ). The second search mode is terminated by the processing from step S109 to step S116.

ステップS101〜ステップS108の第1探索モード、ステップS109〜ステップS116の第2探索モードが終了したら、傾き角算出手段40は、第1探索モードによる平均角度A1の絶対値と、第2探索モードによる平均角度A2の絶対値を比較する。そして、絶対値が大きい方の平均角度の値を平均傾き角Angとして出力する(ステップS117)。平均角度A1の絶対値と、第2探索モードによる平均角度A2の絶対値が等しい場合、本実施形態では、平均傾き角Ang=平均角度A2としているが、平均傾き角Ang=平均角度A1とするような設定であっても良い。   When the first search mode from step S101 to step S108 and the second search mode from step S109 to step S116 are finished, the tilt angle calculating means 40 is based on the absolute value of the average angle A1 in the first search mode and the second search mode. The absolute values of the average angle A2 are compared. Then, the value of the average angle with the larger absolute value is output as the average inclination angle Ang (step S117). When the absolute value of the average angle A1 is equal to the absolute value of the average angle A2 in the second search mode, in this embodiment, the average inclination angle Ang = average angle A2, but the average inclination angle Ang = average angle A1. Such a setting may be used.

ベクトル抽出処理において、互いに探索方向が逆である第1探索モードと第2探索モードを実行するようにしたのは、文字列の傾きに応じて、探索方向を変えた方が良いためである。図9に、横組の場合におけるベクトル抽出における2方向の探索の様子を示す。図9(a)(b)は文字列が左下に傾いた画像、図9(c)(d)は文字列が右下に傾いた画像を示している。文字列が左下に傾いた画像の場合、図9(a)に示すように、下から探索した場合には、エッジを検出し易いが、図9(b)に示すように、上から探索した場合には、エッジを検出し難い。また、文字列が右下に傾いた画像の場合、図9(c)に示すように、下から探索した場合には、エッジを検出し難いが、図9(d)に示すように、上から探索した場合には、エッジを検出し易い。このため、2つの方向から探索を行うようにしているのである。   In the vector extraction process, the first search mode and the second search mode in which the search directions are opposite to each other are executed because it is better to change the search direction according to the inclination of the character string. FIG. 9 shows a state of search in two directions in vector extraction in the case of horizontal composition. FIGS. 9A and 9B show images in which the character string is tilted to the lower left, and FIGS. 9C and 9D show images in which the character string is tilted to the lower right. In the case of an image in which the character string is tilted to the lower left, as shown in FIG. 9A, when searching from the bottom, it is easy to detect an edge, but as shown in FIG. 9B, the search is performed from the top. In some cases, it is difficult to detect an edge. Also, in the case of an image in which the character string is tilted to the lower right, as shown in FIG. 9C, it is difficult to detect an edge when searching from the bottom, but as shown in FIG. When searching from, it is easy to detect an edge. For this reason, the search is performed from two directions.

次に、図8のステップS102におけるベクトル抽出処理の詳細について説明する。図10は、ステップS102におけるベクトル抽出処理の詳細を示すフローチャートである。エッジ抽出手段30、は、対象画素(x,y)が黒画素であるかどうかを判断する(ステップS121)。具体的には、ImageB(x,y)=0であるかどうかを判断する。   Next, details of the vector extraction processing in step S102 of FIG. 8 will be described. FIG. 10 is a flowchart showing details of the vector extraction processing in step S102. The edge extraction unit 30 determines whether the target pixel (x, y) is a black pixel (step S121). Specifically, it is determined whether or not ImageB (x, y) = 0.

ステップS121において、対象画素(x,y)が黒画素でないと判断された場合、その対象画素(x,y)を始点とするベクトルは無いと判断して、図8のステップS104に進み、x座標を変更して、探索対象を次の画素に変更する。   If it is determined in step S121 that the target pixel (x, y) is not a black pixel, it is determined that there is no vector starting from the target pixel (x, y), and the process proceeds to step S104 in FIG. The search target is changed to the next pixel by changing the coordinates.

ステップS121において、対象画素(x,y)が黒画素であると判断された場合、その対象画素(x,y)をベクトル始点と設定し、初期設定を行う(ステップS122)。具体的には、対象画素(x,y)を重複して抽出されることを回避するため、ImageB(x,y)=255にセットし、X(0)=x、Y(0)=y、N=1、yo=y、xp=x+1、yp=yo+M(例えば、M=12)に設定する。X(0)、Y(0)はベクトル始点の座標値であり、Nは連続黒画素数であり、yoは直前の黒画素の座標値、xp、ypは次に探索する画素の座標値であり、Mは隣接する列における探索範囲を決定する変数である。   If it is determined in step S121 that the target pixel (x, y) is a black pixel, the target pixel (x, y) is set as a vector start point, and initial setting is performed (step S122). Specifically, in order to avoid redundant extraction of the target pixel (x, y), set ImageB (x, y) = 255, and X (0) = x, Y (0) = y , N = 1, yo = y, xp = x + 1, yp = yo + M (for example, M = 12). X (0) and Y (0) are the coordinate values of the vector start point, N is the number of continuous black pixels, yo is the coordinate value of the immediately preceding black pixel, xp and yp are the coordinate values of the pixel to be searched next. Yes, M is a variable that determines the search range in adjacent columns.

次に、傾き角算出手段40は、画素(xp,yp)が黒画素であるかどうかを判断する(ステップS123)。具体的には、ImageB(xp,yp)=0であるかどうかを判断する。ステップS123において、画素(xp,yp)が黒画素であると判断された場合、x方向に移動して次の画素を設定する処理を行う(ステップS124)。具体的には、黒画素と判断された画素(xp,yp)を重複して抽出されることを回避するため、ImageB(xp,yp)=255にセットし、X(N)=xp、Y(N)=yp、N←N+1、xp←xp+1、yo=yp、yp←yo+Mに設定する(ステップS124)。   Next, the inclination angle calculation means 40 determines whether or not the pixel (xp, yp) is a black pixel (step S123). Specifically, it is determined whether ImageB (xp, yp) = 0. If it is determined in step S123 that the pixel (xp, yp) is a black pixel, processing for moving to the x direction and setting the next pixel is performed (step S124). Specifically, in order to avoid redundant extraction of pixels (xp, yp) determined to be black pixels, ImageB (xp, yp) = 255 is set, and X (N) = xp, Y (N) = yp, N ← N + 1, xp ← xp + 1, yo = yp, yp ← yo + M are set (step S124).

続いて、傾き角算出手段40は、1だけインクリメントしたxpと、水平方向の終端を示すXs−1と比較する(ステップS125)。xp≦Xs−1の場合は、水平方向の終端を超えていないことになるので、ステップS123に戻って、移動した位置の画素(xp,yp)が黒画素であるかどうかを判断する。xp>Xs−1の場合は、水平方向の終端を超えており、これ以上探索可能な画素が存在しないため、ステップS128に進む。ステップS123、S124、S125のループにおいては、黒画素が見つかり続けた場合、xpを1ずつインクリメントしながら、文書画像の水平方向終端まで画素を探索する。   Subsequently, the tilt angle calculation means 40 compares xp incremented by 1 with Xs−1 indicating the end in the horizontal direction (step S125). If xp ≦ Xs−1, the end in the horizontal direction is not exceeded, so the process returns to step S123 to determine whether the pixel (xp, yp) at the moved position is a black pixel. In the case of xp> Xs-1, since the end in the horizontal direction is exceeded and there are no more searchable pixels, the process proceeds to step S128. In the loop of steps S123, S124, and S125, when black pixels continue to be found, the pixels are searched to the end of the document image in the horizontal direction while incrementing xp by one.

ステップS123において、画素(xp,yp)が黒画素でないと判断された場合、エッジ抽出手段30は、x方向には移動せず、y方向にのみ移動させて次の画素を設定する処理を行う(ステップS126)。具体的には、変数ypを1だけデクリメントする(yp←yp−1)。   If it is determined in step S123 that the pixel (xp, yp) is not a black pixel, the edge extraction unit 30 performs a process of setting the next pixel by moving only in the y direction without moving in the x direction. (Step S126). Specifically, the variable yp is decremented by 1 (yp ← yp−1).

続いて、エッジ抽出手段30は、1だけデクリメントしたypと、垂直方向の探索範囲の終端を示すyo−Mと比較する(ステップS127)。ステップS127において、yp≧yo−Mの場合は、垂直方向の終端を超えていないことになるので、ステップS123に戻って、移動した位置の画素(xp,yp)が黒画素であるかどうかを判断する。ステップS127において、yp<yo−Mの場合は、ステップS128に進む。ステップS123、S126、S127のループにおいては、ある特定のxpにおいて、最大2M+1個の画素を探索する。このループにおいて、黒画素が見つかれば、ステップS124に進み、黒画素が見つからなければ、水平方向に連続する黒画素が途絶えたと判断し、ステップS128に進むことになる。   Subsequently, the edge extraction means 30 compares yp decremented by 1 with yo-M indicating the end of the search range in the vertical direction (step S127). In step S127, if yp ≧ yo-M, the vertical end is not exceeded, so the process returns to step S123 to determine whether the pixel (xp, yp) at the moved position is a black pixel. to decide. In step S127, if yp <yo-M, the process proceeds to step S128. In the loop of steps S123, S126, and S127, a maximum of 2M + 1 pixels are searched in a specific xp. In this loop, if a black pixel is found, the process proceeds to step S124. If no black pixel is found, it is determined that the black pixels continuous in the horizontal direction have been interrupted, and the process proceeds to step S128.

ステップS125においてxp>Xs−1の場合、または、ステップS127においてyp<yo−Mの場合は、エッジ抽出手段30は、連続黒画素数Nとベクトル長しきい値Lとの比較を行う(ステップS128)。比較の結果、N≧Lである場合は、ベクトルありと判断し、図8のステップS103に進み、抽出ベクトルの傾き角angを算出する。一方、比較の結果、N<Lである場合は、ベクトルなしと判断し、図8のステップS104に進み、ベクトル抽出の探索始点を変更する。   If xp> Xs-1 in step S125, or if yp <yo-M in step S127, the edge extraction means 30 compares the number of consecutive black pixels N with the vector length threshold L (step S128). If N ≧ L as a result of the comparison, it is determined that there is a vector, the process proceeds to step S103 in FIG. 8, and the inclination angle ang of the extracted vector is calculated. On the other hand, if N <L as a result of the comparison, it is determined that there is no vector, the process proceeds to step S104 in FIG. 8, and the search start point for vector extraction is changed.

ステップS102、S110の始点(x,y)からのベクトル抽出処理の具体例を図11に示す。図11においては、説明の便宜上、M=2の場合を示している。また、図11においては、y方向の画素は、連続して示してあるが、x方向については、説明の便宜上、離して示してある。図11に示すように、探索画素(x,y)が黒画素であった場合、(x,y)をベクトル抽出の始点とし、(X(0),Y(0))で表す(ステップS122)。そして、水平方向に移動し(X(1))、最大2M+1(図11の例では5)画素を探索し、見つかった黒画素を(X(1),Y(1))で表す(ステップS124)。X(1)において黒画素が見つかった場合、さらに水平方向に移動し(X(2))、最大2M+1画素を探索し、見つかった黒画素を(X(2),Y(2))で表す(ステップS124)。このようにして、連続する黒画素を抽出していく。   A specific example of vector extraction processing from the start point (x, y) in steps S102 and S110 is shown in FIG. FIG. 11 shows a case where M = 2 for convenience of explanation. In FIG. 11, the pixels in the y direction are shown continuously, but the x direction is shown apart for convenience of explanation. As shown in FIG. 11, when the search pixel (x, y) is a black pixel, (x, y) is used as the starting point of vector extraction and is represented by (X (0), Y (0)) (step S122). ). Then, it moves in the horizontal direction (X (1)), searches a maximum of 2M + 1 (5 in the example of FIG. 11) pixels, and represents the found black pixel as (X (1), Y (1)) (step S124). ). If a black pixel is found in X (1), it moves further in the horizontal direction (X (2)), searches for a maximum of 2M + 1 pixels, and represents the found black pixel as (X (2), Y (2)). (Step S124). In this way, continuous black pixels are extracted.

次に、図8のステップS103、S111における抽出ベクトルの傾き角ang算出処理の詳細について説明する。図12は、横組に対応した抽出ベクトルを構成する頂点(黒画素)を示す図である。上述のように、ステップS102において、ベクトル抽出処理を実行することにより、抽出ベクトルは、N個の頂点{X(n),Y(n)}からなる。図12には、両端付近の4個の頂点を示している。   Next, the details of the extraction vector inclination angle ang calculation processing in steps S103 and S111 of FIG. 8 will be described. FIG. 12 is a diagram showing vertices (black pixels) constituting the extraction vector corresponding to the horizontal composition. As described above, by executing the vector extraction process in step S102, the extraction vector is composed of N vertices {X (n), Y (n)}. FIG. 12 shows four vertices near both ends.

ステップS103において、傾き角算出手段40は、以下の〔数式2〕に従った処理を実行し、N個の頂点{X(n),Y(n)}の重心(Xg,Yg)を算出する。   In step S103, the inclination angle calculation means 40 executes processing according to the following [Equation 2] to calculate the centroids (Xg, Yg) of N vertices {X (n), Y (n)}. .

〔数式2〕
Xg={ΣnX(n)}/N
Yg={ΣnY(n)}/N
[Formula 2]
Xg = {Σ n X (n)} / N
Yg = {Σ n Y (n)} / N

重心(Xg,Yg)を算出したら、傾き角算出手段40は、N個の頂点{X(n),Y(n)}の重心(Xg,Yg)からの水平方向平均距離dx、垂直方向平均距離dyを算出する。具体的には、初期値dx=dy=0とし、n=0,・・・,N−1に対して、以下の〔数式3〕に従った処理を実行する。   After calculating the center of gravity (Xg, Yg), the inclination angle calculating means 40 calculates the horizontal average distance dx from the center of gravity (Xg, Yg) of the N vertices {X (n), Y (n)}, the average in the vertical direction. The distance dy is calculated. Specifically, the initial value dx = dy = 0 is set, and n = 0,..., N−1 is executed according to the following [Equation 3].

〔数式3〕
X(n)≧Xgの場合、dx←dx+X(n)−Xg,dy←dy+Y(n)−Yg
X(n)<Xgの場合、dx←dx+Xg−X(n),dy←dy+Yg−Y(n)
[Formula 3]
When X (n) ≧ Xg, dx ← dx + X (n) −Xg, dy ← dy + Y (n) −Yg
When X (n) <Xg, dx ← dx + Xg−X (n), dy ← dy + Yg−Y (n)

水平方向平均距離dx、垂直方向平均距離dyを算出したら、傾き角算出手段40は、以下の〔数式4〕に従った処理を実行し、抽出ベクトルの傾き角angを算出する。   After calculating the horizontal direction average distance dx and the vertical direction average distance dy, the inclination angle calculation means 40 executes processing according to the following [Equation 4] to calculate the inclination angle ang of the extracted vector.

〔数式4〕
ang=tan-1(dy/dx)
[Formula 4]
ang = tan −1 (dy / dx)

<2.5.2.ベクトル抽出とベクトルの角度算出処理(縦組)>
次に、ステップS40におけるエッジ抽出手段30、傾き角算出手段40によるベクトル抽出と長線ベクトルの角度算出処理について、縦組の文書画像に好適な処理を説明する。図13は、エッジ抽出手段30、傾き角算出手段40による、縦組に好適なベクトル抽出と傾き角算出処理を示すフローチャートである。エッジ抽出手段30は、まず、第1探索モードの初期設定を行う(ステップS201)。具体的には、初期値として角度合計A=0、平均角度A1=0、抽出ベクトル数v=0に設定する。また、探索開始画素(x,y)=(Xs−1,0)に設定する。次に、エッジ抽出手段30は、対象画素(x,y)を始点とするベクトルを抽出する(ステップS202)。ステップS202におけるベクトル抽出処理については、後述する。
<2.5.2. Vector extraction and vector angle calculation processing (vertical composition)>
Next, processing suitable for vertical document images will be described with respect to vector extraction and long line vector angle calculation processing by the edge extraction means 30 and the inclination angle calculation means 40 in step S40. FIG. 13 is a flowchart showing vector extraction and inclination angle calculation processing suitable for vertical composition by the edge extraction means 30 and the inclination angle calculation means 40. The edge extraction unit 30 first performs initial setting of the first search mode (step S201). Specifically, the initial values are set to total angle A = 0, average angle A1 = 0, and number of extraction vectors v = 0. Further, the search start pixel (x, y) = (Xs−1, 0) is set. Next, the edge extraction means 30 extracts a vector starting from the target pixel (x, y) (step S202). The vector extraction process in step S202 will be described later.

ステップS202において、ベクトルを抽出することができた場合には、傾き角算出手段40は、抽出したベクトルの傾き角を算出する(ステップS103)。ステップS203における傾き角算出処理については、後述する。傾き角angが算出されたら、角度合計Aに傾き角angを加算する(A←A+ang)。また、抽出ベクトル数vを1だけインクリメントする(v←v+1)。   If a vector can be extracted in step S202, the inclination angle calculation means 40 calculates the inclination angle of the extracted vector (step S103). The tilt angle calculation process in step S203 will be described later. When the inclination angle ang is calculated, the inclination angle ang is added to the total angle A (A ← A + ang). Also, the number of extracted vectors v is incremented by 1 (v ← v + 1).

続いて、垂直方向の画素を特定する変数yを1だけインクリメントした(ステップS204)後、垂直方向の終端を示すYs−1と比較する(ステップS105)。y≦Ys−1の場合は、垂直方向の終端を超えていないことになるので、ステップS202に戻って、移動した位置の画素(x,y)を始点とし、ステップS202のベクトル抽出処理を実行する。   Subsequently, the variable y for specifying the pixel in the vertical direction is incremented by 1 (step S204), and then compared with Ys-1 indicating the end in the vertical direction (step S105). If y ≦ Ys−1, the vertical end is not exceeded, so the process returns to step S202, and the vector (x, y) at the moved position is used as the starting point, and the vector extraction process in step S202 is executed. To do.

ステップS205において、y>Ys−1の場合は、垂直方向の終端を超えてしまうため、垂直方向の画素を特定する変数yを0とし、水平方向の画素を特定する変数xを1だけデクリメントした(ステップS206)後、水平方向の終端を示す“0”とxの値を比較する(ステップS207)。x≧0の場合は、水平方向の終端を超えていないことになるので、ステップS202に戻って、移動した位置の画素(x,y)を始点とし、ステップS202のベクトル抽出処理を実行する。このようにして、ステップS202〜ステップS207の処理を繰り返し、x=Xs−1側からx=0側に向かって全画素を探索することにより、角度合計Aおよび抽出ベクトル数vが得られる。   In step S205, when y> Ys-1, the vertical end is exceeded. Therefore, the variable y specifying the vertical pixel is set to 0, and the variable x specifying the horizontal pixel is decremented by 1. After (step S206), “0” indicating the end in the horizontal direction is compared with the value of x (step S207). If x ≧ 0, the horizontal end is not exceeded, so the process returns to step S202, and the vector (x, y) at the moved position is used as the starting point, and the vector extraction process in step S202 is executed. In this way, the angle sum A and the number of extraction vectors v are obtained by repeating the processing of step S202 to step S207 and searching all pixels from the x = Xs-1 side toward the x = 0 side.

全画素についての探索が終わったら、傾き角算出手段40は、角度合計Aを抽出ベクトル数vで除算する処理を実行し、抽出ベクトルの平均角度A1(=A/v)を算出する(ステップS208)。ステップS201〜ステップS208の処理で第1探索モードが終了する。   When the search for all the pixels is completed, the inclination angle calculating means 40 executes a process of dividing the angle sum A by the number of extracted vectors v, and calculates the average angle A1 (= A / v) of the extracted vectors (step S208). ). The first search mode is terminated by the processing from step S201 to step S208.

次に、エッジ抽出手段30は、第2探索モードの初期設定を行う(ステップS209)。具体的には、初期値として角度合計A=0、平均角度A2=0、抽出ベクトル数v=0に設定する。また、探索開始画素(x,y)=(0,0)に設定する。次に、エッジ抽出手段30は、対象画素(x,y)を始点とするベクトルを抽出する(ステップS210)。ステップS210におけるベクトル抽出処理については、後述する。   Next, the edge extraction unit 30 performs initial setting of the second search mode (step S209). Specifically, the initial values are set as total angle A = 0, average angle A2 = 0, and number of extraction vectors v = 0. Further, the search start pixel (x, y) = (0, 0) is set. Next, the edge extraction means 30 extracts a vector starting from the target pixel (x, y) (step S210). The vector extraction process in step S210 will be described later.

ステップS210において、ベクトルを抽出することができた場合には、傾き角算出手段40は、抽出したベクトルの傾き角を算出する(ステップS211)。ステップS211における傾き角算出処理については、後述する。傾き角angが算出されたら、角度合計Aに傾き角angを加算する(A←A+ang)。また、抽出ベクトル数vを1だけインクリメントする(v←v+1)。   If the vector can be extracted in step S210, the inclination angle calculation means 40 calculates the inclination angle of the extracted vector (step S211). The tilt angle calculation process in step S211 will be described later. When the inclination angle ang is calculated, the inclination angle ang is added to the total angle A (A ← A + ang). Also, the number of extracted vectors v is incremented by 1 (v ← v + 1).

続いて、垂直方向の画素を特定する変数yを1だけインクリメントした(ステップS212)後、垂直方向の終端を示すYs−1と比較する(ステップS213)。y≦Ys−1の場合は、垂直方向の終端を超えていないことになるので、ステップS210に戻って、移動した位置の画素(x,y)を始点とし、ステップS210のベクトル抽出処理を実行する。   Subsequently, the variable y for specifying the pixel in the vertical direction is incremented by 1 (step S212), and then compared with Ys-1 indicating the end in the vertical direction (step S213). In the case of y ≦ Ys−1, the vertical end is not exceeded, so the process returns to step S210 and the pixel (x, y) at the moved position is used as the starting point, and the vector extraction process in step S210 is executed. To do.

ステップS213において、y>Ys−1の場合は、垂直方向の終端を超えてしまうため、垂直方向の画素を特定する変数yを0とし、水平方向の画素を特定する変数xを1だけインクリメントした(ステップS214)後、水平方向の終端を示す“Xs−1”とxの値を比較する(ステップS215)。x≦Xs−1の場合は、水平方向の終端を超えていないことになるので、ステップS210に戻って、移動した位置の画素(x,y)を始点とし、ステップS210のベクトル抽出処理を実行する。このようにして、ステップS210〜ステップS215の処理を繰り返し、x=0側からx=Xs−1側に向かって全画素を探索することにより、角度合計Aおよび抽出ベクトル数vが得られる。   In step S213, if y> Ys-1, the vertical end is exceeded. Therefore, the variable y specifying the vertical pixel is set to 0, and the variable x specifying the horizontal pixel is incremented by 1. After (Step S214), "Xs-1" indicating the end in the horizontal direction is compared with the value of x (Step S215). If x ≦ Xs−1, it means that the end in the horizontal direction is not exceeded, so the process returns to step S210 and the pixel (x, y) at the moved position is used as the starting point, and the vector extraction process in step S210 is executed. To do. In this way, by repeating the processing of step S210 to step S215 and searching all pixels from the x = 0 side toward the x = Xs−1 side, the angle sum A and the number of extraction vectors v can be obtained.

全画素についての探索が終わったら、傾き角算出手段40は、角度合計Aを抽出ベクトル数vで除算する処理を実行し、抽出ベクトルの平均角度A2(=A/v)を算出する(ステップS216)。ステップS209〜ステップS216の処理で第2探索モードが終了する。   When the search for all the pixels is completed, the inclination angle calculating means 40 executes a process of dividing the angle sum A by the number of extracted vectors v, and calculates the average angle A2 (= A / v) of the extracted vectors (step S216). ). The second search mode is terminated by the processing from step S209 to step S216.

ステップS201〜ステップS208の第1探索モード、ステップS209〜ステップS216の第2探索モードが終了したら、傾き角算出手段40は、第1探索モードによる平均角度A1の絶対値と、第2探索モードによる平均角度A2の絶対値を比較する。そして、絶対値が大きい方の平均角度の値を平均傾き角Angとして出力する(ステップS217)。平均角度A1の絶対値と、第2探索モードによる平均角度A2の絶対値が等しい場合、本実施形態では、平均傾き角Ang=平均角度A2としているが、平均傾き角Ang=平均角度A1とするような設定であっても良い。   When the first search mode of step S201 to step S208 and the second search mode of step S209 to step S216 are completed, the tilt angle calculation means 40 uses the absolute value of the average angle A1 in the first search mode and the second search mode. The absolute values of the average angle A2 are compared. Then, the average angle value having the larger absolute value is output as the average inclination angle Ang (step S217). When the absolute value of the average angle A1 is equal to the absolute value of the average angle A2 in the second search mode, in this embodiment, the average inclination angle Ang = average angle A2, but the average inclination angle Ang = average angle A1. Such a setting may be used.

ベクトル抽出処理において、互いに探索方向が逆である第1探索モードと第2探索モードを実行するようにしたのは、横組みの場合と同様、文字列の傾きに応じて、探索方向を変えた方が良いためである。図14に、縦組の場合におけるベクトル抽出における2方向の探索の様子を示す。図14(a)(b)は文字列が右上に傾いた画像、図14(c)(d)は文字列が左上に傾いた画像を示している。文字列が右上に傾いた画像の場合、図14(a)に示すように、右から探索した場合には、エッジを検出し易いが、図14(b)に示すように、左から探索した場合には、エッジを検出し難い。また、文字列が左上に傾いた画像の場合、図14(c)に示すように、右から探索した場合には、エッジを検出し難いが、図14(d)に示すように、左から探索した場合には、エッジを検出し易い。このため、2つの方向から探索を行うようにしているのである。   In the vector extraction process, the first search mode and the second search mode in which the search directions are opposite to each other are executed, as in the case of horizontal composition, the search direction is changed according to the inclination of the character string. This is because it is better. FIG. 14 shows a state of search in two directions in vector extraction in the case of vertical composition. FIGS. 14A and 14B show images in which the character string is tilted to the upper right, and FIGS. 14C and 14D show images in which the character string is tilted to the upper left. In the case of an image in which the character string is tilted to the upper right, as shown in FIG. 14A, when searching from the right, it is easy to detect an edge, but as shown in FIG. 14B, the search is performed from the left. In some cases, it is difficult to detect an edge. Further, in the case of an image in which the character string is tilted to the upper left, as shown in FIG. 14C, it is difficult to detect an edge when searching from the right, but from the left as shown in FIG. 14D. When searching, it is easy to detect an edge. For this reason, the search is performed from two directions.

次に、図13のステップS202におけるベクトル抽出処理の詳細について説明する。図15は、ステップS202におけるベクトル抽出処理の詳細を示すフローチャートである。エッジ抽出手段30は、まず、対象画素(x,y)が黒画素であるかどうかを判断する(ステップS221)。具体的には、ImageB(x,y)=0であるかどうかを判断する。   Next, details of the vector extraction process in step S202 of FIG. 13 will be described. FIG. 15 is a flowchart showing details of the vector extraction processing in step S202. The edge extraction unit 30 first determines whether or not the target pixel (x, y) is a black pixel (step S221). Specifically, it is determined whether or not ImageB (x, y) = 0.

ステップS221において、対象画素(x,y)が黒画素でないと判断された場合、その対象画素(x,y)を始点とするベクトルは無いと判断して、図13のステップS204に進み、y座標を変更して、探索対象を次の画素に変更する。   If it is determined in step S221 that the target pixel (x, y) is not a black pixel, it is determined that there is no vector starting from the target pixel (x, y), and the process proceeds to step S204 in FIG. The search target is changed to the next pixel by changing the coordinates.

ステップS221において、対象画素(x,y)が黒画素であると判断された場合、その対象画素(x,y)をベクトル始点と設定し、初期設定を行う(ステップS222)。具体的には、対象画素(x,y)を重複して抽出されることを回避するため、ImageB(x,y)=255にセットし、X(0)=x、Y(0)=y、N=1、xo=x、yp=y+1、xp=xo+M(例えば、M=12)に設定する。X(0)、Y(0)はベクトル始点の座標値であり、Nは連続黒画素数であり、xoは直前の黒画素の座標値、xp、ypは次に探索する画素の座標値であり、Mは隣接する列における探索範囲を決定する変数である。   If it is determined in step S221 that the target pixel (x, y) is a black pixel, the target pixel (x, y) is set as a vector start point, and initial setting is performed (step S222). Specifically, in order to avoid redundant extraction of the target pixel (x, y), set ImageB (x, y) = 255, and X (0) = x, Y (0) = y , N = 1, xo = x, yp = y + 1, xp = xo + M (for example, M = 12). X (0) and Y (0) are the coordinate values of the vector start point, N is the number of continuous black pixels, xo is the coordinate value of the immediately preceding black pixel, xp and yp are the coordinate values of the pixel to be searched next. Yes, M is a variable that determines the search range in adjacent columns.

次に、エッジ抽出手段30は、画素(xp,yp)が黒画素であるかどうかを判断する(ステップS223)。具体的には、ImageB(xp,yp)=0であるかどうかを判断する。ステップS223において、画素(xp,yp)が黒画素であると判断された場合、y方向に移動して次の画素を設定する処理を行う(ステップS224)。具体的には、黒画素と判断された画素(xp,yp)を重複して抽出されることを回避するため、ImageB(xp,yp)=255にセットし、X(N)=xp、Y(N)=yp、N←N+1、yp←yp+1、xo=xp、xp←xo+Mに設定する(ステップS224)。   Next, the edge extraction unit 30 determines whether or not the pixel (xp, yp) is a black pixel (step S223). Specifically, it is determined whether ImageB (xp, yp) = 0. If it is determined in step S223 that the pixel (xp, yp) is a black pixel, processing for moving to the y direction and setting the next pixel is performed (step S224). Specifically, in order to avoid redundant extraction of pixels (xp, yp) determined to be black pixels, ImageB (xp, yp) = 255 is set, and X (N) = xp, Y (N) = yp, N ← N + 1, yp ← yp + 1, xo = xp, xp ← xo + M are set (step S224).

続いて、エッジ抽出手段30は、1だけインクリメントしたypと、垂直方向の終端を示すYs−1と比較する(ステップS225)。yp≦Ys−1の場合は、垂直方向の終端を超えていないことになるので、ステップS223に戻って、移動した位置の画素(xp,yp)が黒画素であるかどうかを判断する。yp>Ys−1の場合は、垂直方向の終端を超えており、これ以上探索可能な画素が存在しないため、ステップS228に進む。ステップS223、S224、S225のループにおいては、黒画素が見つかり続けた場合、ypを1ずつインクリメントしながら、文書画像の垂直方向終端まで画素を探索する。   Subsequently, the edge extraction unit 30 compares yp incremented by 1 with Ys−1 indicating the end in the vertical direction (step S225). If yp ≦ Ys−1, it means that the end of the vertical direction is not exceeded, so the process returns to step S223 to determine whether or not the pixel (xp, yp) at the moved position is a black pixel. In the case of yp> Ys−1, since the end of the vertical direction is exceeded and there are no more searchable pixels, the process proceeds to step S228. In the loop of steps S223, S224, and S225, when black pixels continue to be found, the pixels are searched until the end of the document image in the vertical direction while incrementing yp by one.

ステップS223において、画素(xp,yp)が黒画素でないと判断された場合、エッジ抽出手段30は、y方向には移動せず、x方向にのみ移動させて次の画素を設定する処理を行う(ステップS226)。具体的には、変数xpを1だけデクリメントする(xp←xp−1)。   If it is determined in step S223 that the pixel (xp, yp) is not a black pixel, the edge extraction unit 30 performs a process of setting the next pixel by moving only in the x direction without moving in the y direction. (Step S226). Specifically, the variable xp is decremented by 1 (xp ← xp−1).

続いて、エッジ抽出手段30は、1だけデクリメントしたxpと、水平方向の探索範囲の終端を示すxo−Mと比較する(ステップS227)。ステップS227において、xp≧xo−Mの場合は、水平方向の終端を超えていないことになるので、ステップS223に戻って、移動した位置の画素(xp,yp)が黒画素であるかどうかを判断する。ステップS227において、xp<xo−Mの場合は、ステップS228に進む。ステップS223、S226、S227のループにおいては、ある特定のypにおいて、最大2M+1個の画素を探索する。このループにおいて、黒画素が見つかれば、ステップS224に進み、黒画素が見つからなければ、水平方向に連続する黒画素が途絶えたと判断し、ステップS228に進むことになる。   Subsequently, the edge extraction unit 30 compares xp decremented by 1 with xo-M indicating the end of the horizontal search range (step S227). In step S227, if xp ≧ xo−M, the horizontal end is not exceeded, so the process returns to step S223 to determine whether the pixel (xp, yp) at the moved position is a black pixel. to decide. In step S227, if xp <xo-M, the process proceeds to step S228. In the loop of steps S223, S226, and S227, a maximum of 2M + 1 pixels are searched in a specific yp. If a black pixel is found in this loop, the process proceeds to step S224. If no black pixel is found, it is determined that the black pixels continuous in the horizontal direction have been interrupted, and the process proceeds to step S228.

ステップS225においてyp>Ys−1の場合、または、ステップS227においてxp<xo−Mの場合は、エッジ抽出手段30は、連続黒画素数Nとベクトル長しきい値Lとの比較を行う(ステップS228)。比較の結果、N≧Lである場合は、ベクトルありと判断し、図13のステップS203に進み、抽出ベクトルの傾き角angを算出する。一方、比較の結果、N<Lである場合は、ベクトルなしと判断し、図13のステップS204に進み、ベクトル抽出の探索始点を変更する。   If yp> Ys-1 in step S225, or if xp <xo-M in step S227, the edge extracting means 30 compares the number of consecutive black pixels N with the vector length threshold L (step S228). If N ≧ L as a result of the comparison, it is determined that there is a vector, the process proceeds to step S203 in FIG. 13, and the inclination angle ang of the extracted vector is calculated. On the other hand, if N <L as a result of the comparison, it is determined that there is no vector, the process proceeds to step S204 in FIG. 13, and the search start point for vector extraction is changed.

ステップS202、S210の始点(x,y)からのベクトル抽出処理の具体例を図16に示す。図16においては、説明の便宜上、M=2の場合を示している。また、図16においては、x方向の画素は、連続して示してあるが、y方向については、説明の便宜上、離して示してある。図16に示すように、探索画素(x,y)が黒画素であった場合、(x,y)をベクトル抽出の始点とし、(X(0),Y(0))で表す(ステップS222)。そして、垂直方向に移動し(Y(1))、最大2M+1(図16の例では5)画素を探索し、見つかった黒画素を(X(1),Y(1))で表す(ステップS224)。Y(1)において黒画素が見つかった場合、さらに水平方向に移動し(Y(2))、最大2M+1画素を探索し、見つかった黒画素を(X(2),Y(2))で表す(ステップS224)。このようにして、連続する黒画素を抽出していく。   A specific example of vector extraction processing from the start point (x, y) in steps S202 and S210 is shown in FIG. FIG. 16 shows a case where M = 2 for convenience of explanation. In FIG. 16, the pixels in the x direction are shown continuously, but the y direction is shown apart for convenience of explanation. As shown in FIG. 16, when the search pixel (x, y) is a black pixel, (x, y) is used as the starting point of vector extraction and is represented by (X (0), Y (0)) (step S222). ). Then, it moves in the vertical direction (Y (1)), searches a maximum of 2M + 1 (5 in the example of FIG. 16) pixels, and represents the found black pixel as (X (1), Y (1)) (step S224). ). If a black pixel is found in Y (1), it moves further in the horizontal direction (Y (2)), searches for a maximum of 2M + 1 pixels, and represents the found black pixel as (X (2), Y (2)). (Step S224). In this way, continuous black pixels are extracted.

次に、図13のステップS203、S211における抽出ベクトルの傾き角ang算出処理の詳細について説明する。図17は、縦組に対応した抽出ベクトルを構成する頂点(黒画素)を示す図である。上述のように、ステップS202において、ベクトル抽出処理を実行することにより、抽出ベクトルは、N個の頂点{X(n),Y(n)}からなる。図17には、両端付近の4個の頂点を示している。   Next, details of the extraction vector inclination angle ang calculation processing in steps S203 and S211 of FIG. 13 will be described. FIG. 17 is a diagram showing vertices (black pixels) that constitute an extraction vector corresponding to a vertical composition. As described above, by executing the vector extraction process in step S202, the extraction vector is composed of N vertices {X (n), Y (n)}. FIG. 17 shows four vertices near both ends.

ステップS203において、傾き角算出手段40は、以下の〔数式5〕に従った処理を実行し、N個の頂点{X(n),Y(n)}の重心(Xg,Yg)を算出する。なお、〔数式5〕は上記〔数式2〕と同一のものである。   In step S203, the inclination angle calculation means 40 executes processing according to the following [Equation 5] to calculate the centroids (Xg, Yg) of N vertices {X (n), Y (n)}. . [Formula 5] is the same as [Formula 2].

〔数式5〕
Xg={ΣnX(n)}/N
Yg={ΣnY(n)}/N
[Formula 5]
Xg = {Σ n X (n)} / N
Yg = {Σ n Y (n)} / N

重心(Xg,Yg)を算出したら、傾き角算出手段40は、N個の頂点{X(n),Y(n)}の重心(Xg,Yg)からの水平方向平均距離dx、垂直方向平均距離dyを算出する。具体的には、初期値dx=dy=0とし、n=0,・・・,N−1に対して、以下の〔数式6〕に従った処理を実行する。   After calculating the center of gravity (Xg, Yg), the inclination angle calculating means 40 calculates the horizontal average distance dx from the center of gravity (Xg, Yg) of the N vertices {X (n), Y (n)}, the average in the vertical direction. The distance dy is calculated. Specifically, the initial value dx = dy = 0 is set, and the process according to the following [Formula 6] is executed for n = 0,..., N−1.

〔数式6〕
Y(n)≧Ygの場合、dx←dx+X(n)−Xg,dy←dy+Y(n)−Yg
Y(n)<Ygの場合、dx←dx+Xg−X(n),dy←dy+Yg−Y(n)
[Formula 6]
When Y (n) ≧ Yg, dx ← dx + X (n) −Xg, dy ← dy + Y (n) −Yg
When Y (n) <Yg, dx ← dx + Xg−X (n), dy ← dy + Yg−Y (n)

水平方向平均距離dx、垂直方向平均距離dyを算出したら、傾き角算出手段40は、以下の〔数式7〕に従った処理を実行し、抽出ベクトルの傾き角angを算出する。   After calculating the horizontal direction average distance dx and the vertical direction average distance dy, the inclination angle calculation means 40 executes processing according to the following [Equation 7] to calculate the inclination angle ang of the extracted vector.

〔数式7〕
ang=tan-1(dx/dy)
[Formula 7]
ang = tan −1 (dx / dy)

<2.6.文書画像の回転処理>
次に、ステップS50における文書回転手段50による文書画像の回転処理について説明する。文書回転手段50は、傾き角算出手段40により算出された平均傾き角Angを用いて、文書画像を回転して補正画像を得る。文書画像は、上述のようにImage(x,y)(0≦x≦Xs−1、0≦y≦Ys−1)で表現されるが、平均傾き角Angで回転処理後の補正画像をImageC(x´,y´)(0≦x´≦Xs−1、0≦y´≦Ys−1)とする。文書画像Image(x,y)も、補正画像ImageC(x´,y´)も、各画素は、0から255の範囲の値をとるものとする。この場合、文書画像Image(x,y)と、補正画像ImageC(x´,y´)の画素の関係は、以下の〔数式8〕のようになる。
<2.6. Rotation processing of document image>
Next, the rotation processing of the document image by the document rotation unit 50 in step S50 will be described. The document rotation unit 50 rotates the document image using the average inclination angle Ang calculated by the inclination angle calculation unit 40 to obtain a corrected image. As described above, the document image is represented by Image (x, y) (0 ≦ x ≦ Xs−1, 0 ≦ y ≦ Ys−1). However, the corrected image after the rotation process with the average inclination angle Ang is defined as ImageC. (X ′, y ′) (0 ≦ x ′ ≦ Xs−1, 0 ≦ y ′ ≦ Ys−1). In both the document image Image (x, y) and the corrected image ImageC (x ′, y ′), each pixel has a value in the range of 0 to 255. In this case, the relationship between the pixels of the document image Image (x, y) and the corrected image ImageC (x ′, y ′) is expressed by the following [Equation 8].

〔数式8〕
x=(x´−Xs/2)・cos(Ang)+(y´−Ys/2)・sin(Ang)+Xs/2
y=−(x´−Xs/2)・sin(Ang)+(y´−Ys/2)・cos(Ang)+Ys/2
[Formula 8]
x = (x′−Xs / 2) · cos (Ang) + (y′−Ys / 2) · sin (Ang) + Xs / 2
y = − (x′−Xs / 2) · sin (Ang) + (y′−Ys / 2) · cos (Ang) + Ys / 2

文書回転手段50は、上記〔数式8〕に示した関係から、x´,y´を求めるための数式を作成し、その数式に従った処理を実行して、文書画像Image(x,y)の各画素(x,y)に対応する補正画像ImageC(x´,y´)の画素(x´,y´)を求め、補正画像ImageC(x´,y´)の画素(x´,y´)に、文書画像Image(x,y)の対応する画素(x,y)の画素値を与える。これにより、補正画像ImageC(x´,y´)が得られる。   The document rotation means 50 creates a mathematical formula for obtaining x ′ and y ′ from the relationship shown in the above [Formula 8], executes a process according to the mathematical formula, and creates a document image Image (x, y). The pixel (x ′, y ′) of the corrected image ImageC (x ′, y ′) corresponding to each pixel (x, y) is obtained, and the pixel (x ′, y ′) of the corrected image ImageC (x ′, y ′) is obtained. The pixel value of the corresponding pixel (x, y) of the document image Image (x, y) is given to '). As a result, a corrected image ImageC (x ′, y ′) is obtained.

横組の場合における文書画像の回転の様子を図18に示す。図18(a)は、文書画像Image(x,y)を示し、図18(b)は、補正画像ImageC(x´,y´)を示している。図18(a)(b)において、斜め、または水平方向の実線は、文字が配置されたラインを示す。また、水平方向の破線は、回転の基準となる水平方向の基準線を示している。図18(a)では、基準線から角度Angだけ文字が右肩下がりに傾いて配置されている。文書回転手段50により角度−Angだけ回転され、図18(b)に示すように、基準線と平行に文字が配置された状態になる。   FIG. 18 shows how the document image is rotated in the horizontal composition. 18A shows the document image Image (x, y), and FIG. 18B shows the corrected image ImageC (x ′, y ′). In FIGS. 18A and 18B, a solid line in an oblique or horizontal direction indicates a line on which characters are arranged. Further, the broken line in the horizontal direction indicates a horizontal reference line serving as a reference for rotation. In FIG. 18A, the characters are arranged so as to be inclined downward from the reference line by an angle Ang. The document is rotated by the angle -Ang by the document rotation means 50, and as shown in FIG. 18B, the characters are arranged in parallel with the reference line.

横組の場合の画像変化の具体例を図19、図20、図21、図22に示す。これらは、それぞれ図4(a)〜(d)に対応している。図19は、読み取った文書画像の具体例を示す図である。図19(a)は、左下に傾き、図19(b)は、右下に傾いている。図20は、二値化処理、水平方向の画素膨張処理後の画像の具体例を示す図である。黒い部分は、文字画素領域が膨張された部分である。図21は、黒い部分は、文字画素領域のエッジ部である文字画素である。図22は、文書画像回転処理後の画像の具体例を示す図である。図22(a)は、図19(a)の文書画像が−1.953度回転された補正画像であり、図22(b)は、図19(a)の文書画像が+1.378度回転された補正画像である。いずれも横組の文字列がほぼ水平に補正された状態となることがわかる。   Specific examples of image changes in the case of horizontal composition are shown in FIGS. 19, 20, 21, and 22. These correspond to FIGS. 4A to 4D, respectively. FIG. 19 is a diagram illustrating a specific example of the read document image. FIG. 19A is tilted to the lower left, and FIG. 19B is tilted to the lower right. FIG. 20 is a diagram illustrating a specific example of an image after binarization processing and horizontal pixel expansion processing. The black portion is a portion in which the character pixel region is expanded. In FIG. 21, a black part is a character pixel which is an edge part of a character pixel area. FIG. 22 is a diagram illustrating a specific example of an image after the document image rotation processing. 22A is a corrected image obtained by rotating the document image of FIG. 19A by −1.953 degrees, and FIG. 22B is a rotated image of the document image of FIG. 19A by +1.378 degrees. Corrected image. It can be seen that in both cases, the horizontal character string is corrected almost horizontally.

<2.7.電子文書の作成>
次に、ステップS60における電子文書作成手段55による電子文書の作成処理について説明する。電子文書作成手段55が、補正画像から電子文書ファイルを作成する処理を行う。電子文書作成手段55により補正画像は圧縮されて電子文書ファイルに貼付される。
<2.7. Creation of electronic documents>
Next, an electronic document creation process by the electronic document creation means 55 in step S60 will be described. The electronic document creation means 55 performs processing for creating an electronic document file from the corrected image. The corrected image is compressed by the electronic document creation means 55 and attached to the electronic document file.

電子文書ファイルの作成処理については、公知の種々の形式を用いることができるが、本実施形態では、PDF形式を用いている。具体的には、補正画像に対して文字認識を行って、文字コードを取得し、取得した文字コードを、非描画属性に設定して透明文字データを作成し、指定された割り付け位置を維持して補正画像に付加する。この処理は、Acrobat(登録商標)等の公知のPDF変換アプリケーションと同様のアルゴリズムを用いて行われる。非描画属性に設定して透明文字データを作成することは、Acrobat(登録商標)等の公知のPDF変換アプリケーションにより行うことができる。透明文字データを付加しておくことにより、文字コードを利用した全文検索が可能となる。   For the electronic document file creation process, various known formats can be used. In this embodiment, the PDF format is used. Specifically, character recognition is performed on the corrected image, the character code is acquired, the acquired character code is set as a non-drawing attribute, transparent character data is created, and the specified allocation position is maintained. To add to the corrected image. This process is performed using an algorithm similar to a known PDF conversion application such as Acrobat (registered trademark). The transparent character data can be created by setting the non-drawing attribute to a known PDF conversion application such as Acrobat (registered trademark). By adding transparent character data, a full-text search using a character code can be performed.

補正画像から電子文書を作成する際、本実施形態では、圧縮伸張後のモスキートノイズの発生を低減するために、画像の圧縮前に色数削減処理を実行している。図23は、色数削減処理を説明するための図である。図23(a)は、補正画像を構成する画素のビット配列を示しており、図23(b)は、色数削減画像を構成する画素のビット配列を示している。図23(a)に示すように、本実施形態では、補正画像がR、G、B各色が8ビットで表現されているので、各色は256階調の深さを持っている。色数削減処理において、電子文書作成手段55は、Rを3ビット8階調、Gを3ビット8階調、Bを2ビット4階調に低下させる。この結果、図23(b)に示すように、全体として8ビット256色の色数削減画像が得られる。図23の例では、R、G、Bの階調がそれぞれ1/32、1/32、1/64に削減されることになる。画像は画素あたり24ビットから8ビットで符号化し、新たにカラールックアップテーブル(画素インデックス値からRGB値への変換テーブル)を定義して添付する。図23に示した手法以外にも、公知の色数削減手法を用いることができる。電子文書作成手段55は、複数の色数削減手法を設定可能に構成されており、電子文書作成手段55として機能するキー入力I/F4を介した指示に従って、指示された色数削減手法を実行するように、電子文書作成手段55を設定する。色数削減画像に対する圧縮手法としては、公知の様々な手法を用いることができる。例えば、非可逆圧縮ではJPEG等、可逆圧縮ではZIP等を用いることができる。   In creating an electronic document from a corrected image, in this embodiment, in order to reduce the occurrence of mosquito noise after compression / expansion, color number reduction processing is performed before image compression. FIG. 23 is a diagram for explaining the color number reduction processing. FIG. 23A shows the bit arrangement of the pixels constituting the corrected image, and FIG. 23B shows the bit arrangement of the pixels constituting the color number reduced image. As shown in FIG. 23A, in the present embodiment, the R, G, and B colors are represented by 8 bits in the corrected image, so each color has a depth of 256 gradations. In the color number reduction process, the electronic document creation means 55 reduces R to 3 bits and 8 gradations, G to 3 bits and 8 gradations, and B to 2 bits and 4 gradations. As a result, as shown in FIG. 23B, an 8-bit 256-color reduced image is obtained as a whole. In the example of FIG. 23, the R, G, and B gradations are reduced to 1/32, 1/32, and 1/64, respectively. The image is encoded from 24 bits to 8 bits per pixel, and a new color lookup table (pixel index value to RGB value conversion table) is defined and attached. In addition to the method shown in FIG. 23, a known color number reduction method can be used. The electronic document creation unit 55 is configured to be able to set a plurality of color number reduction methods, and executes the instructed color number reduction method in accordance with an instruction via the key input I / F 4 functioning as the electronic document creation unit 55. Thus, the electronic document creation means 55 is set. Various known methods can be used as the compression method for the color-reduced image. For example, JPEG or the like can be used for lossy compression, and ZIP or the like can be used for lossless compression.

画像を圧縮伸張した際に、モスキートノイズが目立つのは、ソース画像が実質的に二値に近くコントラストが高いモノクロ画像で、生成されるモスキートノイズはハーフトーンになる。例えば、ソース画像の背景が白色で文字が黒色で表現された文字画像である場合、生成されるモスキートノイズは白または黒に近いグレー色になる。しかし、256階調から数段階の階調に色数制限を施すと、白に近いグレー色は白に、黒に近いグレー色は黒に近似されてしまうため、ハーフトーンのモスキートノイズは表現されなくなる。一方ソースのモノクロ画像は、データ形式上は256階調をもつが、実用上は4〜8階調程度に低下させても問題ない。2階調に低下させると、文字輪郭部にジャギーが発生するので、アンチエイリアシング効果を維持するために4階調以上は必要である。そこで、本実施形態では、カラー画像の場合は、RGB各256階調から各々4〜8階調に低下させ、色数をフルカラーの約1600万色(256の3乗)から256色程度に減少させている。   When the image is compressed and expanded, the mosquito noise is conspicuous when the source image is a monochrome image that is substantially binary and has high contrast, and the generated mosquito noise is halftone. For example, when the source image is a character image in which the background is white and the characters are expressed in black, the generated mosquito noise is white or a gray color close to black. However, if the number of colors is limited from 256 tones, the gray color close to white is approximated to white, and the gray color close to black is approximated to black, so halftone mosquito noise is expressed. Disappear. On the other hand, the monochrome image of the source has 256 gradations in the data format, but there is no problem even if it is reduced to about 4 to 8 gradations in practice. If the gradation is reduced to two gradations, jaggy is generated in the character outline portion, so that four gradations or more are necessary to maintain the anti-aliasing effect. Therefore, in the present embodiment, in the case of a color image, the RGB is reduced from 256 tones to 4 to 8 each, and the number of colors is reduced from about 16 million colors (256 to the cube of 256) to about 256 colors. I am letting.

<3.変形例等>
以上、本発明の好適な実施形態について説明したが、本発明は上記実施形態に限定されず、種々の変形が可能である。例えば、上記実施形態では、抽出された文字コードから透明文字データを作成して、電子文書ファイルに付加する処理を行ったが、この処理を省略し、透明文字データを付加しないようにしても良い。また、電子文書の作成自体を行わず、傾きを補正した補正画像のみを得るようにしても良い。
<3. Modified example>
The preferred embodiments of the present invention have been described above. However, the present invention is not limited to the above embodiments, and various modifications can be made. For example, in the above embodiment, transparent character data is created from the extracted character code and added to the electronic document file. However, this processing may be omitted and transparent character data may not be added. . In addition, it is possible to obtain only a corrected image in which the inclination is corrected without creating the electronic document itself.

1・・・CPU(Central Processing Unit)
2・・・RAM(Random Access Memory)
3・・・記憶装置
4・・・キー入力I/F
5・・・データ入出力I/F
6・・・表示部
7・・・イメージスキャナ
10・・・二値化手段
20・・・文字画素領域膨張手段
30・・・エッジ抽出手段
40・・・傾き角算出手段
50・・・文書回転手段
55・・・電子文書作成手段
60・・・文書画像記憶手段
70・・・補正画像記憶手段
1 ... CPU (Central Processing Unit)
2 ... RAM (Random Access Memory)
3 ... Storage device 4 ... Key input I / F
5. Data input / output I / F
DESCRIPTION OF SYMBOLS 6 ... Display part 7 ... Image scanner 10 ... Binarization means 20 ... Character pixel area expansion means 30 ... Edge extraction means 40 ... Inclination angle calculation means 50 ... Document rotation Means 55 ... Electronic document creation means 60 ... Document image storage means 70 ... Correction image storage means

Claims (10)

光学的読み取りを行って得られた文書画像に対して、光学的読み取り時の傾きを補正する装置であって、
前記文書画像の各画素の値としきい値を比較して二値化し、二値画像を作成する二値化手段と、
前記二値画像のうち、一方の値をとる画素を文字画素、他方の値をとる画素を背景画素とし、前記二値画像に対して水平方向または垂直方向に文字画素が存在する文字画素領域を膨張させる文字画素領域膨張手段と、
前記水平方向に膨張させた二値画像内の文字画素領域のエッジ部より水平方向の折れ線を複数抽出するか、前記垂直方向に膨張させた二値画像内の文字画素領域のエッジ部より垂直方向の折れ線を複数抽出するようにしているエッジ抽出手段と、
前記抽出された複数の折れ線を構成する頂点座標列をもとに、各々の折れ線を直線近似し、各々の近似直線の傾き角を算出する傾き角算出手段と、
前記算出された複数の折れ線の傾き角の平均値に基づいて、前記文書画像に対して回転処理を施して補正画像を作成する文書回転手段と、を備え、
前記二値化手段は、水平方向の全画素に占める文字画素の割合と、垂直方向の全画素に占める文字画素の割合を算出し、水平方向の全画素に占める文字画素の割合が垂直方向の全画素に占める文字画素の割合より大きい場合は横組と、垂直方向の全画素に占める文字画素の割合が水平方向の全画素に占める文字画素の割合より大きい場合は縦組と判定し、
前記文字画素領域膨張手段は、前記二値化手段により横組と判定された場合、水平方向に文字画素領域を膨張させるようにし、前記二値化手段により縦組と判定された場合、垂直方向に文字画素領域を膨張させるようにしていることを特徴とする文書画像の傾き補正装置。
A device that corrects the tilt at the time of optical reading for a document image obtained by optical reading,
Binarizing means for comparing the value of each pixel of the document image with a threshold value to create a binary image;
Among the binary images, a pixel having one value is a character pixel, a pixel having the other value is a background pixel, and a character pixel region in which character pixels exist in a horizontal direction or a vertical direction with respect to the binary image. A character pixel area expansion means for expanding;
A plurality of horizontal polygonal lines are extracted from the edge portion of the character pixel region in the binary image expanded in the horizontal direction, or the vertical direction from the edge portion of the character pixel region in the binary image expanded in the vertical direction. Edge extraction means for extracting a plurality of polygonal lines,
Inclination angle calculation means for linearly approximating each polygonal line and calculating the inclination angle of each approximate line based on the vertex coordinate string constituting the plurality of extracted polygonal lines,
Document rotation means for performing a rotation process on the document image based on the calculated average value of the inclination angles of the plurality of broken lines, and creating a corrected image,
The binarization means calculates the ratio of character pixels to all pixels in the horizontal direction and the ratio of character pixels to all pixels in the vertical direction, and the ratio of character pixels to all pixels in the horizontal direction is calculated in the vertical direction. If it is larger than the proportion of character pixels in all pixels, it is determined as horizontal composition, and if the proportion of character pixels in all pixels in the vertical direction is larger than the proportion of character pixels in all pixels in the horizontal direction, it is determined as vertical composition.
The character pixel area expansion means expands the character pixel area in the horizontal direction when the binarization means determines that the horizontal composition is used, and the character pixel area expansion means uses the vertical direction when the binarization means determines the vertical composition. inclination correction device of the document image, characterized that you have to inflate the character pixel area.
光学的読み取りを行って得られた文書画像に対して、光学的読み取り時の傾きを補正する装置であって、
前記文書画像の各画素の値としきい値を比較して二値化し、二値画像を作成する二値化手段と、
前記二値画像のうち、一方の値をとる画素を文字画素、他方の値をとる画素を背景画素とし、前記二値画像に対して水平方向または垂直方向に文字画素が存在する文字画素領域を膨張させる文字画素領域膨張手段と、
前記水平方向に膨張させた二値画像内の文字画素領域のエッジ部より水平方向の折れ線を複数抽出するか、前記垂直方向に膨張させた二値画像内の文字画素領域のエッジ部より垂直方向の折れ線を複数抽出するようにしているエッジ抽出手段と、
前記抽出された複数の折れ線を構成する頂点座標列をもとに、各々の折れ線を直線近似し、各々の近似直線の傾き角を算出する傾き角算出手段と、
前記算出された複数の折れ線の傾き角の平均値に基づいて、前記文書画像に対して回転処理を施して補正画像を作成する文書回転手段と、を備え、
前記エッジ抽出手段は、前記水平方向の折れ線を抽出するにあたり、前記水平方向に文字画素領域を膨張させた二値画像に対して垂直方向に文字画素が2個以上連続しないように補正して前記エッジ部を特定し、前記垂直方向の折れ線を抽出するにあたり、前記垂直方向に文字画素領域を膨張させた二値画像に対して水平方向に文字画素が2個以上連続しないように補正して前記エッジ部を特定しており、
さらに、前記エッジ抽出手段は、前記水平方向に文字画素領域を膨張させた二値画像に対して、垂直方向の一方から他方に向かって探索して前記水平方向の複数の折れ線を第1折れ線群として抽出するとともに、垂直方向の他方から一方に向かって探索して前記水平方向の複数の折れ線を第2折れ線群として抽出するか、または前記垂直方向に文字画素領域を膨張させた二値画像に対して、水平方向の一方から他方に向かって探索して前記垂直方向の複数の折れ線を第1折れ線群として抽出するとともに、水平方向の他方から一方に向かって探索して前記垂直方向の複数の折れ線を第2折れ線群として抽出するようにし、
前記傾き角算出手段は、前記第1折れ線群および前記第2折れ線群の各々の近似直線の傾き角を算出するようにし、
前記文書回転手段は、前記第1折れ線群の折れ線の傾き角の平均値と前記第2折れ線群の折れ線の傾き角の平均値のいずれか絶対値が大きい方の平均値に基づいて、前記回転処理を施すようにしていることを特徴とする文書画像の傾き補正装置。
A device that corrects the tilt at the time of optical reading for a document image obtained by optical reading,
Binarizing means for comparing the value of each pixel of the document image with a threshold value to create a binary image;
Among the binary images, a pixel having one value is a character pixel, a pixel having the other value is a background pixel, and a character pixel region in which character pixels exist in a horizontal direction or a vertical direction with respect to the binary image. A character pixel area expansion means for expanding;
A plurality of horizontal polygonal lines are extracted from the edge portion of the character pixel region in the binary image expanded in the horizontal direction, or the vertical direction from the edge portion of the character pixel region in the binary image expanded in the vertical direction. Edge extraction means for extracting a plurality of polygonal lines,
Inclination angle calculation means for linearly approximating each polygonal line and calculating the inclination angle of each approximate line based on the vertex coordinate string constituting the plurality of extracted polygonal lines,
Document rotation means for performing a rotation process on the document image based on the calculated average value of the inclination angles of the plurality of broken lines, and creating a corrected image,
The edge extraction unit corrects the character image area so that two or more character pixels do not continue in the vertical direction with respect to the binary image obtained by expanding the character pixel region in the horizontal direction when extracting the horizontal broken line. In specifying the edge portion and extracting the vertical polygonal line, the binary image obtained by expanding the character pixel region in the vertical direction is corrected so that two or more character pixels do not continue in the horizontal direction. The edge part is specified,
Further, the edge extraction means searches the binary image in which the character pixel region is expanded in the horizontal direction from one side in the vertical direction to the other side, and sets the plurality of horizontal lines in the first line group. And extracting the plurality of horizontal lines as a second line group by searching from one to the other in the vertical direction, or a binary image in which the character pixel area is expanded in the vertical direction. On the other hand, a search is performed from one side in the horizontal direction toward the other to extract the plurality of vertical lines as a first broken line group, and a search is performed from the other side in the horizontal direction toward the other to search the plurality of vertical lines. Extract the line as the second line group,
The inclination angle calculating means calculates an inclination angle of each approximate straight line of the first broken line group and the second broken line group;
The document rotation means is configured to perform the rotation based on an average value of the larger one of the average values of the inclination angles of the polygonal lines of the first polygonal line group and the inclination angles of the polygonal lines of the second polygonal line group. inclination correction device of the document image, characterized that you have to such as to carry out processing.
請求項において、
前記エッジ抽出手段は、前記水平方向の折れ線を抽出するにあたり、前記水平方向に文字画素領域を膨張させた二値画像に対して垂直方向に文字画素が連続する箇所を抽出し、抽出箇所の開始点または終了点の画素以外を背景画素に置換することにより、垂直方向に文字画素が2個以上連続しないようにして前記エッジ部を特定し、
前記垂直方向の折れ線を抽出するにあたり、前記垂直方向に文字画素領域を膨張させた二値画像に対して水平方向に文字画素が連続する箇所を抽出し、抽出箇所の開始点または終了点の画素以外を背景画素に置換することにより、水平方向に文字画素が2個以上連続しないようにして前記エッジ部を特定していることを特徴とする文書画像の傾き補正装置。
In claim 2 ,
The edge extracting means extracts a portion where character pixels continue in the vertical direction with respect to the binary image obtained by expanding the character pixel region in the horizontal direction when extracting the horizontal broken line, and starts the extraction portion. By replacing the pixel other than the pixel at the point or the end point with the background pixel, the edge portion is specified so that two or more character pixels do not continue in the vertical direction,
In extracting the vertical broken line, a portion where character pixels continue in the horizontal direction is extracted from the binary image obtained by expanding the character pixel region in the vertical direction, and a pixel at the start point or end point of the extraction portion A document image inclination correction apparatus characterized in that the edge portion is specified so that two or more character pixels do not continue in the horizontal direction by substituting a pixel other than the background pixel.
請求項または請求項において、
前記エッジ抽出手段は、水平方向に隣接する文字画素が垂直方向に上下M画素(M>1)以内に収まっている文字画素の座標列を前記水平方向の折れ線の頂点座標列として抽出するようにし、垂直方向に隣接する文字画素が水平方向に左右M画素以内に収まっている文字画素の座標列を前記垂直方向の折れ線の頂点座標列として抽出するようにしていることを特徴とする文書画像の傾き補正装置。
In claim 2 or claim 3 ,
The edge extraction means extracts a character string coordinate string in which character pixels adjacent in the horizontal direction are within vertical M pixels (M> 1) in the vertical direction as a vertex coordinate string of the horizontal broken line. A character image coordinate string in which character pixels adjacent in the vertical direction are within M pixels left and right in the horizontal direction is extracted as a vertex coordinate string of the broken line in the vertical direction. Tilt correction device.
光学的読み取りを行って得られた文書画像に対して、光学的読み取り時の傾きを補正する装置であって、
前記文書画像の各画素の値としきい値を比較して二値化し、二値画像を作成する二値化手段と、
前記二値画像のうち、一方の値をとる画素を文字画素、他方の値をとる画素を背景画素とし、前記二値画像に対して水平方向または垂直方向に文字画素が存在する文字画素領域を膨張させる文字画素領域膨張手段と、
前記水平方向に膨張させた二値画像内の文字画素領域のエッジ部より水平方向の折れ線を複数抽出するか、前記垂直方向に膨張させた二値画像内の文字画素領域のエッジ部より垂直方向の折れ線を複数抽出するようにしているエッジ抽出手段と、
前記抽出された複数の折れ線を構成する頂点座標列をもとに、各々の折れ線を直線近似し、各々の近似直線の傾き角を算出する傾き角算出手段と、
前記算出された複数の折れ線の傾き角の平均値に基づいて、前記文書画像に対して回転処理を施して補正画像を作成する文書回転手段と、を備え
前記傾き角算出手段は、前記折れ線の頂点座標列の重心を算出し、重心と各頂点座標との水平方向の平均距離と、重心と各頂点座標との垂直方向の平均距離との比率に対して逆正接(arctangent)を算出することにより前記傾き角を算出するようにしていることを特徴とする文書画像の傾き補正装置。
A device that corrects the tilt at the time of optical reading for a document image obtained by optical reading,
Binarizing means for comparing the value of each pixel of the document image with a threshold value to create a binary image;
Among the binary images, a pixel having one value is a character pixel, a pixel having the other value is a background pixel, and a character pixel region in which character pixels exist in a horizontal direction or a vertical direction with respect to the binary image. A character pixel area expansion means for expanding;
A plurality of horizontal polygonal lines are extracted from the edge portion of the character pixel region in the binary image expanded in the horizontal direction, or the vertical direction from the edge portion of the character pixel region in the binary image expanded in the vertical direction. Edge extraction means for extracting a plurality of polygonal lines,
Inclination angle calculation means for linearly approximating each polygonal line and calculating the inclination angle of each approximate line based on the vertex coordinate string constituting the plurality of extracted polygonal lines,
Document rotation means for performing a rotation process on the document image based on the calculated average value of the inclination angles of the plurality of broken lines, and creating a corrected image ,
The inclination angle calculation means calculates the center of gravity of the vertex coordinate sequence of the broken line, and the ratio of the average distance in the horizontal direction between the center of gravity and each vertex coordinate and the average distance in the vertical direction between the center of gravity and each vertex coordinate. inclination correction device of the document image, characterized that you have to calculate the tilt angle by calculating the arctangent (arctangent) Te.
請求項1から請求項5のいずれか一項において、
前記文字画素領域膨張手段は、対象とする背景画素より水平方向にD画素(D>2)以内に文字画素が少なくとも1つ存在するか、当該背景画素より垂直方向にD画素以内に文字画素が少なくとも1つ存在する場合に、当該背景画素を文字画素に置換することにより、水平方向または垂直方向に文字画素領域を膨張させるようにしていることを特徴とする文書画像の傾き補正装置。
In any one of Claims 1-5 ,
The character pixel area expanding means has at least one character pixel within D pixels (D> 2) in the horizontal direction from the target background pixel, or has a character pixel within D pixels in the vertical direction from the background pixel. An apparatus for correcting a tilt of a document image, wherein when at least one exists, a character pixel region is expanded in a horizontal direction or a vertical direction by replacing the background pixel with a character pixel.
請求項1から請求項のいずれか一項において、
前記補正画像に対して非可逆圧縮を施して所定の形式の電子文書ファイルを作成する電子文書作成手段をさらに有することを特徴とする文書画像の傾き補正装置。
In any one of Claims 1-6 ,
An apparatus for correcting inclination of a document image, further comprising electronic document creation means for creating an electronic document file of a predetermined format by irreversibly compressing the corrected image.
請求項1から請求項のいずれか一項において、
前記補正画像に対して、RGB各階調の深さを所定の深さ以下に低下させることにより全体の色数を所定数以下に低下させた色数削減画像を作成し、色数削減画像に対して圧縮を施して所定の形式の電子文書ファイルを作成する電子文書作成手段をさらに有することを特徴とする文書画像の傾き補正装置。
In any one of Claims 1-6 ,
For the corrected image, a color number reduced image in which the total number of colors is reduced to a predetermined number or less by reducing the depth of each RGB gradation to a predetermined depth or less is obtained. And a document image inclination correction device, further comprising electronic document creation means for creating an electronic document file of a predetermined format by performing compression.
請求項または請求項において、
前記電子文書作成手段は、前記補正画像を基に特定された文字コードを非描画属性に設定し、割り付け位置を維持しながら前記電子文書ファイルに組み込むようにしていることを特徴とする文書画像の傾き補正装置。
In claim 7 or claim 8 ,
The electronic document creation means sets a character code specified based on the corrected image as a non-drawing attribute, and incorporates the character code into the electronic document file while maintaining the assigned position. Tilt correction device.
請求項1から請求項のいずれか一項に記載の文書画像の傾き補正装置としてコンピュータを機能させるためのプログラム。
Program for causing a computer to function as inclination correction device of the document image according to any one of claims 1 to 9.
JP2013108627A 2013-05-23 2013-05-23 Document image skew correction device Expired - Fee Related JP6108100B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP2013108627A JP6108100B2 (en) 2013-05-23 2013-05-23 Document image skew correction device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP2013108627A JP6108100B2 (en) 2013-05-23 2013-05-23 Document image skew correction device

Publications (2)

Publication Number Publication Date
JP2014230119A JP2014230119A (en) 2014-12-08
JP6108100B2 true JP6108100B2 (en) 2017-04-05

Family

ID=52129588

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2013108627A Expired - Fee Related JP6108100B2 (en) 2013-05-23 2013-05-23 Document image skew correction device

Country Status (1)

Country Link
JP (1) JP6108100B2 (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR101972857B1 (en) * 2018-02-02 2019-04-26 주식회사 엘지씨엔에스 Method for managing security of output document and document managing server based deep learning
JP7211166B2 (en) 2019-03-04 2023-01-24 京セラドキュメントソリューションズ株式会社 IMAGE TILT ANGLE DETECTION DEVICE, IMAGE FORMING APPARATUS AND IMAGE TILT ANGLE DETECTION PROGRAM
CN115082461B (en) * 2022-08-19 2022-11-04 成都中医药大学 Edge calculation-based pre-judgment filtering method and device

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH0792104A (en) * 1993-09-27 1995-04-07 Mec:Kk Method for inspecting defective point of object
JPH08241376A (en) * 1995-03-02 1996-09-17 Canon Inc Device and method for character recognition
JP4170441B2 (en) * 1997-11-28 2008-10-22 富士通株式会社 Document image inclination detection apparatus and storage medium for document image inclination detection program
JP3998439B2 (en) * 2001-07-12 2007-10-24 グローリー株式会社 Image processing apparatus, image processing method, and program causing computer to execute these methods
JP4571066B2 (en) * 2005-11-18 2010-10-27 株式会社リコー Image processing apparatus and image reading apparatus
JP4783441B2 (en) * 2009-02-09 2011-09-28 シャープ株式会社 Image processing apparatus and scanner apparatus

Also Published As

Publication number Publication date
JP2014230119A (en) 2014-12-08

Similar Documents

Publication Publication Date Title
US8634659B2 (en) Image processing apparatus, computer readable medium storing program, and image processing method
US7460710B2 (en) Converting digital images containing text to token-based files for rendering
JP5875637B2 (en) Image processing apparatus and image processing method
US8520006B2 (en) Image processing apparatus and method, and program
JP4694613B2 (en) Document orientation determination apparatus, document orientation determination method, program, and recording medium therefor
JPH118755A (en) Method for scanning and detecting many photographs and removing artificial edge
JP2010171976A (en) Method and system for correcting distorted document image
US7454067B1 (en) Symbol classification depending on cluster shapes in difference image
JP6108100B2 (en) Document image skew correction device
JP2009302758A (en) Image processing device, image conversion method, and computer program
JP2018139457A (en) Image processing apparatus, control method for image processing and program
US10586125B2 (en) Line removal method, apparatus, and computer-readable medium
CN115619656A (en) Digital file deviation rectifying method and system
JP4582200B2 (en) Image processing apparatus, image conversion method, and computer program
JP5049922B2 (en) Image processing apparatus and image processing method
JP2006209353A (en) Image determination apparatus, image formimg apparatus, image determination method, image determination program, image formimg program, and computer readable recording medium
JP4605260B2 (en) Vector image generation method, image processing apparatus, and computer program
US8934144B2 (en) Overcoat processing mechanism
US9659230B2 (en) Methods and systems for estimating skew angle of an image
JP4208520B2 (en) Image processing apparatus, image processing method, program, and storage medium
JP2002150280A (en) Distortion correcting method
JP2006237858A (en) Image processing apparatus, image processing method, program for allowing computer to execute the method, and recording medium
JP7301529B2 (en) Image processing device, image processing method, and program
JP2006201885A (en) Image decision unit, method, and program, and image forming unit and program, image decision program, and computer-readable recording medium
CN111681161B (en) Restoration method and device for folded two-dimensional code image and computer readable storage medium

Legal Events

Date Code Title Description
A621 Written request for application examination

Free format text: JAPANESE INTERMEDIATE CODE: A621

Effective date: 20160418

A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20161129

A521 Written amendment

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20170117

TRDD Decision of grant or rejection written
A01 Written decision to grant a patent or to grant a registration (utility model)

Free format text: JAPANESE INTERMEDIATE CODE: A01

Effective date: 20170208

A61 First payment of annual fees (during grant procedure)

Free format text: JAPANESE INTERMEDIATE CODE: A61

Effective date: 20170221

R150 Certificate of patent or registration of utility model

Ref document number: 6108100

Country of ref document: JP

Free format text: JAPANESE INTERMEDIATE CODE: R150

LAPS Cancellation because of no payment of annual fees