JP3885001B2 - Image processing method and image processing apparatus - Google Patents
Image processing method and image processing apparatus Download PDFInfo
- Publication number
- JP3885001B2 JP3885001B2 JP2002188353A JP2002188353A JP3885001B2 JP 3885001 B2 JP3885001 B2 JP 3885001B2 JP 2002188353 A JP2002188353 A JP 2002188353A JP 2002188353 A JP2002188353 A JP 2002188353A JP 3885001 B2 JP3885001 B2 JP 3885001B2
- Authority
- JP
- Japan
- Prior art keywords
- image
- image processing
- processing method
- black
- histogram
- 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
Links
Images
Landscapes
- Facsimile Image Signal Circuits (AREA)
- Image Analysis (AREA)
Description
【0001】
【発明の属する技術分野】
本発明は、画像処理方法及び画像処理装置に関し、特に矩形画像の検出を行う画像処理方法及び画像処理装置に関する。
【0002】
【従来の技術】
従来より、原画像から矩形領域を検出し、切り出すためのアルゴリズムが種々提案されている。例えば、特開平8-237537号においては、まず輪郭抽出を行い、輪郭が直線を成す部分を探すことによって矩形領域の探索を行なう技術が記載されている。
【0003】
【発明が解決しようとする課題】
しかしながら従来の矩形切り出しのアルゴリズムによれば、ノイズの多い環境下においては、矩形輪郭の直線部分を検出すること、さらに、4つの直線を関連付けて1個の矩形を検出することは困難であった。従って、正確な切り出しを行うことは困難であり、切り出し結果の精度は十分とはいえなかった。
【0004】
本発明は上述した問題を解決するためになされたものであり、ノイズの多い環境下でも矩形領域を高精度に検出可能とする画像処理方法及び画像処理装置を提供することを目的とする。
【0005】
【課題を解決するための手段】
上記目的を達成するための一手法として、本発明の画像処理方法は以下の工程を備える。
【0006】
すなわち、画像から矩形領域を検出する画像処理方法であって、原画像を2値化した画像において、その水平及び垂直方向の黒画素数のヒストグラムを作成するヒストグラム作成工程と、該ヒストグラムを台形近似することによって、前記2値画像における矩形領域の存在範囲を検出する矩形範囲検出工程と、前記存在範囲内における、前記矩形領域の傾き方向を検出する傾き方向検出工程とを有し、前記矩形範囲検出工程においては、前記矩形領域が長方形であると仮定して、前記ヒストグラムの形状が、左右の斜辺が対称となる台形を呈するように、該左右の斜辺について回帰分析による直線近似の精度を比較して、誤差の少ない一方の斜辺から得られるデータに合わせて、他方の斜辺のデータを修正することを特徴とする。
【0007】
さらに、前記2値画像に対してラベル付けを行うラベリング工程を有し、前記ヒストグラム作成工程においては、前記ラベル付けされた画素数のヒストグラムを作成することを特徴とする。
【0008】
【発明の実施の形態】
以下、本発明に係る一実施形態について、図面を参照して詳細に説明する。
【0009】
<第1実施形態>
●システム構成
図1は、本発明が実行されるコンピュータシステムの構成を示すブロック図である。101はCPUであり、システム全体の制御を行なう。102はキーボードであり、102aのマウスとともにシステムへのデータ入力に使用される。103は表示装置であり、CRTや液晶等で構成されている。104はROM、105はRAMであり、システムの記憶装置を構成し、システムが実行するプログラムやシステムが利用するデータを記憶する。106はハードディスク装置(HDD)、107はフロッピディスク装置(FDD)であり、システムのファイルシステムに使用される外部記憶装置を構成している。108はプリンタである。
【0010】
109はネットワークI/Fであり、LANまたはWANに接続している。I/F109を介して、コンピュータプログラムやデジタル画像等のデータファイルを他のコンピュータシステムとやりとりすることができる。プログラムやデータはハードディスク106に記録されたり、直接RAM105に展開されて実行される。
【0011】
110はイメージスキャナであり、原稿台上の写真や印刷物を読み込んで、多値のデジタル画像データとしてRAM105上に取り込むことができる。
【0012】
●矩形画像概要
図2に、イメージスキャナ110から取り込んで2値化された画像の一例を示す。図中の矩形は、写真等の矩形の原稿画像(以下、矩形画像と称する)を示し、3つの楕円はノイズを示している。なお、同図においては説明のためノイズを簡略化して示したが、実際のノイズ分はサイズも形状も不定であり、その数も数百から数千個程度になることが多い。また、画像の2値化は所定の閾値との比較による周知の単純二値化法を用いるとし、ここでは詳細な説明を省略する。
【0013】
図2に示す画像は、RAM105上で幅W画素、高さH画素のビットマップとして保持されている。各画素は1バイトの深さを持ち、黒画素は値255、白画素は値0で示されるとする。また、RAM105上のビットマップは2次元配列としてアクセスできるものとし、該ビットマップの左上を起点として水平方向にi番目、垂直方向にj番目の画素をbuf(i,j)と表記する。本実施形態ではこのビットマップから、以下に示す方法によって矩形画像の存在領域の座標を特定する。
【0014】
●ヒストグラム作成
図3は、図2に示す2値画像においてノイズが存在しない理想的な状態を想定した場合に、水平方向に黒画素を計数したヒストグラムの様子を示す図であり、同図上部が2値画像、下部がヒストグラム例を示す。同図によれば、2値画像の矩形の4頂点に対応して、ヒストグラムが概ね台形をなすことがわかる。なお、実際の2値画像はノイズを含むため、ヒストグラムが完全な台形となることはないが、水平方向における頂点の位置を特定するのに十分な情報を、このヒストグラムの台形形状から得ることができる。
【0015】
図4は、図3に示したヒストグラムの作成処理を示すフローチャートである。以下、ヒストグラムデータを格納する配列をhist()で示す。
【0016】
先ずステップS401,S402において、変数x,y及びのそれぞれに値0を代入し、ステップS403で変数hist(x)に値0を代入する。
【0017】
そしてステップS404において、ビットマップ上の画素buf(x,y)と値255を比較し、異なればステップS406へ進むが、等しければステップS405へ進んでhist(x)を値1だけインクリメントした後、ステップS406へ進む。
【0018】
ステップS406では変数yを値1だけインクリメントし、次にステップS407においてyとビットマップの高さHを比較する。yとHが異なればステップS404へ戻るが、等しければステップS408へ進んで変数xを値1だけインクリメントし、ステップS409でxとビットマップ幅Wを比較する。xとWが異なればステップS402へ戻るが、等しければ処理を終了する。
【0019】
●頂点検出処理
以上の処理によって、黒画素を計数したヒストグラムの配列hist()が得られる。このヒストグラムは図3に示したように、X軸及び3つの直線で囲まれた台形をなしている。本実施形態ではこの台形において、左辺がX軸と交わる位置をa、左辺と上底が交わる位置をb、右辺と上底が交わる位置をc、右辺がX軸と交わる位置をdとする。
【0020】
ここで図5のフローチャートを用いて、ヒストグラムが呈する台形の左辺を解析して、上記位置a,bを求める方法について説明する。
【0021】
まずステップS501において、hist(x)が最大になるピーク点Pを検出する。図3に示すヒストグラムにおいては、X=400前後の位置に高さ800のピークがある。次にステップS502において、点Pの前方向に、ピークの半分の高さになる点Fを検出する。図3に示すヒストグラムにおいては、X=100前後の位置が点Fに相当する。そしてステップS503で、点Fの前方向にピークの1/4の高さになる点F0を検出し、さらにステップS504で、点Fの後方向にピークの3/4の高さになる点F1を検出する。
【0022】
次にステップS505において、F0≦X≦F1の全ての点について、周知の回帰分析を用いて直線近似を行うことによって、図3に示すような直線Lを得る。そしてステップS506において直線LがX軸と交わる点を算出し、この点をaとして得る。そしてステップS507において、直線LがピークPの高さの98%になる点を算出し、この点をbとして得る。これは、ピークPはノイズ分を含んでいるため実際のピークよりも多めに出ていることを考慮して、これを98%分に補正するためである。
以上、図5に示すフローチャートにより、ピークPの前方向への探索を行って点a,bを得る例について説明したが、同様にピークPの後方向に探索を行うことにより、点c、dを得ることができる。
【0023】
また、以上は水平方向の頂点位置検出についての説明であるが、上記説明における縦軸と横軸を反転して全く同様の方法を適用することにより、垂直方向における頂点位置検出を行うことが可能である。これにより図6に示すように、矩形を囲む縦横それぞれ4個の座標値、すなわち8個の変数(ax,bx,cx,dx,ay,by,cy,dy)を、頂点候補として得ることができる。
【0024】
ここで、矩形から上記8つの変数は一意に決定されるが、逆に、8つの変数から矩形を決定することはできない。すなわち図7に示すように、8つの変数に基づく矩形としては、その斜行方向(以下、斜行モード)によって4通りの頂点座標が考えられるが、そのいずれであるかを決定することができない。なお図7においては、矩形が完全に水平である特別な場合(不図示)をモード0として、4つの斜行モードをそれぞれ、モード1,2,-1,-2とする。これら各モードで示される画像からは同じ形状のヒストグラムが生成されるため、ヒストグラム以外の他の方法によって、斜行モードを判定する必要がある。
【0025】
●斜行モード判定
以下、本実施形態における斜行モード判定処理について、詳細に説明する。
【0026】
上述した図6は、図7に示すモード1の状態に相当するが、図6において斜線で示した2つの三角領域の内側に存在する黒画素を計数すると、理想的には黒画素(図中網点部分)が含まれないため、黒画素の計数結果は0になると考えられる。以下、この図6に示す斜線領域を、モード1のテンプレートと呼ぶ。なお、図7に示す他のモードについても同様に、矩形上部に存在する2つの三角領域を、各モードのテンプレートとする。
【0027】
ここで図8に示すように、実際にはモード1である矩形画像(図中網点部分)に対してモード2のテンプレート(図中斜線部分)を当てはめると、テンプレートの内側に矩形部分がはみ出してしまうため、黒画素数の計数結果は0にならない。本実施形態ではこの特性を利用して、矩形の斜行モードを判定する。
【0028】
具体的には、判定対象となる矩形画像に対して4つのモードのテンプレートを適用した場合の黒画素数をそれぞれ計数し、計数結果が最少であるテンプレートを、その画像の斜行モードとして決定する。すなわち、テンプレートへの入り込みの度合いが最も少ない場合が、該矩形画像が最も近似する斜行度合いであるとする。もちろん、テンプレート外に存在する黒画素を計数し、計数結果が最大であるテンプレートによって斜行モードを決定することも可能である。
【0029】
以上の処理により、2値画像中の矩形領域の4つの頂点座標を特定することができる。従ってこの情報に基づき、原画像に対して周知の斜行補正及び画像切り出し処理を施すことによって、例えばイメージスキャナ110上に配置した矩形の写真画像を切り出すことができる。
【0030】
なお、上記周知の斜行補正処理としては、単純補間法(ニアレストネイバ法)または線形補間法(バイリニア法)を用いることが望ましく、前者は速度に優れ、後者は画質に優れるので、用途に応じて使い分ければ良い。
【0031】
以上説明したように本実施形態によれば、ノイズの多い環境下であっても、矩形領域を正確に検出することができる。
【0032】
なお、矩形領域が完全な長方形であれば、理想的なヒストグラムとして、左右の斜辺が対称となる理想的な台形を呈するはずであるが、ノイズの影響により左右の斜辺が対称とはならず、すなわち、図3に示すa-b間の距離が、c-d間の距離と等しくならないことがある。そのような場合には、ノイズの影響が少ないと考えられる方の斜辺から得られるデータにあわせて、台形近似を行う。具体的には左右の斜辺について、回帰分析による直線近似の精度(直線と実データの間の2乗誤差)を比較して、誤差の少ないほうを採用すれば良い。
【0033】
同様に、矩形検出の結果として得られた4つの頂点を結んだ矩形が、ノイズの影響で必ずしも長方形にならず、隣り合う辺が直交しないことも考えられる。このような場合も、ノイズの影響が少ないと考えられる方のデータに基づいて、矩形が長方形になるように修正を施すことで、矩形検出の精度を向上することができる。
【0034】
<第2実施形態>
以下、本発明に係る第2実施形態について説明する。なお、第2実施形態におけるシステム構成は上述した第1実施形態と同様であるため、説明を省略する。
【0035】
上述した第1実施形態においては、画像内に1つの矩形領域が存在する場合について説明した。このような状況としては例えば、イメージスキャナ110の原稿台上に1枚の写真を必ずしも水平ではなく載置した状態でスキャンを行い、その後自動的に斜行補正、画像切り出しを行うことで、写真画像を抽出する処理が想定される。
【0036】
しかしながら、一般的なフラットヘッドスキャナの原稿台はA4サイズ程度の原稿の載置を可能とするため、一般的な写真(所謂L版サイズ)の複数枚を一度に載置することができる。従って、このような複数枚の写真画像を一回のスキャンによって読み取り、得られた画像から写真画像を示す矩形領域だけを切り出すことができれば、スキャン作業の効率化が図れる。
【0037】
そこで第2実施形態においては、一枚の画像から、複数の矩形画像を検出することを特徴とする。
【0038】
以下、図9を参照して、第2実施形態における複数の矩形画像の検出処理について説明する。図9の左部は、原稿台の副走査方向(図中長手方向)に2枚の写真を離して配置した際の2値化画像を示し、図9の右部は該2値化画像の副走査方向におけるヒストグラムの様子を示す。同図から分かるように、複数枚の写真が離れて配置されている場合、ヒストグラムに複数個の台形が現れる。従って第2実施形態においてはこのヒストグラムを参照することによって、これら複数の台形の間、すなわち図9において1点鎖線Lで示した位置で、画像を二つに切り分ける。すると、以降は上述した第1実施形態で示した方法によって、該切り分けられた各々の領域において、矩形画像をそれぞれ検出することができる。
【0039】
なお、図9においては複数枚の写真を副走査方向に離して配置した場合について説明したが、これを主走査方向(図中短手方向)に離して配置した場合も同様に、主走査方向についてのヒストグラムを作成することによって、画像を主走査方向で切り分け、それぞれの矩形画像を抽出することができる。
【0040】
以上説明したように第2実施形態によれば、一枚の画像から複数の矩形画像を検出することができる。
【0041】
<第3実施形態>
以下、本発明に係る第3実施形態について説明する。なお、第3実施形態におけるシステム構成は上述した第1実施形態と同様であるため、説明を省略する。
【0042】
第3実施形態においては、図2に示すような2値画像に対して理想的なラベリング処理を施すことによってノイズの影響を排除し、矩形画像の検出をより高精度に行うことを特徴とする。
【0043】
ここで、図2に示す2値画像における理想的なラベリング処理とは、黒画素同士の連結に基づき、例えば上方の矩形オブジェクトに含まれる全ての画素に対して画素値1を与え、下方の矩形オブジェクトに含まれる全画素に対しては画素値2を与えることである。すなわち、微小なノイズ分にはラベルを与えず、画素値255のままにしておく。
【0044】
●ラベリング処理概要
以下、上記理想的なラベリングを実現するためのラベリング方法について、詳細に説明する。
【0045】
図10は、図2における上方の矩形オブジェクトを含む左上部分に対応し、第3実施形態における塗りつぶし処理の起点となるブロックの探索方法を説明するための図である。
【0046】
まず図10に示すように、図2に示したW画素×H画素のビットマップ全体を、w画素×h画素のブロックに分け、その内部が全て値255の黒画素で占められるようなブロック(以下、「黒ブロック」と称する)を図中矢印方向に探索する。図3において黒矩形で示したブロックが、見つかった黒ブロックである。
【0047】
第3実施形態では、見つかった黒ブロックと黒画素が連結している領域を塗りつぶすことによって、高速なラベリングを実現する。図11に、第3実施形態におけるラベリング処理全体のフローチャートを示し、説明する。
【0048】
まずステップS1401で、変数cに値1を代入し、ステップS1402で黒ブロック探索を行う。この黒ブロック探索処理の詳細については後述する。
【0049】
次にステップS1403において黒ブロックが見つかったか否かを判断し、見つかったらステップS1404へ進むが、見つからなければ処理を終了する。
【0050】
ステップS1404では、見つかった黒ブロックを起点にして、黒画素連結領域をラベルcで塗りつぶす。この塗りつぶし処理の詳細については後述する。
【0051】
そしてステップS1405で変数cを1だけインクリメントしてステップS1402に戻り、以上の処理を繰り返す。
【0052】
この処理の結果、所定以上の大きさを持つオブジェクトのみに対して、ラベル1,2,…,cを与えることができる。
【0053】
●黒ブロック探索処理
以下、図11のステップS1402に示した黒ブロック探索処理の詳細を図12のフローチャートに示し、説明する。
【0054】
まずステップS1501〜S1504において、変数y,x,j,iをそれぞれ値0で初期化する。そしてステップS1505でbuf(x+i,y+j)が黒画素を示す255であるか否かを判断し、255であればステップS1506へ、255でなければステップS1510へ進む。
【0055】
ステップS1506では変数iを値1だけインクリメントし、ステップS1507でiがブロック幅を示すwに等しければステップS1508へ進み、異なればステップS1505へ進む。
【0056】
ステップS1508では変数jを値1だけインクリメントし、ステップS1509でjがブロック高さを示すhに等しければ処理を終了し、このとき、(x,y)を左上起点とするw×h画素ブロックが黒ブロックであるとして検出される。jがhと異なるときはステップS1504へ戻る。
【0057】
ステップS1510ではxにwを加え、ステップS1511でxが画像幅を示すW以上であればステップS1512へ進み、そうでなければステップS1503へ戻る。
【0058】
ステップS1512ではyにhを加え、ステップS1513でyが画像高さを示すH以上であれば処理を終了し、このとき、黒ブロックは存在しないと判定される。yがH未満であればステップS1502へ戻る。
【0059】
以上の処理によって、W画素×H画素の2値画像からw画素×h画素の黒ブロックが検出される。
【0060】
●連結領域の塗りつぶし処理
以下、図11のステップS1404に示した連結領域の塗りつぶし処理の詳細を図13のフローチャートに示し、説明する。
【0061】
なお、オブジェクトの塗りつぶし処理としては種々の方法が知られており、第3実施形態ではどのような塗りつぶし方法を用いても良い。したがって、ここでは基本的な方法について説明することとし、説明の簡略化のためオブジェクトは外に凸である単純な形状であると仮定する。
【0062】
上述した黒ブロック探索処理の結果、図14に示すように(x,y)を左上起点とするブロックが黒ブロックとして検出されている。そこで第3実施形態の塗りつぶし処理においては、この黒ブロックの中心点である((x+w)/2,(y+h)/2)を起点として、黒画素で連結している領域をラベルcで塗りつぶす。すなわち、値255である画素値を値cで置き換える。
【0063】
具体的にはまずステップS601において、黒ブロックの中心点((x+w)/2,(y+h)/2)を含む走査線について、該走査線上の黒連結部分をラベルcで塗りつぶす。すなわち、図14に示す黒ブロックを含むオブジェクトにおける上記走査線の左端(x0,y+h/2)と右端(x1,y+h/2)を結ぶ線分(図14においてオブジェクトを水平方向に切断する線分)がラベルcで塗りつぶされる。なお、上記(x0,y+h/2)と(x1,y+h/2)を結ぶ線分を以下では連結線分と称し、その塗りつぶし処理の詳細については後述する。
【0064】
そして、ステップS602で連結線分から下にある黒連結部分を塗りつぶし、ステップS603で連結線分から上にある黒連結部分を塗りつぶす。なお、ステップS602,S603における塗りつぶし処理の詳細については後述する。
【0065】
この処理の結果、黒ブロックと黒画素で連結した領域を、ラベルcで塗りつぶすことができる。
【0066】
●連結線分の塗りつぶし処理
以下、図13のステップS601に示した連結線分の塗りつぶし処理の詳細を図15のフローチャートに示し、説明する。なお、説明の簡略化のために、処理の起点となる黒ブロックの中心点((x+w)/2,(y+h)/2)を、座標(X,Y)で示すとする。すなわち、X=(x+w)/2,Y=(y+h)/2とする。
【0067】
まず、ステップS801で変数iにXを代入し、ステップS802でiを値1だけデクリメントする。そして、ステップS803でbuf(i,Y)が値255に等しいか否かを判定し、異なればステップS804へ進むが、等しければステップS802へ戻ってiをさらにデクリメントする。
【0068】
ステップS804では変数x0に値i+1を格納し、ステップS805では変数iにXを代入する。そしてステップS806でiを値1だけインクリメントし、ステップS807でbuf(i,Y)が値255に等しいか否かを判定し、等しければステップS808へ進むが、異なればステップS806へ戻ってiをさらにインクリメントする。
【0069】
ステップS808では、変数x1に値i-1を格納し、ステップS809では変数iに値x0を代入し、ステップS810ではbuf(i,Y)にcを代入する。そしてステップS811でiを値1だけインクリメントし、ステップS812でiがx1よりも大きければ処理を終了するが、そうでなければステップS810に戻る。
【0070】
この処理により、変数x0,x1に連結線分の両端におけるx座標を格納し、該連結線分をラベルcで塗りつぶすことができる。
【0071】
●連結線分から下(上)の塗りつぶし処理
以下、図13のステップS602に示した連結線分から下にある黒連結部分の塗りつぶし処理の詳細を図16のフローチャートに示し、説明する。なお、ここでもY=y+h/2とし、したがって、(x0,Y)と(x1,Y)を結ぶ連結線分より下の黒連結部分をラベルcで塗りつぶす。
【0072】
まず、ステップS901で変数Yを値1だけインクリメントし、ステップS902で変数iにx0を代入する。そしてステップS903でbuf(i,Y)が値255に等しいか否かを判定し、異なればステップS904へ、等しければステップS906へ進む。
【0073】
ステップS904ではiを値1だけインクリメントし、ステップS905でiがx1よりも大きければ処理を終了するが、そうでなければステップS903に戻る。
【0074】
ステップS906ではXにiを代入し、ステップS907で(X,Y)を起点として、横方向、すなわち走査線上の連結線分を塗りつぶす。なお、この走査線上の塗りつぶし処理については図15のフローチャートで示したため、ここではその詳細な説明を省略する。
【0075】
なお、図13のステップS603に示した連結線分から上にある黒連結部分の塗りつぶし処理については、基本的に上述した図16のフローチャートに示す、下方向への塗りつぶし処理と同様であり、ステップS901においてYをインクリメントする代わりにデクリメントすれば良く、他のステップについては同様の処理を行えば良い。
【0076】
以上説明したようなラベリング処理によれば、所定サイズの黒ブロックを含むオブジェクト、すなわち所定サイズ以上の面積をもつオブジェクトについてのみ、ラベル付けを行うことができる。したがって、微小なノイズ領域に対してラベルを付けてしまうことがなく、高速なラベリングが可能になる。
【0077】
●ラベリング後の矩形検出
以上のラベリング処理により、図2に示すbuf()の2次元配列においては、同図上方の矩形オブジェクトに含まれる全ての画素に対してラベル1としての画素値1が、下方の矩形オブジェクトに含まれる全画素に対してはラベル2としての画素値2が、それ以外の微小ノイズ部分の黒画素には画素値255が、背景の白画素には値0が、それぞれ格納される。
【0078】
第3実施形態においては、各ラベル領域毎に矩形オブジェクトの位置(頂点座標)を判定する。すなわち、ラベリング後の画像に対して、上述した第1及び第2実施形態において説明した矩形検出処理を施す。具体的には、上述した図4に示すヒストグラムの作成フローチャートにおいて、ステップS404に示すbuf()の比較対象を、黒画素を示す値255から、ラベル値(この場合、1または2)に変更すれば良い。これにより、ラベル1及びラベル2の領域が、矩形として検出される。
【0079】
なお、ここでは2個の矩形を含む場合を例として説明したが、任意個数の矩形を含む2値画像に対して上記ラベリング処理を施し、各ラベル毎に、矩形検出処理を行うことが可能であることは言うまでもない。
【0080】
以上説明したように第3実施形態によれば、2値画像に対して理想的なラベリング処理を施すことによってノイズの影響を排除し、矩形画像の検出をより高精度に行うことができる。
【0081】
<第4実施形態>
以下、本発明に係る第4実施形態について説明する。なお、第4実施形態におけるシステム構成は上述した第1実施形態と同様であるため、説明を省略する。
【0082】
上述した第3実施形態においては、2値画像から黒ブロックの探索を行なう際にまず2値画像全体をブロックに分割した後に、各ブロックの内部が全て黒画素であるか否かをチェックした。しかしながら黒ブロックの探索方法としては他の方法も適用可能であり、例えば第4実施形態においては、2値画像内におけるブロックの左上座標を連続的に変化させていく方法について説明する。この方法によれば演算負荷は高くなるものの、黒ブロックの検出性能を向上することができる。
【0083】
図17は、第4実施形態において矩形オブジェクト内の黒ブロックを探索する様子を示す図である。同図によれば第4実施形態における探索の起点(x,y)は、第3実施形態で図10に示したブロック境界からは外れた位置にあることが分かる。
【0084】
図18に、第4実施形態における黒ブロックの探索処理のフローチャートを示し、詳細に説明する。
【0085】
まずステップS1101〜S1104において、変数y,x,j,iをそれぞれ値0で初期化する。そしてステップS1105でbuf(x+i,y+j)が黒画素を示す255であるか否かを判断し、255であればステップS1106へ、255でなければステップS1110へ進む。
【0086】
ステップS1106では変数iを値1だけインクリメントし、ステップS1107でiがブロック幅を示すwに等しければステップS1108へ進み、異なればステップS1105へ進む。
【0087】
ステップS1108では変数jを値1だけインクリメントし、ステップS1109でjがブロック高さを示すhに等しければ処理を終了し、このとき、(x,y)を左上起点とするw×h画素ブロックが黒ブロックであるとして検出される。jがhと異なるときはステップS1104へ戻る。
【0088】
ステップS1110ではxにi+1を加える。なお、ここでxを単に値1だけインクリメントしても、最終的には全く同様の結果が得られるが、i+1を加えることで探索の無駄を省き、処理を高速化できる。
【0089】
そして、ステップS1111でxが画像幅を示すW以上であればステップS1112へ進み、そうでなければステップS1103へ戻る。
【0090】
ステップS1112ではyを値1だけインクリメントし、ステップS1113でyが画像高さを示すHに等しければ処理を終了し、このとき、黒ブロックは存在しないと判定される。yがHに等しくなければステップS1102へ戻る。
【0091】
以上の処理によって、W画素×H画素の2値画像からw画素×h画素の黒ブロックが検出される。そして、以降は上述した第3実施形態と同様に、黒画素連結領域の塗りつぶし及び矩形検出処理を行うことができる。
【0092】
以上説明したように第4実施形態によれば、所定サイズの黒ブロックをより高精度に検出することができる。したがって、有効なオブジェクトのみについてのラベリングを、より高精度に行うことができ、ひいては、より高精度な矩形検出が可能となる。
【0093】
なお、上述した第3及び第4実施形態によれば、ブロック内の全画素が黒画素であることを黒ブロックの判定条件としたが、例えばノイズの状態によっては、黒領域の内部に白画素が多数混入することがある。そこで本発明においては例えば、ブロック内部の黒画素数をカウントし、これが所定の閾値を超えた場合に黒ブロックであると判定しても良い。
【0094】
また、探索すべき黒ブロックは必ずしも矩形である必要はなく、例えば六角形等の多角形や、円形もしくは楕円形であってもよいし、想定されるオブジェクトの形状に応じて選択可能なようにしてもよい。
【0095】
また、探索ブロックのサイズも1つの所定サイズに限らず、例えば大きなブロックサイズから探索をはじめ、オブジェクトが見つからなければ徐々にサイズを小さくして探索を繰り返すようにしても良い。これにより、想定されたよりも小さなオブジェクトをノイズと誤認し、無視してしまう危険性を回避できる。
【0096】
【他の実施形態】
なお、本発明は、複数の機器(例えばホストコンピュータ、インタフェイス機器、リーダ、プリンタなど)から構成されるシステムに適用しても、一つの機器からなる装置(例えば、複写機、ファクシミリ装置など)に適用しても良い。
【0097】
また、本発明の目的は、前述した実施形態の機能を実現するソフトウェアのプログラムコードを記録した記憶媒体を、システムあるいは装置に供給し、そのシステムあるいは装置のコンピュータ(またはCPUまたはMPU)が記憶媒体に格納されたプログラムコードを読み出し実行することによっても達成されることは言うまでもない。
【0098】
この場合、記憶媒体から読み出されたプログラムコード自体が前述した実施形態の機能を実現することになり、そのプログラムコードを記憶した記憶媒体は本発明を構成することになる。
【0099】
プログラムコードを供給するための記憶媒体としては、例えば、フロッピーディスク、ハードディスク、光ディスク、光磁気ディスク、CD-ROM、CD-R、磁気テープ、不揮発性のメモリカード、ROMなどを用いることが出来る。
【0100】
また、コンピュータが読み出したプログラムコードを実行することにより、前述した実施形態の機能が実現されるだけでなく、そのプログラムコードの指示に基づき、コンピュータ上で稼動しているOS(オペレーティングシステム)などが実際の処理の一部を行い、その処理によって前述した実施形態の機能が実現される場合も含まれることは言うまでもない。
【0101】
さらに、記憶媒体から読み出されたプログラムコードが、コンピュータに挿入された機能拡張ボードやコンピュータに接続された機能拡張ユニットに備わるメモリに書き込まれた後、そのプログラムコードの指示に基づき、その機能拡張ボードや機能拡張ユニットに備わるCPUなどが実際の処理の一部または全部を行い、その処理によって前述した実施形態の機能が実現される場合も含まれることは言うまでもない。
【0102】
【発明の効果】
以上説明したように本発明によれば、ノイズの多い環境下でも矩形領域を高精度に検出することができる。
【図面の簡単な説明】
【図1】本発明に係る一実施形態における画像処理システムの概要構成を示すブロック図である。
【図2】本実施形態において検出対象となる2値画像例を示す図である。
【図3】本実施形態における黒画素数の水平方向ヒストグラム例を示す図である。
【図4】本実施形態におけるヒストグラム算出処理を示すフローチャートである。
【図5】本実施形態におけるヒストグラムの台形近似方法を示すフローチャートである。
【図6】本実施形態における矩形画像の検出座標例を示す図である。
【図7】本実施形態における4つの斜行モードを示す図である。
【図8】本実施形態における斜行モード判定の原理を説明するための図である。
【図9】第2実施形態において、複数枚の写真を配置した際のヒストグラムの様子を示す図である。
【図10】第3実施形態における黒ブロック探索方法を説明するための図である。
【図11】第3実施形態におけるラベリング処理の概要を示すフローチャートである。
【図12】第3実施形態における黒ブロック探索処理を示すフローチャートである。
【図13】第3実施形態における塗りつぶし処理を示すフローチャートである。
【図14】第3実施形態における連結線分塗りつぶし方法を説明するための図である。
【図15】第3実施形態における連結線分塗りつぶし処理を示すフローチャートである。
【図16】第3実施形態における連結線分下領域の塗りつぶし処理を示すフローチャートである。
【図17】第4実施形態における黒ブロック探索方法を説明するための図である。
【図18】第4実施形態における黒ブロック探索処理を示すフローチャートである。
【符号の説明】
101 CPU
102 キーボード
102a マウス
103 表示部
104 ROM
105 RAM
106 ハードディスク
107 フロッピーディスク
108 プリンタ
109 ネットワークI/F
110 イメージスキャナ[0001]
BACKGROUND OF THE INVENTION
The present invention relates to an image processing method and an image processing apparatus, and more particularly to an image processing method and an image processing apparatus that detect a rectangular image.
[0002]
[Prior art]
Conventionally, various algorithms for detecting and cutting out a rectangular area from an original image have been proposed. For example, Japanese Patent Application Laid-Open No. 8-237537 describes a technique for searching a rectangular region by first extracting a contour and searching for a portion where the contour forms a straight line.
[0003]
[Problems to be solved by the invention]
However, according to the conventional rectangular segmentation algorithm, it was difficult to detect a straight line portion of a rectangular outline and to detect a single rectangle by associating four straight lines in a noisy environment. . Therefore, it is difficult to perform accurate extraction, and the accuracy of the extraction result is not sufficient.
[0004]
SUMMARY An advantage of some aspects of the invention is that it provides an image processing method and an image processing apparatus capable of detecting a rectangular region with high accuracy even in a noisy environment.
[0005]
[Means for Solving the Problems]
As a technique for achieving the above object, the image processing method of the present invention includes the following steps.
[0006]
That is, an image processing method for detecting a rectangular area from an image, in which an original image is binarized, a histogram creating step for creating a histogram of the number of black pixels in the horizontal and vertical directions, and the histogram is approximated to a trapezoid A rectangular range detecting step for detecting an existing range of the rectangular area in the binary image, and an inclination direction detecting step for detecting an inclination direction of the rectangular area within the existing range, and the rectangular range In the detection step, assuming that the rectangular region is a rectangle, the shape of the histogram exhibits a trapezoid whose left and right hypotenuses are symmetrical. Compare the accuracy of linear approximation by regression analysis for the left and right hypotenuses, and there is little error In accordance with data obtained from one hypotenuse, the data of the other hypotenuse is modified.
[0007]
Furthermore, it has a labeling process for labeling the binary image, and the histogram creating process creates a histogram of the number of labeled pixels.
[0008]
DETAILED DESCRIPTION OF THE INVENTION
Hereinafter, an embodiment according to the present invention will be described in detail with reference to the drawings.
[0009]
<First Embodiment>
● System configuration
FIG. 1 is a block diagram showing a configuration of a computer system in which the present invention is executed. A
[0010]
[0011]
[0012]
● Rectangle image overview
FIG. 2 shows an example of an image taken from the
[0013]
The image shown in FIG. 2 is held on the
[0014]
● Histogram creation
FIG. 3 is a diagram showing a state of a histogram in which black pixels are counted in the horizontal direction when assuming an ideal state where noise does not exist in the binary image shown in FIG. The lower part shows an example of a histogram. According to the figure, it can be seen that the histogram has a substantially trapezoidal shape corresponding to the four vertices of the rectangle of the binary image. Note that since the actual binary image contains noise, the histogram will not be a complete trapezoid, but sufficient information can be obtained from the trapezoidal shape of this histogram to specify the position of the vertex in the horizontal direction. it can.
[0015]
FIG. 4 is a flowchart showing the histogram creation process shown in FIG. Hereinafter, an array for storing histogram data is denoted by hist ().
[0016]
First, in steps S401 and S402, the
[0017]
In step S404, the pixel buf (x, y) on the bitmap is compared with the value 255.If they are different, the process proceeds to step S406, but if they are equal, the process proceeds to step S405 and hist (x) is incremented by the
[0018]
In step S406, the variable y is incremented by 1 and then in step S407, y is compared with the height H of the bitmap. If y and H are different, the process returns to step S404. If they are equal, the process proceeds to step S408, where the variable x is incremented by 1, and x and the bitmap width W are compared in step S409. If x and W are different, the process returns to step S402, but if they are equal, the process ends.
[0019]
● Vertex detection processing
Through the above processing, a histogram array hist () obtained by counting black pixels is obtained. As shown in FIG. 3, this histogram has a trapezoid surrounded by the X axis and three straight lines. In the present embodiment, in this trapezoid, a position where the left side intersects the X axis is a, a position where the left side and the upper base intersect is b, a position where the right side and the upper base intersect is c, and a position where the right side intersects the X axis is d.
[0020]
Here, a method of obtaining the positions a and b by analyzing the left side of the trapezoid represented by the histogram will be described using the flowchart of FIG.
[0021]
First, in step S501, a peak point P at which hist (x) is maximum is detected. In the histogram shown in FIG. 3, there is a peak of height 800 at a position around X = 400. Next, in step S502, a point F that is half the height of the peak in the forward direction of the point P is detected. In the histogram shown in FIG. 3, a position around X = 100 corresponds to the point F. In step S503, a point F0 having a height of 1/4 of the peak in front of the point F is detected, and further in step S504, a point F1 having a height of 3/4 of the peak in the backward direction of the point F. Is detected.
[0022]
Next, in step S505, a straight line L as shown in FIG. 3 is obtained by performing a linear approximation using a well-known regression analysis for all points of F0 ≦ X ≦ F1. In step S506, a point where the straight line L intersects the X axis is calculated, and this point is obtained as a. In step S507, a point where the straight line L is 98% of the height of the peak P is calculated, and this point is obtained as b. This is because the peak P includes noise and is corrected to 98% in consideration of the fact that the peak P appears more than the actual peak.
As described above, the example of obtaining the points a and b by performing the forward search of the peak P has been described with reference to the flowchart illustrated in FIG. 5, but the points c and d are obtained by performing the backward search of the peak P in the same manner. Can be obtained.
[0023]
Further, the above is the explanation of the vertex position detection in the horizontal direction, but it is possible to detect the vertex position in the vertical direction by inverting the vertical axis and the horizontal axis in the above description and applying the same method. It is. As a result, as shown in FIG. 6, four coordinate values, that is, eight variables (ax, bx, cx, dx, ay, by, cy, dy) surrounding the rectangle can be obtained as vertex candidates. it can.
[0024]
Here, the above eight variables are uniquely determined from the rectangle, but conversely, the rectangle cannot be determined from the eight variables. That is, as shown in FIG. 7, as the rectangle based on the eight variables, four vertex coordinates can be considered depending on the skew direction (hereinafter referred to as skew mode), but it is not possible to determine which of them is. . In FIG. 7, a special case (not shown) where the rectangle is completely horizontal is set as
[0025]
● Skew mode judgment
Hereinafter, the skew mode determination processing in the present embodiment will be described in detail.
[0026]
FIG. 6 described above corresponds to the state of
[0027]
As shown in FIG. 8, when a
[0028]
Specifically, the number of black pixels when the four mode templates are applied to the rectangular image to be determined is counted, and the template with the smallest counting result is determined as the skew mode of the image. . That is, it is assumed that the case where the degree of entry into the template is the smallest is the skewing degree that the rectangular image is closest to. Of course, it is also possible to count the black pixels existing outside the template and determine the skew feeding mode based on the template having the maximum counting result.
[0029]
With the above processing, the four vertex coordinates of the rectangular area in the binary image can be specified. Therefore, based on this information, for example, a rectangular photographic image arranged on the
[0030]
As the known skew correction processing, it is desirable to use a simple interpolation method (nearest neighbor method) or a linear interpolation method (bilinear method), the former being excellent in speed and the latter being excellent in image quality. You can use them accordingly.
[0031]
As described above, according to the present embodiment, a rectangular region can be accurately detected even in a noisy environment.
[0032]
If the rectangular area is a perfect rectangle, the ideal histogram should exhibit an ideal trapezoid in which the left and right hypotenuses are symmetric, but the left and right hypotenuses are not symmetric due to the influence of noise. That is, the distance between ab shown in FIG. 3 may not be equal to the distance between cd. In such a case, trapezoidal approximation is performed in accordance with data obtained from the hypotenuse that is considered to be less affected by noise. Specifically, for the left and right hypotenuses, the accuracy of linear approximation by regression analysis (the square error between the straight line and the actual data) is compared, and the one with the smaller error may be adopted.
[0033]
Similarly, a rectangle connecting four vertices obtained as a result of rectangle detection may not necessarily be a rectangle due to the influence of noise, and adjacent sides may not be orthogonal. Even in such a case, the accuracy of rectangle detection can be improved by performing correction so that the rectangle becomes a rectangle based on data that is considered to be less influenced by noise.
[0034]
Second Embodiment
Hereinafter, a second embodiment according to the present invention will be described. The system configuration in the second embodiment is the same as that of the first embodiment described above, and a description thereof will be omitted.
[0035]
In the first embodiment described above, the case where one rectangular area exists in the image has been described. As such a situation, for example, scanning is performed with a single photo placed on the platen of the
[0036]
However, since the document table of a general flat head scanner can place a document of about A4 size, a plurality of general photographs (so-called L size) can be placed at a time. Therefore, if such a plurality of photographic images can be read by a single scan and only a rectangular area indicating the photographic image can be cut out from the obtained image, the efficiency of the scanning operation can be improved.
[0037]
Therefore, the second embodiment is characterized in that a plurality of rectangular images are detected from one image.
[0038]
Hereinafter, with reference to FIG. 9, the detection processing of the several rectangular image in 2nd Embodiment is demonstrated. The left part of FIG. 9 shows a binarized image when two photographs are arranged apart from each other in the sub-scanning direction (longitudinal direction in the figure) of the document table, and the right part of FIG. 9 shows the binarized image. The state of the histogram in the sub-scanning direction is shown. As can be seen from the figure, when a plurality of photographs are arranged apart from each other, a plurality of trapezoids appear in the histogram. Therefore, in the second embodiment, by referring to this histogram, the image is divided into two parts between these plural trapezoids, that is, at the position indicated by the one-dot chain line L in FIG. Then, a rectangular image can be detected in each segmented area by the method described in the first embodiment described above.
[0039]
In FIG. 9, the case where a plurality of photographs are arranged apart from each other in the sub-scanning direction has been described, but the case where they are arranged apart from each other in the main scanning direction (short direction in the figure) is also the main scanning direction. By creating a histogram for, the image can be cut in the main scanning direction and each rectangular image can be extracted.
[0040]
As described above, according to the second embodiment, a plurality of rectangular images can be detected from one image.
[0041]
<Third Embodiment>
The third embodiment according to the present invention will be described below. The system configuration in the third embodiment is the same as that in the first embodiment described above, and a description thereof will be omitted.
[0042]
The third embodiment is characterized in that an ideal labeling process is performed on a binary image as shown in FIG. 2 to eliminate the influence of noise and to detect a rectangular image with higher accuracy. .
[0043]
Here, the ideal labeling process in the binary image shown in FIG. 2 is based on the connection of black pixels, for example, by giving a pixel value of 1 to all the pixels included in the upper rectangular object, The
[0044]
● Outline of labeling process
Hereinafter, a labeling method for realizing the ideal labeling will be described in detail.
[0045]
FIG. 10 is a diagram for explaining a method of searching for a block corresponding to the upper left portion including the upper rectangular object in FIG. 2 and serving as a starting point of the painting process in the third embodiment.
[0046]
First, as shown in FIG. 10, the entire W pixel × H pixel bitmap shown in FIG. 2 is divided into blocks of w pixels × h pixels, and all of the blocks are occupied by black pixels having a value of 255 ( (Hereinafter referred to as “black block”) is searched in the direction of the arrow in the figure. The blocks indicated by black rectangles in FIG. 3 are found black blocks.
[0047]
In the third embodiment, high-speed labeling is realized by painting a region where a found black block and a black pixel are connected. FIG. 11 is a flowchart illustrating the entire labeling process according to the third embodiment.
[0048]
First, in step S1401, the
[0049]
Next, in step S1403, it is determined whether a black block is found. If found, the process proceeds to step S1404. If not found, the process ends.
[0050]
In step S1404, starting from the found black block, the black pixel connection region is filled with the label c. Details of the filling process will be described later.
[0051]
In step S1405, the variable c is incremented by 1. The process returns to step S1402, and the above processing is repeated.
[0052]
As a result of this processing, labels 1, 2,..., C can be given only to objects having a size larger than a predetermined size.
[0053]
● Black block search processing
Details of the black block search process shown in step S1402 of FIG. 11 will be described below with reference to the flowchart of FIG.
[0054]
First, in steps S1501 to S1504, variables y, x, j, and i are each initialized with a value of 0. In step S1505, it is determined whether buf (x + i, y + j) is 255 indicating a black pixel. If 255, the process proceeds to step S1506. If not 255, the process proceeds to step S1510.
[0055]
In step S1506, the variable i is incremented by a
[0056]
In step S1508, the variable j is incremented by a value of 1. If the j is equal to h indicating the block height in step S1509, the process ends.At this time, the w × h pixel block having (x, y) as the upper left starting point is determined. Detected as a black block. If j is different from h, the process returns to step S1504.
[0057]
In step S1510, w is added to x. If x is equal to or larger than W indicating the image width in step S1511, the process proceeds to step S1512. Otherwise, the process returns to step S1503.
[0058]
In step S1512, h is added to y. If y is equal to or greater than H indicating the image height in step S1513, the process is terminated, and at this time, it is determined that there is no black block. If y is less than H, the process returns to step S1502.
[0059]
Through the above processing, a black block of w pixels × h pixels is detected from the binary image of W pixels × H pixels.
[0060]
● Filling the connected area
The details of the connecting area filling process shown in step S1404 of FIG. 11 will be described with reference to the flowchart of FIG.
[0061]
Various methods are known as the object filling process, and any painting method may be used in the third embodiment. Accordingly, the basic method will be described here, and it is assumed that the object has a simple shape that is convex outward for the sake of simplicity.
[0062]
As a result of the black block search process described above, a block having (x, y) as the upper left starting point is detected as a black block as shown in FIG. Therefore, in the filling process of the third embodiment, the regions connected by the black pixels are labeled from the center point ((x + w) / 2, (y + h) / 2) of the black block. Fill with c. That is, the pixel value having the
[0063]
Specifically, first, in step S601, with respect to the scanning line including the center point ((x + w) / 2, (y + h) / 2) of the black block, the black connected portion on the scanning line is filled with the label c. That is, a line segment connecting the left end (x0, y + h / 2) and the right end (x1, y + h / 2) of the scanning line in the object including the black block shown in FIG. 14 (the object in the horizontal direction in FIG. 14). The line segment to be cut) is filled with label c. The line segment connecting the above (x0, y + h / 2) and (x1, y + h / 2) is hereinafter referred to as a connected line segment, and the details of the filling process will be described later.
[0064]
In step S602, the black connected portion below the connecting line segment is filled, and in step S603, the black connected portion above the connecting line segment is filled. Details of the painting process in steps S602 and S603 will be described later.
[0065]
As a result of this processing, the area connected by the black block and the black pixel can be filled with the label c.
[0066]
● Fill line processing
The details of the connecting line segment filling process shown in step S601 of FIG. 13 will be described with reference to the flowchart of FIG. For simplification of explanation, it is assumed that the center point ((x + w) / 2, (y + h) / 2) of the black block that is the starting point of processing is indicated by coordinates (X, Y). That is, X = (x + w) / 2 and Y = (y + h) / 2.
[0067]
First, X is substituted for variable i in step S801, and i is decremented by 1 in step S802. In step S803, it is determined whether buf (i, Y) is equal to the
[0068]
In step S804, the value i + 1 is stored in the variable x0, and in step S805, X is substituted for the variable i. In step S806, i is incremented by a
[0069]
In step S808, the value i-1 is stored in the variable x1, in step S809, the value x0 is substituted into the variable i, and in step S810, c is substituted into buf (i, Y). In step S811, i is incremented by 1 and if i is larger than x1 in step S812, the process ends. If not, the process returns to step S810.
[0070]
By this processing, the x coordinates at both ends of the connecting line segment can be stored in the variables x0 and x1, and the connecting line segment can be filled with the label c.
[0071]
● Filling processing from the connecting line to the bottom (upper)
The details of the process of painting the black connected portion below the connecting line segment shown in step S602 of FIG. 13 will be described with reference to the flowchart of FIG. Here, Y = y + h / 2 is also set, and therefore, the black connected portion below the connecting line segment connecting (x0, Y) and (x1, Y) is filled with the label c.
[0072]
First, the variable Y is incremented by 1 in step S901, and x0 is substituted for variable i in step S902. In step S903, it is determined whether buf (i, Y) is equal to the
[0073]
In step S904, i is incremented by a value of 1. If i is larger than x1 in step S905, the process ends. If not, the process returns to step S903.
[0074]
In step S906, i is substituted for X, and in step S907, (X, Y) is used as a starting point, and the connecting line segment on the scanning line is filled in the horizontal direction. Note that the painting process on the scanning line is shown in the flowchart of FIG. 15, and therefore detailed description thereof is omitted here.
[0075]
Note that the process for filling the black connected portion above the connecting line segment shown in step S603 in FIG. 13 is basically the same as the process for filling in the downward direction shown in the flowchart of FIG. In this case, instead of incrementing Y, it may be decremented, and the same processing may be performed for the other steps.
[0076]
According to the labeling process as described above, it is possible to label only an object including a black block having a predetermined size, that is, an object having an area larger than the predetermined size. Therefore, labeling is not performed on a minute noise region, and high-speed labeling is possible.
[0077]
● Rectangle detection after labeling
With the above labeling processing, in the two-dimensional array of buf () shown in FIG. 2, the
[0078]
In the third embodiment, the position (vertex coordinates) of the rectangular object is determined for each label area. That is, the rectangle detection processing described in the first and second embodiments described above is performed on the labeled image. Specifically, in the histogram creation flowchart shown in FIG. 4 described above, the comparison target of buf () shown in step S404 is changed from a
[0079]
Although the case where two rectangles are included has been described here as an example, the above labeling process can be performed on a binary image including an arbitrary number of rectangles, and the rectangle detection process can be performed for each label. Needless to say.
[0080]
As described above, according to the third embodiment, by performing an ideal labeling process on a binary image, it is possible to eliminate the influence of noise and detect a rectangular image with higher accuracy.
[0081]
<Fourth embodiment>
The fourth embodiment according to the present invention will be described below. The system configuration in the fourth embodiment is the same as that in the first embodiment described above, and a description thereof will be omitted.
[0082]
In the third embodiment described above, when searching for a black block from a binary image, the entire binary image is first divided into blocks, and then it is checked whether or not all the inside of each block is black pixels. However, other methods can be applied as the black block search method. For example, in the fourth embodiment, a method of continuously changing the upper left coordinate of a block in a binary image will be described. According to this method, although the calculation load increases, the black block detection performance can be improved.
[0083]
FIG. 17 is a diagram illustrating a state where a black block in a rectangular object is searched in the fourth embodiment. According to the figure, it can be seen that the search starting point (x, y) in the fourth embodiment is located away from the block boundary shown in FIG. 10 in the third embodiment.
[0084]
FIG. 18 shows a flowchart of black block search processing in the fourth embodiment, which will be described in detail.
[0085]
First, in steps S1101 to S1104, variables y, x, j, and i are each initialized with a value of 0. In step S1105, it is determined whether buf (x + i, y + j) is 255 indicating a black pixel. If 255, the process proceeds to step S1106. If not 255, the process proceeds to step S1110.
[0086]
In step S1106, the variable i is incremented by the
[0087]
In step S1108, the variable j is incremented by a
[0088]
In step S1110, i + 1 is added to x. Note that even if x is simply incremented by 1 here, the same result is finally obtained. However, by adding i + 1, search waste can be eliminated and the processing speed can be increased.
[0089]
If x is greater than or equal to W indicating the image width in step S1111, the process proceeds to step S1112, and if not, the process returns to step S1103.
[0090]
In step S1112, y is incremented by a
[0091]
Through the above processing, a black block of w pixels × h pixels is detected from the binary image of W pixels × H pixels. Thereafter, similarly to the third embodiment described above, it is possible to perform black pixel connection region filling and rectangle detection processing.
[0092]
As described above, according to the fourth embodiment, a black block of a predetermined size can be detected with higher accuracy. Therefore, labeling for only valid objects can be performed with higher accuracy, and as a result, rectangular detection with higher accuracy is possible.
[0093]
According to the third and fourth embodiments described above, the black block determination condition is that all the pixels in the block are black pixels. For example, depending on the state of noise, white pixels may be included in the black area. May be mixed. Therefore, in the present invention, for example, the number of black pixels in the block may be counted, and when this exceeds a predetermined threshold, it may be determined that the block is a black block.
[0094]
Further, the black block to be searched does not necessarily have to be a rectangle, and may be a polygon such as a hexagon, a circle or an ellipse, and can be selected according to the assumed shape of the object. May be.
[0095]
Also, the size of the search block is not limited to one predetermined size. For example, the search may be started from a large block size, and if no object is found, the size may be gradually reduced and the search may be repeated. As a result, it is possible to avoid a risk that a smaller object than assumed is mistaken for noise and ignored.
[0096]
[Other Embodiments]
Note that the present invention can be applied to a system including a plurality of devices (for example, a host computer, an interface device, a reader, and a printer), and a device (for example, a copying machine and a facsimile device) including a single device. You may apply to.
[0097]
Another object of the present invention is to supply a storage medium storing software program codes for realizing the functions of the above-described embodiments to a system or apparatus, and the computer (or CPU or MPU) of the system or apparatus stores the storage medium. Needless to say, this can also be achieved by reading and executing the program code stored in.
[0098]
In this case, the program code itself read from the storage medium realizes the functions of the above-described embodiment, and the storage medium storing the program code constitutes the present invention.
[0099]
As a storage medium for supplying the program code, for example, a floppy disk, a hard disk, an optical disk, a magneto-optical disk, a CD-ROM, a CD-R, a magnetic tape, a nonvolatile memory card, a ROM, or the like can be used.
[0100]
In addition, by executing the program code read by the computer, not only the functions of the above-described embodiments are realized, but also an OS (operating system) running on the computer based on the instruction of the program code. It goes without saying that a part of the actual processing is performed and the functions of the above-described embodiments are realized by the processing.
[0101]
Further, after the program code read from the storage medium is written to a memory provided in a function expansion board inserted into the computer or a function expansion unit connected to the computer, the function expansion is performed based on the instruction of the program code. It goes without saying that the CPU or the like provided in the board or the function expansion unit performs part or all of the actual processing, and the functions of the above-described embodiments are realized by the processing.
[0102]
【The invention's effect】
As described above, according to the present invention, a rectangular region can be detected with high accuracy even in a noisy environment.
[Brief description of the drawings]
FIG. 1 is a block diagram showing a schematic configuration of an image processing system according to an embodiment of the present invention.
FIG. 2 is a diagram illustrating an example of a binary image to be detected in the present embodiment.
FIG. 3 is a diagram illustrating an example of a horizontal histogram of the number of black pixels in the present embodiment.
FIG. 4 is a flowchart showing histogram calculation processing in the present embodiment.
FIG. 5 is a flowchart showing a method for approximating a trapezoid of a histogram in the present embodiment.
FIG. 6 is a diagram illustrating an example of detected coordinates of a rectangular image in the present embodiment.
FIG. 7 is a diagram showing four skew feeding modes in the present embodiment.
FIG. 8 is a diagram for explaining the principle of skew mode determination in the present embodiment;
FIG. 9 is a diagram showing a state of a histogram when a plurality of photographs are arranged in the second embodiment.
FIG. 10 is a diagram for explaining a black block search method according to the third embodiment;
FIG. 11 is a flowchart showing an outline of a labeling process in the third embodiment.
FIG. 12 is a flowchart showing black block search processing in the third embodiment.
FIG. 13 is a flowchart showing a painting process in the third embodiment.
FIG. 14 is a diagram for explaining a connecting line segment filling method according to the third embodiment;
FIG. 15 is a flowchart showing a connecting line segment filling process in the third embodiment;
FIG. 16 is a flowchart showing a process of filling a region below a connecting line segment in the third embodiment.
FIG. 17 is a diagram for explaining a black block search method according to the fourth embodiment;
FIG. 18 is a flowchart showing black block search processing in the fourth embodiment.
[Explanation of symbols]
101 CPU
102 keyboard
102a mouse
103 Display
104 ROM
105 RAM
106 hard disk
107 floppy disk
108 Printer
109 Network I / F
110 Image scanner
Claims (28)
原画像を2値化した画像において、その水平及び垂直方向の黒画素数のヒストグラムを作成するヒストグラム作成工程と、
該ヒストグラムを台形近似することによって、前記2値画像における矩形領域の存在範囲を検出する矩形範囲検出工程と、
前記存在範囲内における、前記矩形領域の傾き方向を検出する傾き方向検出工程とを有し、
前記矩形範囲検出工程においては、前記矩形領域が長方形であると仮定して、前記ヒストグラムの形状が、左右の斜辺が対称となる台形を呈するように、該左右の斜辺について回帰分析による直線近似の精度を比較して、誤差の少ない一方の斜辺から得られるデータに合わせて、他方の斜辺のデータを修正することを特徴とする画像処理方法。An image processing method for detecting a rectangular area from an image,
A histogram creating step of creating a histogram of the number of black pixels in the horizontal and vertical directions in an image obtained by binarizing an original image;
A rectangular range detecting step of detecting the existence range of the rectangular area in the binary image by approximating the histogram to a trapezoid;
An inclination direction detecting step for detecting an inclination direction of the rectangular area within the existence range;
In the rectangular range detection step, assuming that the rectangular area is a rectangle, the histogram is linearly approximated by regression analysis with respect to the left and right hypotenuses so that the left and right hypotenuses are symmetrical . An image processing method characterized by comparing the accuracy and correcting data of the other hypotenuse according to data obtained from one hypotenuse with a small error .
前記2値画像の水平及び垂直方向における前記ヒストグラムのそれぞれについて台形近似を行い、
前記2値画像の水平及び垂直方向のそれぞれついて、矩形領域の存在範囲を検出することを特徴とする請求項1記載の画像処理方法。In the rectangular range detection step,
Performing a trapezoidal approximation for each of the histograms in the horizontal and vertical directions of the binary image;
The image processing method according to claim 1, wherein an existence range of a rectangular area is detected for each of the binary image in a horizontal direction and a vertical direction.
前記矩形領域に対する複数の頂点座標候補に基づいて、該矩形領域の複数の傾き方向を仮定し、
該複数の傾き方向のそれぞれで示される矩形領域について、その外部に存在する黒画素数を計数し、
それぞれの計数結果に基づいて1つの傾き方向を特定することによって、前記4頂点の座標を特定することを特徴とする請求項5記載の画像処理方法。In the tilt direction detection step,
Based on a plurality of vertex coordinate candidates for the rectangular area, assuming a plurality of inclination directions of the rectangular area,
For the rectangular area indicated by each of the plurality of tilt directions, the number of black pixels existing outside the counter is counted,
6. The image processing method according to claim 5, wherein the coordinates of the four vertices are specified by specifying one inclination direction based on each counting result.
前記矩形領域に対する複数の頂点座標候補に基づいて、該矩形領域の複数の傾き方向を仮定し、
該複数の傾き方向のそれぞれで示される矩形領域について、その内部に存在する黒画素を計数し、
それぞれの計数結果に基づいて1つの傾き方向を特定することによって、前記4頂点の座標を特定することを特徴とする請求項5記載の画像処理方法。In the tilt direction detection step,
Based on a plurality of vertex coordinate candidates for the rectangular area, assuming a plurality of inclination directions of the rectangular area,
For the rectangular area indicated by each of the plurality of inclination directions, the black pixels existing inside the rectangular area are counted,
6. The image processing method according to claim 5, wherein the coordinates of the four vertices are specified by specifying one inclination direction based on each counting result.
前記ヒストグラム作成工程においては、前記2値画像を前記写真画像毎に主走査方向で分割し、該分割した2値画像毎に、前記ヒストグラムを作成することを特徴とする請求項13記載の画像処理方法。When the original image is an image in which a plurality of photographic images are arranged at positions separated in the main scanning direction,
14. The image processing according to claim 13, wherein in the histogram creation step, the binary image is divided in the main scanning direction for each photographic image, and the histogram is created for each of the divided binary images. Method.
前記ヒストグラム作成工程においては、前記2値画像を前記写真画像毎に副走査方向で分割し、該分割した2値画像毎に、前記ヒストグラムを作成することを特徴とする請求項13記載の画像処理方法。When the original image is an image in which a plurality of photographic images are arranged at positions separated in the sub-scanning direction,
14. The image processing according to claim 13, wherein, in the histogram creation step, the binary image is divided in the sub-scanning direction for each photographic image, and the histogram is created for each of the divided binary images. Method.
前記ヒストグラム作成工程においては、前記ラベル付けされた画素数のヒストグラムを作成することを特徴とする請求項1記載の画像処理方法。And a labeling step for labeling the binary image,
The image processing method according to claim 1, wherein in the histogram creating step, a histogram of the number of labeled pixels is created.
前記2値画像において、その内部における黒画素数が所定割合以上であるような所定サイズのブロックを、黒ブロックとして検出する黒ブロック検出工程と、
検出された黒ブロック内および該黒ブロックに連結している黒画素について、所定のラベル値で置き換えるラベル付け工程と、を有することを特徴とする請求項17記載の画像処理方法。The labeling process includes
In the binary image, a black block detecting step of detecting a block having a predetermined size such that the number of black pixels in the binary image is a predetermined ratio or more, as a black block;
18. The image processing method according to claim 17, further comprising a labeling step of replacing black pixels in the detected black block and black pixels connected to the black block with a predetermined label value.
前記2値画像全体を前記所定サイズのブロックに分割する分割工程と、
前記ブロックごとに黒ブロックであるか否かを判定する判定工程と、を有することを特徴とする請求項18記載の画像処理方法。The black block detection step includes
A dividing step of dividing the entire binary image into blocks of the predetermined size;
The image processing method according to claim 18, further comprising: a determination step of determining whether each block is a black block.
前記2値画像において前記所定サイズのブロック位置を順次ずらすことによって、黒ブロックを検出することを特徴とする請求項18記載の画像処理方法。In the black block detection step,
19. The image processing method according to claim 18, wherein black blocks are detected by sequentially shifting the block positions of the predetermined size in the binary image.
前記黒ブロック内の基準ラインを前記ラベル値で置き換える基準ラベル付け工程と、
前記前記基準ラインよりも上部に連結している黒画素を前記ラベル値で置き換える上部ラベル付け工程と、
前記前記基準ラインよりも下部に連結している黒画素を前記ラベル値で置き換える下部ラベル付け工程と、を有することを特徴とする請求項18記載の画像処理方法。The labeling step includes
A reference labeling step of replacing a reference line in the black block with the label value;
An upper labeling step of replacing black pixels connected above the reference line with the label value;
The image processing method according to claim 18, further comprising a lower labeling step of replacing a black pixel connected to a lower part than the reference line with the label value.
原画像を2値化した画像において、その水平及び垂直方向の黒画素数のヒストグラムを作成するヒストグラム作成手段と、
該ヒストグラムを台形近似することによって、前記2値画像における矩形領域の存在範囲を検出する矩形範囲検出手段と、
前記存在範囲内における、前記矩形領域の傾き方向を検出する傾き方向検出手段とを有し、
前記矩形範囲検出手段においては、前記矩形領域が長方形であると仮定して、前記ヒストグラムの形状が、左右の斜辺が対称となる台形を呈するように、該左右の斜辺について回帰分析による直線近似の精度を比較して、誤差の少ない一方の斜辺から得られるデータに合わせて、他方の斜辺のデータを修正することを特徴とする画像処理装置。An image processing apparatus for detecting a rectangular area from an image,
A histogram creating means for creating a histogram of the number of black pixels in the horizontal and vertical directions in an image obtained by binarizing an original image;
Rectangular range detection means for detecting the existence range of the rectangular area in the binary image by approximating the histogram to a trapezoid;
Inclination direction detecting means for detecting the inclination direction of the rectangular region within the existence range,
In the rectangular range detecting means, assuming that the rectangular area is a rectangle, the histogram is linearly approximated by regression analysis with respect to the left and right hypotenuses so that the left and right hypotenuses are symmetrical . An image processing apparatus characterized by comparing accuracy and correcting data on the other hypotenuse according to data obtained from one hypotenuse with a small error .
コンピュータが実行することによって、
原画像を2値化した画像において、その水平及び垂直方向の黒画素数のヒストグラムを作成するヒストグラム作成工程と、
該ヒストグラムを台形近似することによって、前記2値画像における矩形領域の存在範囲を検出する矩形範囲検出工程と、
前記存在範囲内における、前記矩形領域の傾き方向を検出する傾き方向検出工程とを実現し、
前記矩形範囲検出工程においては、前記矩形領域が長方形であると仮定して、前記ヒストグラムの形状が、左右の斜辺が対称となる台形を呈するように、該左右の斜辺について回帰分析による直線近似の精度を比較して、誤差の少ない一方の斜辺から得られるデータに合わせて、他方の斜辺のデータを修正することを特徴とするコンピュータが読取可能な画像処理プログラム。An image processing program for detecting a rectangular area from an image,
By running the computer
A histogram creating step of creating a histogram of the number of black pixels in the horizontal and vertical directions in an image obtained by binarizing an original image;
A rectangular range detecting step of detecting the existence range of the rectangular area in the binary image by approximating the histogram to a trapezoid;
An inclination direction detection step of detecting an inclination direction of the rectangular area within the existence range,
In the rectangular range detection step, assuming that the rectangular area is a rectangle, the histogram is linearly approximated by regression analysis with respect to the left and right hypotenuses so that the left and right hypotenuses are symmetrical . A computer-readable image processing program for comparing accuracy and correcting data on the other hypotenuse according to data obtained from one hypotenuse with a small error .
Priority Applications (3)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2002188353A JP3885001B2 (en) | 2002-06-27 | 2002-06-27 | Image processing method and image processing apparatus |
US10/375,195 US7321687B2 (en) | 2002-03-07 | 2003-02-28 | Apparatus and method for image processing to label an object in a binary image |
US11/843,481 US7567708B2 (en) | 2002-03-07 | 2007-08-22 | Apparatus and method for image processing |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
JP2002188353A JP3885001B2 (en) | 2002-06-27 | 2002-06-27 | Image processing method and image processing apparatus |
Publications (2)
Publication Number | Publication Date |
---|---|
JP2004030430A JP2004030430A (en) | 2004-01-29 |
JP3885001B2 true JP3885001B2 (en) | 2007-02-21 |
Family
ID=31183128
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
JP2002188353A Expired - Fee Related JP3885001B2 (en) | 2002-03-07 | 2002-06-27 | Image processing method and image processing apparatus |
Country Status (1)
Country | Link |
---|---|
JP (1) | JP3885001B2 (en) |
Families Citing this family (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP3690402B2 (en) * | 2003-03-28 | 2005-08-31 | セイコーエプソン株式会社 | Image processing system, projector, program, information storage medium, and image processing method |
JP4777024B2 (en) | 2005-09-06 | 2011-09-21 | キヤノン株式会社 | Image processing apparatus and image processing apparatus control method |
JP5132416B2 (en) | 2008-05-08 | 2013-01-30 | キヤノン株式会社 | Image processing apparatus and control method thereof |
-
2002
- 2002-06-27 JP JP2002188353A patent/JP3885001B2/en not_active Expired - Fee Related
Also Published As
Publication number | Publication date |
---|---|
JP2004030430A (en) | 2004-01-29 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US7567708B2 (en) | Apparatus and method for image processing | |
US9179035B2 (en) | Method of editing static digital combined images comprising images of multiple objects | |
JP3883696B2 (en) | Method for scanning and detecting multiple photos and removing artificial edges | |
US7831107B2 (en) | Image processing apparatus, image processing method, and program | |
US5892854A (en) | Automatic image registration using binary moments | |
JP5017031B2 (en) | Image processing apparatus, image processing method, image processing program, and storage medium | |
JP4502385B2 (en) | Image processing apparatus and control method thereof | |
US20140293383A1 (en) | Image-Processing Device Identifying Object in Image Specified by Encircling Line | |
JP4878209B2 (en) | Image processing apparatus, image processing method, and computer program | |
JP5049920B2 (en) | Image processing apparatus and image processing method | |
US9131193B2 (en) | Image-processing device removing encircling lines for identifying sub-regions of image | |
JP4310288B2 (en) | Image processing apparatus and method, program, and storage medium | |
JP5049922B2 (en) | Image processing apparatus and image processing method | |
US20110019911A1 (en) | Image processing method, image processing apparatus, and computer-readable medium | |
US8238686B2 (en) | Image processing apparatus, method and recording medium | |
KR101377910B1 (en) | Image processing method and image processing apparatus | |
JP3615333B2 (en) | Ruled line eraser | |
JP5335581B2 (en) | Image processing apparatus, image processing method, and program | |
KR101903617B1 (en) | Method for editing static digital combined images comprising images of multiple objects | |
JP3885001B2 (en) | Image processing method and image processing apparatus | |
JP4146047B2 (en) | Image tilt detection method and document image processing apparatus | |
JP7301529B2 (en) | Image processing device, image processing method, and program | |
JP3814547B2 (en) | Image processing apparatus and method | |
EP0975146A1 (en) | Locating the position and orientation of multiple objects with a smart platen | |
JP2004032537A (en) | Image processing method and image processing apparatus |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
A977 | Report on retrieval |
Free format text: JAPANESE INTERMEDIATE CODE: A971007 Effective date: 20060116 |
|
A131 | Notification of reasons for refusal |
Free format text: JAPANESE INTERMEDIATE CODE: A131 Effective date: 20060224 |
|
A521 | Written amendment |
Free format text: JAPANESE INTERMEDIATE CODE: A523 Effective date: 20060425 |
|
A131 | Notification of reasons for refusal |
Free format text: JAPANESE INTERMEDIATE CODE: A131 Effective date: 20060605 |
|
A521 | Written amendment |
Free format text: JAPANESE INTERMEDIATE CODE: A523 Effective date: 20060706 |
|
A02 | Decision of refusal |
Free format text: JAPANESE INTERMEDIATE CODE: A02 Effective date: 20060811 |
|
A521 | Written amendment |
Free format text: JAPANESE INTERMEDIATE CODE: A523 Effective date: 20061011 |
|
A911 | Transfer of reconsideration by examiner before appeal (zenchi) |
Free format text: JAPANESE INTERMEDIATE CODE: A911 Effective date: 20061019 |
|
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: 20061107 |
|
A61 | First payment of annual fees (during grant procedure) |
Free format text: JAPANESE INTERMEDIATE CODE: A61 Effective date: 20061120 |
|
R150 | Certificate of patent or registration of utility model |
Free format text: JAPANESE INTERMEDIATE CODE: R150 |
|
FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20101124 Year of fee payment: 4 |
|
FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20101124 Year of fee payment: 4 |
|
FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20111124 Year of fee payment: 5 |
|
FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20121124 Year of fee payment: 6 |
|
FPAY | Renewal fee payment (event date is renewal date of database) |
Free format text: PAYMENT UNTIL: 20131124 Year of fee payment: 7 |
|
LAPS | Cancellation because of no payment of annual fees |