JP2000339456A - Picture processing method - Google Patents

Picture processing method

Info

Publication number
JP2000339456A
JP2000339456A JP2000008783A JP2000008783A JP2000339456A JP 2000339456 A JP2000339456 A JP 2000339456A JP 2000008783 A JP2000008783 A JP 2000008783A JP 2000008783 A JP2000008783 A JP 2000008783A JP 2000339456 A JP2000339456 A JP 2000339456A
Authority
JP
Japan
Prior art keywords
pixel
label
labeling
stack
target pixel
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.)
Granted
Application number
JP2000008783A
Other languages
Japanese (ja)
Other versions
JP3840025B2 (en
Inventor
Yukinobu Tokieda
幸伸 時枝
Mamoru Kawamura
守 川村
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.)
Japan Radio Co Ltd
Original Assignee
Japan Radio 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 Japan Radio Co Ltd filed Critical Japan Radio Co Ltd
Priority to JP2000008783A priority Critical patent/JP3840025B2/en
Publication of JP2000339456A publication Critical patent/JP2000339456A/en
Application granted granted Critical
Publication of JP3840025B2 publication Critical patent/JP3840025B2/en
Anticipated expiration legal-status Critical
Expired - Fee Related legal-status Critical Current

Links

Abstract

PROBLEM TO BE SOLVED: To speed up the picture of a complicated form in the labeling processing of a binary picture. SOLUTION: A labeling processing part 10 scans the binary picture of a binary picture memory 20 and starts labeling at a new value (n) from a white pixel with the white pixel as start when the white pixel to which a label is not given is detected. When adjacent pixels are checked in order in a line direction from the start and the pixel is the white pixel to which the label is not given, the label (n) is given to the pixel. When the upper/lower adjacent pixels of the pixel are the white pixels to which the labels are not given, they are accumulated in a stack 12. When the labeling of the pixel connected to the start is terminated, the head pixel of the stack 12 is taken out and a same processing is repeated with the pixel as start. The processing is equivalent to the depth priority search algorithm of a multiple tree and the white pixels connected to the white pixel which is detected at first are detected without omission and they can be labeled.

Description

【発明の詳細な説明】DETAILED DESCRIPTION OF THE INVENTION

【0001】[0001]

【発明の属する技術分野】本発明は画像処理方法に関
し、特に画像のラベリング処理に関する。
The present invention relates to an image processing method, and more particularly to an image labeling process.

【0002】[0002]

【従来の技術】画像処理の重要な分野として、画像に基
づく対象物認識がある。画像からの対象物認識では、画
像から所望の対象物の部分を切り出し、この対象物部分
の画像としての特徴量を求め、この特徴量から認識を行
う。この画像からの対象部分の切出しには、一般に画像
の2値化及びラベリングの技術が利用されることが多
い。
2. Description of the Related Art An important field of image processing is image recognition based on images. In recognition of an object from an image, a portion of a desired object is cut out from the image, a feature amount of the object portion as an image is obtained, and recognition is performed from the feature amount. In general, a technique of binarizing and labeling an image is often used to cut out a target portion from the image.

【0003】2値化は、濃淡画像の各画素の画素値をし
きい値と比較し、しきい値より大きいか小さいかで各画
素を分類する処理である。しきい値を適切に選んで2値
化を行うことにより、対象となる部分を抽出できる。ラ
ベリングは、2値化画像において、連結成分、すなわち
注目する画素値(白又は黒のいずれか)を有し互いに連
結した画素群、を抽出し、各連結成分にそれぞれ識別の
ためのラベルを付与する処理である。ラベリングには、
自画素の上下左右の隣接4画素との連結性を考慮する場
合(4連結性)と、さらに斜め方向の隣接4画素を加え
た周囲8画素との連結性を考慮する場合(8連結性)と
が一般に知られている。このラベリング処理により、2
値化画像中の注目画素値を有する各画素を、互いに連結
した画素の塊(連結成分)に分けることができる。この
ように求めた各連結成分が認識の対象となり、各連結成
分毎にその特徴量が求められる。
[0003] Binarization is a process in which the pixel value of each pixel of a grayscale image is compared with a threshold value and each pixel is classified according to whether it is larger or smaller than the threshold value. By appropriately selecting a threshold value and performing binarization, a target portion can be extracted. Labeling extracts a connected component, that is, a group of pixels having a pixel value of interest (either white or black) and connected to each other in a binarized image, and assigns a label for identification to each connected component. This is the processing to be performed. For labeling,
A case where the connectivity between the upper and lower neighboring pixels of the own pixel is considered (four connectivity), and a case where the connectivity with surrounding eight pixels which is obtained by adding four neighboring pixels in the oblique direction is considered (eight connectivity). And are generally known. By this labeling process, 2
Each pixel having the pixel value of interest in the valued image can be divided into a block (connected component) of connected pixels. Each connected component obtained in this way is to be recognized, and the feature amount is obtained for each connected component.

【0004】例えば、監視カメラの画像から侵入者を検
知するシステムとして、現在の画像とその直前の画像と
の差分画像を求め、その差分画像を2値化・ラベリング
して各連結成分を求め、それら各連結成分の面積や重心
から侵入者の有無を判定するものが知られている。
For example, as a system for detecting an intruder from a surveillance camera image, a difference image between a current image and an image immediately before the current image is obtained, and the difference image is binarized and labeled to obtain each connected component. It is known that the presence or absence of an intruder is determined from the area and the center of gravity of each connected component.

【0005】従来の一般的なラベリング処理として次の
ような手順が知られている。この手順では、まず画像の
左上隅から右下隅に向かってラスタ走査により各画像を
調べ、注目画素値を有する画素に仮のラベルを付与し、
この走査が終わると、今度は逆に右下隅から左上隅にラ
スタ走査を行って仮ラベルを調整する。そして、更に右
上隅から左下隅に向かってラスタ走査を行うことによ
り、仮ラベルの再調整をする。
The following procedure is known as a conventional general labeling process. In this procedure, first, each image is examined by raster scanning from the upper left corner to the lower right corner of the image, and a temporary label is assigned to the pixel having the pixel value of interest.
After this scanning is completed, the raster label is scanned from the lower right corner to the upper left corner to adjust the temporary label. Then, the temporary label is readjusted by further performing raster scanning from the upper right corner to the lower left corner.

【0006】例えば4連結性により連結を判断する場
合、上記手順の最初のラスタ走査では、注目画素値を持
つ画素を検出すると、その画素をラベリング対象とし、
その画素の上及び左の隣接画素と同じラベルを仮ラベル
を付与する。上及び左の隣接画素のどちらにもラベルが
付されていない場合は、ラベルリング対象の画素には新
たなラベルを付与する。次の右下隅から左上隅へのラス
タ走査では、仮ラベルを付与した画素を検出すると、そ
の画素のラベルを下及び右の隣接画素のラベルに合わせ
る。下及び右の隣接画素のどちらにもラベルが付されて
いない場合は、元の仮ラベルをそのまま最終的なラベル
とする。そして、最後の右上隅から左下隅への走査で
は、仮ラベルを付与した画素を検出すると、その画素の
ラベルを上及び右の隣接画素のラベルに合わせるように
調整する。
[0006] For example, in the case of judging the connection by the four connectivity, in the first raster scan of the above procedure, when a pixel having a target pixel value is detected, the pixel is set as a labeling object,
A temporary label is assigned to the same label as the adjacent pixel above and to the left of the pixel. When neither the upper nor the left adjacent pixel is labeled, a new label is assigned to the pixel to be labeled. In the next raster scan from the lower right corner to the upper left corner, when a pixel to which a temporary label is added is detected, the label of that pixel is matched with the labels of the lower and right adjacent pixels. If neither the lower nor the right adjacent pixel is labeled, the original temporary label is used as the final label. Then, in the last scan from the upper right corner to the lower left corner, when a pixel to which a temporary label is added is detected, the label of the pixel is adjusted to match the label of the upper and right adjacent pixels.

【0007】最初の走査では、同じ連結成分に属する画
素に一般に異なる仮ラベルが付されるが、中盤及び最後
の走査により、連結成分が比較的単純な形状ならば、同
じ連結成分に属する画素はすべて同じラベルを持つよう
になる。
In the first scan, pixels belonging to the same connected component are generally given different temporary labels. However, if the connected component has a relatively simple shape by the middle scan and the last scan, the pixel belonging to the same connected component will be replaced by a different one. They all have the same label.

【0008】[0008]

【発明が解決しようとする課題】しかしながら、上記従
来処理は、連結成分の形状が複雑になると正しいラベリ
ングができない可能性がある。例えば、図20に示した
ような多数の枝分かれを含む複雑な形状の連結成分10
0は、上記従来処理では同じラベルを付与することがで
きない。このような複雑な形状についても正しいラベリ
ングを行おうとすると、更に走査の方向を増やすなどの
対応が必要となり、処理時間が長くなってしまう。
However, in the above-described conventional processing, correct labeling may not be performed if the shape of the connected component becomes complicated. For example, as shown in FIG. 20, a connected component 10 having a complex shape including a large number of branches.
0 indicates that the same label cannot be assigned in the above-described conventional processing. If correct labeling is performed on such a complicated shape, it is necessary to take measures such as further increasing the scanning direction, and the processing time becomes longer.

【0009】また、上記従来のラベリング処理は、仮ラ
ベルを順次調整していくことで、最終的に1つの連結成
分に属する画素に同一のラベルを与えるようにするもの
なので、全画面についてラベルの調整が完了した段階で
は、各連結成分(例えば白画素の塊)に与えられたラベ
ルが飛び飛びの値になる可能性が高い。このため、連結
成分の総数が知りたければ、ラベルを連番に直す処理が
必要となり、そのための処理時間が必要となる。
In the conventional labeling process, the same label is finally assigned to pixels belonging to one connected component by sequentially adjusting the temporary labels. At the stage where the adjustment is completed, the label given to each connected component (for example, a cluster of white pixels) is likely to have discrete values. For this reason, if it is desired to know the total number of connected components, it is necessary to perform a process of changing the label to a serial number, which requires a processing time.

【0010】また、上記従来のラベリング処理では、す
べてのラスタ走査が完了するまで各画素の最終的なラベ
ルが決定されない。このため、ラベリングの後に行う連
結成分の面積や重心などの特徴量は、後半の走査が完了
するまで行うことができなかった。したがって、上記従
来のラベリング処理は、高速な対象物認識を要求される
応用分野には不向きであった。
In the conventional labeling process, the final label of each pixel is not determined until all raster scans have been completed. For this reason, the feature amount such as the area and the center of gravity of the connected component performed after the labeling cannot be performed until the latter half of the scan is completed. Therefore, the above-described conventional labeling process is not suitable for application fields that require high-speed object recognition.

【0011】本発明はこのような問題点を解決するため
になされたものであり、複雑な形状の画像も比較的高速
にラベリング処理できる方法を提供することを目的とす
る。また、本発明の更なる目的は、ラベリング処理にお
ける連結成分の特徴量を高速に求めることができる方法
を提供することである。
The present invention has been made to solve such a problem, and an object of the present invention is to provide a method capable of relatively quickly processing an image having a complicated shape. It is a further object of the present invention to provide a method capable of quickly obtaining the characteristic amount of a connected component in a labeling process.

【0012】[0012]

【課題を解決するための手段】第1の発明に係る画像処
理方法では、画像を所定の走査順序で調べ、ラベル未付
与でかつ注目画素値を有するというラベル条件を満足す
る画素を検出し、ラベル付け始点画素に定める始点検出
ステップと、ラベル付け始点画素及びこれに連結性を有
する画素にラベルを付与するラベル付与ステップとを繰
り返すことにより、画像内の注目画素値を持つ画素の各
連結成分にラベリングを行う。ここで、ラベル付与ステ
ップでは、ラベル付け始点画素をライン始点とするステ
ップ(a)と、ライン始点を最初の対象画素とし、対象
画素を右及び左のうち所定の一方向に順次1画素ずつ移
動させながら、対象画素が前記ラベル条件を満足する場
合はその対象画素に前記ラベルを付与すると共に、その
対象画素の上下の隣接画素が前記ラベル条件を満足する
場合その隣接画素をスタックに追加するステップ(b)
と、このステップ(b)にて対象画素が前記ラベル条件
を満足しなくなるか又は画像端部に達すると、ラベル付
け始点画素から前記ステップ(b)とは逆方向に順次対
象画素を1画素ずつ移動させながら、対象画素が前記ラ
ベル条件を満足する場合はその対象画素に前記ラベルを
付与すると共に、その対象画素の上下の隣接画素が前記
ラベル条件を満足する場合その隣接画素を前記スタック
に追加するステップ(c)と、このステップ(c)にて
対象画素が前記ラベル条件を満足しなくなるか又は画像
端部に達すると、前記スタックの先頭の画素を取り出し
て新たなライン始点として前記ステップ(b)及び
(c)を実行するステップ(d)と、前記スタックから
画素がなくなるまで上記ステップ(d)を繰り返すステ
ップ(e)とを含む。
In an image processing method according to a first aspect of the present invention, an image is examined in a predetermined scanning order, and a pixel that satisfies a label condition that a label is unassigned and has a target pixel value is detected. Each connected component of a pixel having a pixel value of interest in the image by repeating a start point detecting step to determine a labeling start pixel and a labeling step of labeling a labeling start pixel and a pixel having connectivity thereto. Perform labeling. Here, in the labeling step, a step (a) in which the labeling start pixel is set as the line start point, and the line start point is set as the first target pixel, and the target pixel is sequentially moved one pixel at a time in one of right and left directions. And adding the label to the target pixel if the target pixel satisfies the label condition, and adding the adjacent pixel to the stack if adjacent pixels above and below the target pixel satisfy the label condition. (B)
In step (b), when the target pixel no longer satisfies the label condition or reaches the end of the image, the target pixel is sequentially shifted one pixel at a time from the labeling start pixel in the direction opposite to the step (b). While moving, if the target pixel satisfies the label condition, the label is assigned to the target pixel, and if adjacent pixels above and below the target pixel satisfy the label condition, the adjacent pixel is added to the stack. (C) and when the target pixel no longer satisfies the label condition or reaches the end of the image in this step (c), the top pixel of the stack is taken out and set as a new line start point in the step (c). Steps (d) for performing b) and (c), and steps (e) for repeating the above step (d) until there are no more pixels from the stack.

【0013】この方法では、画像のライン方向に順次画
素の連結性を調べてラベリングを行い、この際にラベリ
ングした画素と連結した隣接ラインの画素をスタックに
登録し、そのラインの連結成分のラベリングが完了する
と、次にスタックから画素を取り出してその画素を始点
として同じ手順を繰り返す。このようにライン上を一画
素ずつ連結性を調べると共に、その画素の上下(すなわ
ち隣接ライン)の連結性を持つ画素をもれなく調べ、ラ
ベリング開始点の候補としてスタックするので、注目画
素値を有する画素の塊(連結成分)に属する画素をもれ
なく検出し、同一ラベルでラベリングすることができ
る。したがって、多数の分岐を含む複雑な形状の連結成
分でも正確にラベリングすることができる。また、この
方法によれば、1つの連結成分ごとに順にラベリングを
行っていくことになるので、画像全体のラベリングが終
了した段階では、各連結成分のラベルは必ず連番にな
る。
In this method, labeling is performed by sequentially examining the connectivity of pixels in the line direction of an image, and at this time, pixels of adjacent lines connected to the labeled pixels are registered in a stack, and labeling of connected components of the line is performed. Is completed, the pixel is then taken out of the stack and the same procedure is repeated starting from that pixel. As described above, the connectivity on the line is examined one pixel at a time, and pixels having connectivity on the upper and lower sides of the pixel (that is, adjacent lines) are completely examined and stacked as candidates for the labeling start point. Pixels belonging to the block (connected component) can be completely detected and labeled with the same label. Therefore, even a connected component having a complicated shape including many branches can be accurately labeled. In addition, according to this method, labeling is performed sequentially for each connected component, so that when the labeling of the entire image is completed, the labels of the connected components are always serial numbers.

【0014】第2の発明では、ラベル付与ステップは、
ラベル付け始点画素をライン始点とするステップ(a)
と、ライン始点を最初の対象画素とし、対象画素が前記
ラベル条件を満足しなくなるか又は画像端部に達するま
で、対象画素を右及び左のうち所定の一方向に順次1画
素ずつ移動させながらその都度対象画素及びその上下の
隣接画素を調べ、隣接画素が前記ラベル条件を満足する
場合はその隣接画素をスタックに追加し、対象画素が前
記ラベル条件を満足する場合はその対象画素に前記ラベ
ルを付与するステップ(b)と、ステップ(b)にて対
象画素が前記ラベル条件を満足しなくなるか又は画像端
部に達すると、対象画素が前記ラベル条件を満足しなく
なるか又は画像端部に達するまで、ラベル付け始点画素
から前記ステップ(b)とは逆方向に順次対象画素を1
画素ずつ移動させその都度対象画素その上下の隣接画素
を調べ、隣接画素が前記ラベル条件を満足する場合その
隣接画素を前記スタックに追加し、対象画素が前記ラベ
ル条件を満足する場合はその対象画素に前記ラベルを付
与するステップ(c)と、ステップ(c)にて対象画素
が前記ラベル条件を満足しなくなるか又は画像端部に達
すると、前記スタックの先頭の画素を取り出して新たな
ライン始点として前記ステップ(b)及び(c)を実行
するステップ(d)と、前記スタックから画素がなくな
るまで上記ステップ(d)を繰り返すステップ(e)
と、を含み、画像の全画素について走査が終わるまで前
記始点検出ステップ及びラベル付与ステップを繰り返
す。
[0014] In the second invention, the labeling step includes:
Step (a) of setting a labeling start pixel as a line start point
With the line start point as the first target pixel, while moving the target pixel one pixel at a time in one of the right and left directions until the target pixel no longer satisfies the label condition or reaches the end of the image. Each time, the target pixel and its upper and lower neighboring pixels are examined, and if the neighboring pixel satisfies the label condition, the neighboring pixel is added to the stack.If the target pixel satisfies the label condition, the label is added to the target pixel. When the target pixel does not satisfy the label condition or reaches the edge of the image in step (b) and step (b), the target pixel no longer satisfies the label condition or reaches the edge of the image. Until the target pixel is reached, the target pixel is sequentially incremented by 1 in the direction opposite to the step (b) from the labeling start pixel.
Each time the pixel is moved, the target pixel is examined above and below adjacent pixels.If the adjacent pixel satisfies the label condition, the adjacent pixel is added to the stack.If the target pixel satisfies the label condition, the target pixel is added. And (c) when the target pixel no longer satisfies the label condition or reaches the end of the image in step (c). (D) performing steps (b) and (c) as described above, and (e) repeating step (d) until there are no more pixels from the stack.
And repeating the start point detecting step and the label assigning step until scanning is completed for all the pixels of the image.

【0015】この方法では、走査の対象画素の隣接画素
スタックする際に、その対象画素がラベル付けされるか
否かによらず、隣接画素がラベル条件を満足するか否か
のみでスタックするか否かを判断するようにした。これ
により、8連結における斜め方向の連結の場合も正しく
スタックすることができるので、8連結成分のラベリン
グ処理を実現することができる。また、この方法は、上
記第1の発明に係る方法とほぼ同じ計算量で、8近傍ラ
ベリングを実現することができる。
In this method, when the adjacent pixels of the scanning target pixel are stacked, whether or not the adjacent pixel satisfies the label condition is determined regardless of whether the target pixel is labeled. Judgment was made. Thereby, the stacking can be correctly performed even in the case of the diagonal connection in the 8-connection, so that the labeling processing of the 8-connected component can be realized. Also, this method can realize 8-neighbor labeling with almost the same calculation amount as the method according to the first invention.

【0016】本発明の好適な各態様では、ラベリングと
並行してラベリングした画素の数や座標を集計すること
により、同一ラベルの画素連結成分の面積や重心などの
特徴量を計算することができ、高速な特徴量計算が可能
になる。
In each of the preferred embodiments of the present invention, by counting the number and coordinates of the pixels labeled in parallel with the labeling, it is possible to calculate the characteristic amount such as the area and the center of gravity of the pixel connected component of the same label. , High-speed feature amount calculation becomes possible.

【0017】また、本発明の好適な態様では、スタック
から取り出した画素がラベル未付与か否かを判定し(前
記ラベル条件の判定)、ラベル付与済みである場合の回
数をカウントすることにより、注目画素値の連結成分中
の穴(注目画素値以外の画素の領域)の数を求めること
ができる。
In a preferred aspect of the present invention, it is determined whether or not a pixel taken out of the stack is unlabeled (determination of the label condition), and the number of times when the label has been labeled is counted. The number of holes (regions of pixels other than the pixel value of interest) in the connected component of the pixel value of interest can be obtained.

【0018】また本発明に係る方法は、画像を所定の走
査順序で調べ、ラベル未付与でかつ注目画素値を有する
というラベル条件を満足する画素を検出し、ラベル付け
始点画素に定める始点検出ステップと、ラベル付け始点
画素及びこれに連結性を有する画素にラベルを付与する
ラベル付与ステップと、を含み、前記ラベル付与ステッ
プは、ラベル付け始点画素をライン始点とする開始ステ
ップと、前記ライン始点を含むライン上の画素を1画素
ずつ走査し、前記ライン始点に対して連結性を有し前記
ラベル条件を満足する画素を見つける毎に前記ラベルを
付与すると共に、その走査ラインの上下の隣接ラインに
おいて、その走査ラインの画素に対して前記ラベル条件
を満足する画素を連結候補画素として所定の記憶手段に
記憶するライン走査ステップと、前記ライン走査ステッ
プにおいて前記走査ライン上でのラベル付け処理が完了
すると、前記記憶手段から連結候補画素を1つ取り出
し、これを新たなライン始点として前記ライン走査ステ
ップを反復する走査反復ステップとを含む。
Further, the method according to the present invention examines an image in a predetermined scanning order, detects a pixel which satisfies a label condition that a label is unassigned and has a pixel value of interest, and detects a starting point to be determined as a labeling starting pixel. And, a labeling starting pixel and a labeling step of giving a label to a pixel having connectivity thereto, including a labeling step, the labeling step is a starting step with a labeling starting pixel as a line starting point, and the line starting point The pixels on the included line are scanned one pixel at a time, and the label is added each time a pixel that has connectivity to the line start point and satisfies the label condition is added. A line scan for storing, in a predetermined storage means, a pixel satisfying the label condition with respect to a pixel of the scan line as a connection candidate pixel. And when the labeling process on the scanning line is completed in the line scanning step, a scanning repetition step of retrieving one connected candidate pixel from the storage means and repeating the line scanning step using this as a new line start point. And

【0019】この方法でも、走査対象のラインの隣接ラ
インにおけるラベル条件を満足する画素をスタックに追
加し、ライン走査が終わった後そのスタックから次のラ
インの走査開始点を取り出してラベリングのためのライ
ン走査を行う。このような処理により、複雑な図形でも
1回の走査で(すなわち従来技術のように仮ラベルの付
け直しのための走査を何度も繰り返すことなく)、高速
にラベリングを行うことができる。
In this method as well, pixels satisfying the label condition in a line adjacent to the line to be scanned are added to the stack, and after the line scanning is completed, the scanning start point of the next line is extracted from the stack and used for labeling. Perform line scanning. By such processing, even a complicated figure can be labeled at a high speed by one scan (that is, without repeating the scan for re-assigning the temporary label as in the related art).

【0020】[0020]

【発明の実施の形態】以下、本発明の実施の形態(以下
実施形態という)について、図面に基づいて説明する。
Embodiments of the present invention (hereinafter referred to as embodiments) will be described below with reference to the drawings.

【0021】<実施形態1> [装置構成]図1は、本発明に係る画像処理装置の概略
構成を示す機能ブロック図である。本実施形態では、2
値画像用メモリ20に記憶された2値画像に対し、ラベ
リング処理部10によりラベリング処理を行い、その結
果をラベル付画像用メモリ30に書き込んでいく。ラベ
リング処理部10は、ラベリングのための制御情報記憶
手段としてスタック12を用いる。このスタック12
は、後入れ先出し(LIFO)方式のデータ構造であ
る。本実施形態では、2値画像において1ラインずつラ
ベリングを進めていくが、このスタック12にはそのラ
インのラベリングの際に求めた次のラインのラベリング
処理の始点画素の座標情報を登録する。このスタック1
2の詳細な利用法については、後の処理手順の説明にて
詳細に述べる。また、ラベリング処理部10は、ラベリ
ング処理と平行して、面積カウンタ14、Xカウンタ1
6及びYカウンタ18を用いて、ラベリングした各連結
成分(すなわち注目する画素値を持つ互いに連結した画
素の塊)の面積や重心を計算する。
<First Embodiment> [Apparatus Configuration] FIG. 1 is a functional block diagram showing a schematic configuration of an image processing apparatus according to the present invention. In the present embodiment, 2
Labeling processing is performed on the binary image stored in the value image memory 20 by the labeling processing unit 10, and the result is written in the labeled image memory 30. The labeling processing unit 10 uses the stack 12 as control information storage means for labeling. This stack 12
Is a last-in first-out (LIFO) data structure. In the present embodiment, the labeling is performed line by line in the binary image. In the stack 12, the coordinate information of the starting pixel of the labeling process of the next line obtained at the time of labeling the line is registered. This stack 1
The detailed usage of 2 will be described in detail later in the description of the processing procedure. In parallel with the labeling processing, the labeling processing unit 10 executes the area counter 14 and the X counter 1
6 and the Y counter 18 are used to calculate the area and centroid of each labeled connected component (i.e., a cluster of connected pixels having the pixel value of interest).

【0022】[全体処理手順]次に図2を参照して、本
実施形態の画像処理装置の全体処理手順を説明する。以
下の処理は、ラベリング処理部10によって行われる。
[Overall Processing Procedure] Next, the overall processing procedure of the image processing apparatus of the present embodiment will be described with reference to FIG. The following processing is performed by the labeling processing unit 10.

【0023】本実施形態のラベリング処理において、ま
ずラベリング処理部10は、付与すべきラベルの値nを
0に初期化する(ステップS10)。本実施形態では、
ラベルとして続き番号を用いている。
In the labeling process of this embodiment, first, the labeling processing unit 10 initializes the value n of the label to be added to 0 (step S10). In this embodiment,
The serial numbers are used as labels.

【0024】ラベル値nを初期化すると、ラベリングす
べき注目画素値の画素の塊を見つけるための画像走査を
行う。以下では、2値画像を構成する白黒の2値のう
ち、「白」を注目する画素値とし、白画素の塊をラベリ
ングするものとする。
When the label value n is initialized, image scanning is performed to find a block of pixels of the target pixel value to be labeled. In the following, it is assumed that “white” is a pixel value of interest and a block of white pixels is labeled from among the black and white binary values forming the binary image.

【0025】本実施形態では、この走査は、画像の左上
隅から右下隅に向かって、ラスタ走査順序に従って行
う。この走査のため、まずラベリング処理部10は、鉛
直座標yの値を0に初期化する(ステップS12)。こ
の鉛直座標yは、走査対象の画像ラインに対し、上から
順に付けた番号である。本実施形態では、図8に示すよ
うに、画像の座標系として、水平方向右向きに水平座標
x、鉛直方向下向きに鉛直座標yをとり、画像の左端の
カラム(列)のx座標を0、上端のライン(行)のy座
標を0としている。鉛直座標yを初期化すると、以降ス
テップS14からS26までの処理ループで、鉛直方向
についての走査が制御される。ステップS16では、水
平方向の走査のために、水平座標xが0に初期化され
る。そして、ステップS18からS24までの処理ルー
プで、水平方向についての走査が制御される。このよう
な走査に従って、2値画像用メモリ20に格納された2
値画像の各画素がラスタ走査順序で調べられる。
In this embodiment, this scanning is performed in the raster scanning order from the upper left corner to the lower right corner of the image. For this scanning, first, the labeling processing unit 10 initializes the value of the vertical coordinate y to 0 (Step S12). The vertical coordinate y is a number sequentially assigned from the top to the image line to be scanned. In the present embodiment, as shown in FIG. 8, as a coordinate system of an image, a horizontal coordinate x is set rightward in the horizontal direction, a vertical coordinate y is set downward in the vertical direction, and the x coordinate of the leftmost column (column) of the image is set to 0, The y coordinate of the top line (line) is set to 0. When the vertical coordinate y is initialized, scanning in the vertical direction is controlled in the processing loop from step S14 to S26. In step S16, the horizontal coordinate x is initialized to 0 for horizontal scanning. Scanning in the horizontal direction is controlled in the processing loop from steps S18 to S24. According to such scanning, the 2D image data stored in the binary image memory 20 is stored.
Each pixel of the value image is examined in raster scanning order.

【0026】ステップS20では、走査において調査対
象に選んだ点(x,y)がラベル未付与の白画素である
か否かを判定する。図では肯定判定をTRUE(真)、
否定判定をFALSE(偽)と表している。この判定結
果が肯定(TRUE)の場合、ラベルnの値を1だけイ
ンクリメントし(ステップS22)、この点(x,y)
を起点とする白画素の塊(連結成分)に対し値nのラベ
ルを付与する処理(ステップS100)を実行する。こ
のステップS100の処理については、後に図3を参照
して詳しく説明する。そして、ステップS24にて水平
座標xの値を1インクリメントすることにより調査対象
を右に1つ移動し、ステップS18に戻る。一方、ステ
ップS20の判定結果が否定(FALSE)の場合は、
何も行わずにステップS24に進み、調査対象の画素を
右に1つ移動してステップS18に戻る。
In step S20, it is determined whether or not the point (x, y) selected as a survey target in the scan is an unlabeled white pixel. In the figure, the affirmative determination is TRUE (true),
A negative determination is indicated as FALSE (false). If the determination result is affirmative (TRUE), the value of the label n is incremented by 1 (step S22), and this point (x, y)
Is performed (step S100) to assign a label of a value n to a cluster of white pixels (connected component) starting from. The processing in step S100 will be described later in detail with reference to FIG. Then, in step S24, the value of the horizontal coordinate x is incremented by one, thereby moving the investigation target one position to the right and returning to step S18. On the other hand, when the determination result of step S20 is negative (FALSE),
The process proceeds to step S24 without performing any operation, moves the target pixel by one to the right, and returns to step S18.

【0027】このようにして処理を進め、ステップS1
8で調査対象の画素が画像の右端を超えたことが分かる
と、ステップS26で鉛直座標yを1だけインクリメン
トし、ステップS14に戻り、次のラインについてステ
ップS16からS24の処理を繰り返す。そして、ステ
ップS14で調査対象のラインが画像の下端を超えたこ
とを検知すると、一連のラベリング処理が完了したこと
になる。
The process proceeds as described above, and step S1
If it is determined in step 8 that the pixel to be examined has exceeded the right end of the image, the vertical coordinate y is incremented by 1 in step S26, the process returns to step S14, and the processes in steps S16 to S24 are repeated for the next line. Then, when it is detected in step S14 that the line to be investigated has exceeded the lower end of the image, a series of labeling processes has been completed.

【0028】以上の処理手順によれば、画像左上隅から
右下隅に向かうラスタ走査順序に従い各画素が調べら
れ、ラベル未付与の白画素が検出されると、その画素を
起点とした連結成分のラベル付け処理(ステップS10
0)が行われることになる。ステップS100により1
つの連結成分についてのラベル付けが終わると、ラスタ
走査順序に従い、ラベル未付与の連結成分の起点となる
白画素の探索が行われる。
According to the above-described processing procedure, each pixel is examined in the raster scanning order from the upper left corner to the lower right corner of the image, and when a white pixel without a label is detected, the connected component of the pixel is determined as a starting point. Labeling process (step S10
0) will be performed. 1 in step S100
After labeling of one connected component is completed, a search for a white pixel serving as a starting point of the unlabeled connected component is performed in the raster scanning order.

【0029】以上の手順から分かるように、ステップS
20で見つけられるラベル未付与の白画素は、1つの白
画素の連結成分(塊)の中の最上ラインの左端の画素で
ある。この画素を始点として、1つの連結成分をラベリ
ングするためのサブルーチン、すなわちステップS10
0の処理が実行される。次に、このステップS100の
処理手順を説明する。
As can be seen from the above procedure, step S
The unlabeled white pixel found at 20 is the leftmost pixel of the top line in the connected component (cluster) of one white pixel. With this pixel as a starting point, a subroutine for labeling one connected component, ie, step S10
0 is executed. Next, the processing procedure of step S100 will be described.

【0030】[連結成分のラベリング]図3に、ステッ
プS100の詳細な処理手順を示す。この手順では、ま
ず準備として、図2に示したメインルーチンから、ステ
ップS20で検出された連結成分の始点の座標(xi,
yi)、及びステップS22で求められたラベル値nを
取得する(S102)。例えば、最初に見つけられた始
点(xi,yi)のラベル値nは、ステップS22によれ
ば1となる。以下の手順では、この始点の画素に連結す
る白画素が順次検出され、ラベルnが付与されていく。
[Labeling of Connected Components] FIG. 3 shows a detailed processing procedure of step S100. In this procedure, as a preparation, first, the coordinates (xi, xi, i) of the starting point of the connected component detected in step S20 from the main routine shown in FIG.
yi) and the label value n obtained in step S22 are acquired (S102). For example, the label value n of the start point (xi, yi) found first becomes 1 according to step S22. In the following procedure, white pixels connected to the pixel at the start point are sequentially detected, and labels n are added.

【0031】このため、まず始点の座標(xi,yi)を
制御用のスタック12(図1参照)に追加する(ステッ
プS104)。本実施形態ではラベリング処理と並行し
て白画素の連結成分の面積や重心の計算を行うが、その
ために用いる面積カウンタ14(面積S)、Xカウンタ
16(Gx)、Yカウンタ18(Gy)の初期化をステ
ップS106で行う。そして、以降、そのスタックに画
素座標のデータがエントリされている間、ステップS1
08からS114の処理ループが繰り返される。
For this purpose, first, the coordinates (xi, yi) of the starting point are added to the control stack 12 (see FIG. 1) (step S104). In the present embodiment, the area and the center of gravity of the connected component of the white pixel are calculated in parallel with the labeling process, and the area counter 14 (area S), the X counter 16 (Gx), and the Y counter 18 (Gy) used for the calculation are used. Initialization is performed in step S106. Thereafter, while the pixel coordinate data is being entered in the stack, step S1 is executed.
The processing loop from 08 to S114 is repeated.

【0032】この処理ループでは、まずスタック12の
先頭のエントリ(すなわち最後に積まれた画素座標)を
取り出し、これを走査開始座標(x0,y0)にセットす
る(ステップS110)。そして、ステップS112で
点(x0,y0)がラベル未付与の注目画素値(この場合
は「白」)の画素かを判定する。なお、図及び以下の説
明では、表現の簡素化のため、点(x,y)の画素がラ
ベル未付与の注目画素値の画素であるかどうかの条件判
断をK(x,y)と表記する。点(x,y)がラベル未
付与の注目画素値の画素である場合には、この結果はT
RUE(真)、そうでない場合にはFALSE(偽)と
なる。
In this processing loop, first, the top entry (that is, the last stacked pixel coordinate) of the stack 12 is fetched and set as the scanning start coordinate (x0, y0) (step S110). Then, in step S112, it is determined whether or not the point (x0, y0) is a pixel having the unlabeled target pixel value (in this case, "white"). In the drawings and the following description, for the sake of simplicity of expression, the condition determination as to whether or not the pixel at the point (x, y) is the pixel of the target pixel value with no label is denoted as K (x, y). I do. If the point (x, y) is the pixel of the unlabeled target pixel value, the result is T
RUE (true), otherwise FALSE (false).

【0033】ステップS112の処理結果がTRUEの
場合は、走査開始座標(x0,y0)を始点として、ライ
ン方向に画素を走査してラベリングを実行していく(ス
テップS200)。このステップS200によれば、走
査開始座標(x0,y0)の画素が属する画像ラインのう
ちその画素に連結性を有する各画素にラベルnが付与さ
れるとともに、そのラインの上下の隣接ラインの走査開
始座標の候補となるものが求められ、それがスタック1
2に追加されることになる。またこのとき、白画素の塊
の面積や重心を求めるためのカウンタ14、16及び1
8のカウントアップも行われる。なお、このステップS
200の詳細な処理手順は後に詳しく説明する。ステッ
プS200の処理が完了すると、ステップS108に戻
り、スタック12から最新に追加されたエントリを取り
出して以上の処理を繰り返す。
If the processing result of step S112 is TRUE, the pixels are scanned in the line direction starting from the scanning start coordinates (x0, y0) to perform labeling (step S200). According to this step S200, the label n is assigned to each pixel having connectivity to the pixel of the image line to which the pixel at the scanning start coordinates (x0, y0) belongs, and the adjacent lines above and below the line are scanned. A candidate for the starting coordinates is obtained, and the stack 1
2 will be added. At this time, the counters 14, 16 and 1 for obtaining the area and the center of gravity of the cluster of white pixels are used.
A count-up of 8 is also performed. This step S
The detailed processing procedure of 200 will be described later in detail. Upon completion of the process in the step S200, the process returns to the step S108, the latest added entry is taken out from the stack 12, and the above process is repeated.

【0034】さて、ステップS112の処理結果がFA
LSEになるのは、スタック12に積まれた座標の画素
が、スタック12から取り出される(ステップS10
8)前にラベル付けされてしまっている場合である。後
に具体例を挙げて説明するが、簡単に言えば、連結した
白画素の塊の中に穴(黒画素)がある場合、このような
ことが起こる。この場合、その座標の属するラインにつ
いてはラベリングが終わっているので、何もせずにステ
ップS108に戻る。
Now, if the processing result of step S112 is FA
The reason for the LSE is that the pixel at the coordinates stacked on the stack 12 is extracted from the stack 12 (step S10).
8) This is the case where the label has been attached before. As will be described later with reference to a specific example, in simple terms, this occurs when there is a hole (black pixel) in a connected mass of white pixels. In this case, since the labeling of the line to which the coordinates belong has been completed, the process returns to step S108 without doing anything.

【0035】このような処理を繰り返した結果スタック
12のエントリがすべてなくなると、始点(xi,yi)
から始まる白画素の連結成分に属する全画素についてラ
ベルnの付与が完了したことになる。
When all entries of the stack 12 are exhausted as a result of repeating such processing, the starting point (xi, yi)
Means that label n has been assigned to all pixels belonging to the connected component of white pixels starting from.

【0036】このときの面積カウンタ14(S)のカウ
ント値がその連結成分の面積Sであり、Xカウンタ16
及びYカウンタ18のカウント値をその面積Sで除した
値が、それぞれその連結成分の重心のx座標(Gx)及
びy座標(Gy)となる。本実施形態では、ステップS
114で、ラベリングした連結成分の重心座標(Gx、
Gy)を計算し、これを連結成分の面積Sの値と共に、
所定の記憶手段に格納する(ステップS116)。
The count value of the area counter 14 (S) at this time is the area S of the connected component, and the X counter 16
And the value obtained by dividing the count value of the Y counter 18 by the area S thereof becomes the x coordinate (Gx) and the y coordinate (Gy) of the center of gravity of the connected component. In the present embodiment, step S
At 114, the barycentric coordinates (Gx,
Gy) is calculated, and is calculated together with the value of the area S of the connected component.
It is stored in a predetermined storage means (step S116).

【0037】以上の処理が完了すると、ステップS10
0の処理が終わり、制御が図2のメインルーチンに戻さ
れて、次の白画素の塊(連結成分)の開始座標が探索さ
れる。
When the above processing is completed, step S10
After the processing of 0 is completed, the control is returned to the main routine of FIG. 2, and the starting coordinates of the next block of white pixels (connected component) are searched.

【0038】[ライン走査]次に、ステップS200の
ライン走査処理の詳細な処理手順を説明する。この処理
は、図4に示すように、ステップS110でスタック1
2から取り出された走査開始座標(x0,y0)の画素か
ら、当該ラインを右方向に走査して連結画素のラベリン
グを行っていく処理(ステップS210:右方向処理)
と、その画素から当該ラインを左方向に走査して連結画
素をラベリングする処理(ステップS250:左方向処
理)を含んでいる。以下、それら各処理の内容を説明す
る。
[Line Scanning] Next, a detailed processing procedure of the line scanning process in step S200 will be described. In this process, as shown in FIG.
Processing for scanning the line to the right from the pixel at the scanning start coordinates (x0, y0) extracted from Step 2 to label connected pixels (Step S210: rightward processing)
And a process of scanning the line from the pixel to the left and labeling the connected pixel (step S250: leftward processing). Hereinafter, the contents of each of these processes will be described.

【0039】右方向処理(ステップS210)の詳細手
順を図5に示す。この処理では、まず2つのフラグF1
及びF2の値をFALSEに初期化(リセット)する
(ステップS212)。これらのフラグは、ステップS
300の隣接ラインの開始点をスタック12に登録する
処理において用いるものであり、その機能についてはス
テップS300の処理の説明の際に詳しく述べる。
FIG. 5 shows the detailed procedure of the rightward processing (step S210). In this process, first, two flags F1
And the value of F2 is initialized (reset) to FALSE (step S212). These flags are set in step S
This function is used in the process of registering the start point of the adjacent line of 300 in the stack 12, and its function will be described in detail in the description of the process of step S300.

【0040】次にステップS214で、水平座標xに走
査開始座標のx座標値x0をセットする。以降、ステッ
プS216でxが2値画像の幅以上になった(すなわち
画像の右端に達した)ことが検知されるまで、ステップ
S224で水平座標xを1ずつインクリメントしなが
ら、ステップS216からS224の処理ループを繰り
返す。
Next, in step S214, the x coordinate value x0 of the scanning start coordinate is set to the horizontal coordinate x. Thereafter, the horizontal coordinate x is incremented by one in step S224 until it is detected in step S216 that x has become greater than or equal to the width of the binary image (that is, the right end of the image has been reached). Repeat the processing loop.

【0041】この処理ループでは、点(x,y0)がラ
ベル未付与の注目画素値の画素か否かを判定し(K
(x,y0))(ステップS218)、この結果がTR
UEの場合は、点(x,y0)の画素に値nのラベルが
付与される(ステップS220)。
In this processing loop, it is determined whether or not the point (x, y0) is the pixel of the target pixel value to which no label is added (K
(X, y0)) (step S218), and the result is TR
In the case of the UE, a label with a value n is assigned to the pixel at the point (x, y0) (step S220).

【0042】この処理ループに進入した最初の時点で
は、x=x0なので、ステップS220では、スタック
12から取り出された走査開始座標(x0,y0)の画素
について条件判定K(x,y)が適用されることになる
が、この画素はステップS112でTRUE判定を受け
たものと同じものなので、ここでの処理結果もTRUE
となり、走査開始座標の画素にラベルnが付与されるこ
とになる。以降、この処理ループでは、検査対象となる
画素の座標が、ライン上を順次右方向に1画素ずつシフ
トされ(ステップS224)、その検査対象画素がラベ
ル未付与の白画素かがステップS218で検査される。
ステップS218の結果がFALSEになるとこの処理
ループを抜けるので、逆に言えばこの処理ループが繰り
返されている間は、検査対象の画素は、走査開始座標の
画素に対し、ライン上でラベルnの画素のみを介してつ
ながっていることになる。したがって、ステップS21
8の結果がTRUE(すなわち検査対象画素がラベル未
付与かつ白画素)の場合は、その検査対象画素は走査開
始座標の画素に対して連結性を有していることが保証さ
れるので、その検査対象画素に対してラベルnを付与し
てよいことになる。
Since x = x0 at the first time when the processing loop is entered, the condition judgment K (x, y) is applied to the pixel at the scanning start coordinates (x0, y0) extracted from the stack 12 in step S220. However, since this pixel is the same as the one that has been determined to be TRUE in step S112, the processing result here is also TRUE.
The label n is assigned to the pixel at the scanning start coordinate. Thereafter, in this processing loop, the coordinates of the pixel to be inspected are sequentially shifted to the right on the line one pixel at a time (step S224), and whether the pixel to be inspected is an unlabeled white pixel is inspected in step S218. Is done.
If the result of step S218 is FALSE, the process exits this processing loop. Conversely, while this processing loop is being repeated, the pixel to be inspected is compared with the pixel at the scanning start coordinate by the label n with the label n on the line. The connection is established only through the pixels. Therefore, step S21
If the result of step 8 is TRUE (that is, the pixel to be inspected is unlabeled and a white pixel), it is assured that the pixel to be inspected has connectivity to the pixel at the scanning start coordinate. The label n may be assigned to the inspection target pixel.

【0043】ステップS102においてセットされたラ
ベル付けの始点(xi,yi)の属するラインについて、
そのライン上でその始点に連結性を有する画素に、その
始点と同じラベルnを付与されることは以上の説明から
理解されよう。その他のラインについては、スタック1
2に積まれた座標の画素から処理が開始されるが、その
開始画素は、後で説明するスタック12への座標追加処
理(ステップS300)の方法から、隣接ラインのラベ
ルnを付与済みの画素に連結性を有していることが保証
される。したがって、その開始画素及び同一ライン上の
連結性を有する画素には、やはりラベルnを付与してよ
いことになり、実際、ステップS108にてスタック1
2から開始画素を取り出した後、図5の処理ループ(ス
テップS216からS224)の実行により、それら各
画素にラベルnが付与されることになる。
For the line to which the labeling start point (xi, yi) set in step S102 belongs,
It will be understood from the above description that a pixel having connectivity to the start point on the line is given the same label n as the start point. Stack 1 for other lines
The process is started from the pixel of the coordinates stacked on the stack 2, and the start pixel is a pixel to which the label n of the adjacent line has been added by the method of the process of adding coordinates to the stack 12 (step S <b> 300) described later. Is guaranteed to have connectivity. Accordingly, the start pixel and the pixel having the connectivity on the same line may also be given the label n.
After extracting the start pixel from 2, the execution of the processing loop of FIG. 5 (steps S216 to S224) results in the label n being assigned to each of those pixels.

【0044】さて、ステップS220で検査対象の画素
(x,y0)にラベル付けをすると、これと並行して、
白画素の連結成分の面積を求めるため面積カウンタ14
(S)のカウント値を1だけインクリメントすると共
に、その連結成分の重心を求めるためにラベル付けした
画素の水平座標xと鉛直座標y0を、Xカウンタ16
(Gx)とYカウンタ18(Gy)のカウント値にそれ
ぞれ加える(ステップS222)。
Now, in step S220, the pixel (x, y0) to be inspected is labeled, and in parallel with this,
Area counter 14 for determining the area of the connected component of the white pixel
The count value of (S) is incremented by one, and the horizontal coordinate x and the vertical coordinate y0 of the pixel labeled for obtaining the center of gravity of the connected component are calculated by the X counter 16.
(Gx) and the count value of the Y counter 18 (Gy), respectively (step S222).

【0045】そしてこの後、隣接ラインの走査開始点を
スタック12に登録するための処理を行う(ステップS
300)。
Thereafter, processing for registering the scanning start point of the adjacent line in the stack 12 is performed (step S).
300).

【0046】図6を参照して、このステップS300の
処理手順を説明する。この処理では、検査対象の画素
(x,y0)の上下の隣接画素が隣接ラインの走査開始
点に適するか否かを判断し、適する場合にはその隣接画
素の座標をスタック12に追加する。この処理におい
て、ステップS302からS310までは上の隣接画素
に関する処理であり、ステップS312からS320ま
でが下の隣接画素に関する処理である。これら両者はい
ずれを先に行ってもよい。
Referring to FIG. 6, the processing procedure of step S300 will be described. In this process, it is determined whether adjacent pixels above and below the inspection target pixel (x, y0) are suitable for the scanning start point of the adjacent line, and if so, the coordinates of the adjacent pixels are added to the stack 12. In this process, steps S302 to S310 are processes related to the upper adjacent pixel, and steps S312 to S320 are processes related to the lower adjacent pixel. Either of these may be performed first.

【0047】図示の順に説明すると、まずステップS3
02では、検査対象の画素(x,y0)の上の隣接画素
(x,y0−1)について判定K(x,y)を適用し、
その隣接画素がラベル未付与の白画素か否かを判定す
る。この判定結果がTRUEの場合、その隣接画素は検
査対象画素に連結性を有していることになる。ここで検
査対象画素自体にはラベルnが付与されているので、そ
の隣接画素が検査対象画素に連結性を有していれば、そ
の隣接画素もラベルnを付与されるべき画素であるとい
える。本実施形態では、基本的に、そのようなラベルn
を付与すべき隣接画素を、隣接ラインの走査開始点とし
てスタック12に登録する。
The operation will be described in the order shown in FIG.
In 02, the judgment K (x, y) is applied to the adjacent pixel (x, y0-1) above the inspection target pixel (x, y0),
It is determined whether or not the adjacent pixel is an unlabeled white pixel. If the result of this determination is TRUE, the adjacent pixel has connectivity to the inspection target pixel. Here, since the label to be inspected itself is given the label n, if the adjacent pixel has connectivity to the pixel to be inspected, it can be said that the adjacent pixel is also a pixel to be given the label n. . In the present embodiment, basically, such a label n
Is registered in the stack 12 as the scanning start point of the adjacent line.

【0048】ただし、そのような隣接画素すべてをスタ
ック12に登録したのではスタックのサイズが大きくな
り、またスタック12からの画素取り出し処理の負荷が
増えるので、本実施形態ではこれを避けるため、スタッ
ク12に登録する画素を絞り込んでいる。前述のフラグ
F1及びF2はこの絞り込みのために用いている。F1
は上隣の隣接画素用、F2は下隣の隣接画素用である。
However, if all such adjacent pixels are registered in the stack 12, the size of the stack becomes large, and the load of the process of taking out pixels from the stack 12 increases. 12, pixels to be registered are narrowed down. The aforementioned flags F1 and F2 are used for this narrowing down. F1
Is for an upper adjacent pixel, and F2 is for a lower adjacent pixel.

【0049】ステップS302で検査対象画素の上の隣
接画素がラベル未付与の白画素と分かった場合、フラグ
F1の現在値がFALSEであるか否かを判定する(ス
テップS304)。そして、F1がFALSEの場合に
のみ、その隣接画素の座標(x,y0−1)をスタック
12に追加する(ステップS306)。そして、F1の
値をTRUEにセットする(ステップS308)。
If it is determined in step S302 that the adjacent pixel above the pixel to be inspected is a white pixel with no label, it is determined whether the current value of the flag F1 is FALSE (step S304). Only when F1 is FALSE, the coordinates (x, y0-1) of the adjacent pixel are added to the stack 12 (step S306). Then, the value of F1 is set to TRUE (step S308).

【0050】前述のステップS212でフラグF1はF
ALSEに初期化されているので、ライン走査処理(ス
テップS200)の中で最初にこのステップ304を通
過する際には、F1は必ずFALSEである。したがっ
て、そのラインの走査開始画素(x0,y0)の上の隣接
画素がラベル未付与の白画素であれば、その隣接画素は
必ずスタック12に登録される。こうして、いったん上
の隣接画素がスタック12に登録されると、ステップS
308でフラグF1がTRUEにセットされ、F1がT
RUEである間は、上の隣接画素(x,y0−1)は、
ラベル未付与の白画素であってもステップS304の判
定により、スタック12に登録されないことになる。し
たがって、例えば最初に走査開始画素(x0,y0)の上
の隣接画素をスタック12に登録した後、その上の隣接
画素から同一ライン上を右方向に白画素が連続している
場合でも、それら白画素はスタック12に登録されな
い。フラグF1がTRUEからFALSEにリセットさ
れるのは、ステップS302で上隣接画素(x,y0−
1)がラベル未付与の白画素でない(すなわち黒画素か
又はラベル付与済みの画素)と判定された場合である
(ステップS310)。F1がFALSEにリセットさ
れた後、再びラベル未付与の白画素である隣接画素
(x,y0−1)が見つかると(ステップS302)、
その隣接画素はスタック12に追加される(ステップS
306)。
At step S212, the flag F1 is set to F
Since it has been initialized to ALSE, F1 is always FALSE when first passing this step 304 in the line scanning process (step S200). Therefore, if the adjacent pixel above the scan start pixel (x0, y0) of the line is a white pixel without label, the adjacent pixel is always registered in the stack 12. Thus, once the upper adjacent pixel is registered in the stack 12, step S
At 308, the flag F1 is set to TRUE and F1 is set to T
While RUE, the upper neighboring pixel (x, y0-1) is
Even a white pixel with no label is not registered in the stack 12 by the determination in step S304. Therefore, for example, after first registering the adjacent pixel on the scanning start pixel (x0, y0) in the stack 12, even if white pixels continue rightward on the same line from the adjacent pixel on top, the White pixels are not registered in the stack 12. The reason that the flag F1 is reset from TRUE to FALSE is that the upper adjacent pixel (x, y0−
1) is a case where it is determined that the pixel is not an unlabeled white pixel (that is, a black pixel or a labeled pixel) (step S310). After F1 is reset to FALSE, when an adjacent pixel (x, y0-1), which is a white pixel without labeling, is found again (step S302).
The adjacent pixel is added to the stack 12 (step S
306).

【0051】以上、検査対象画素の上の隣接画素につい
てのスタック処理を説明したが、下の隣接画素もこれと
全く同様スタック処理される。すなわち、まずステップ
S312で下の隣接画素(x,y0+1)がラベル未付
与の白画素かが判定され、この判定結果がTRUEの場
合、ステップS314でフラグF2がFALSEか否か
が更に判定され、F2がFALSEである場合にのみ、
その画素(x,y0+1)がスタック12に登録される
(ステップS316)。そして、スタック12への登録
がなされると、ステップS318でフラグF2はTRU
Eにセットされる。いったんTRUEにセットされたフ
ラグF2は、走査が進んでステップS312で下の隣接
画素(x,y0+1)がラベル未付与の白画素でなくな
ると、FALSEにリセットされる(ステップS32
0)。
The stacking process for the adjacent pixel above the inspection target pixel has been described above, but the stacking process for the lower adjacent pixel is performed in exactly the same manner. That is, first, in step S312, it is determined whether the lower adjacent pixel (x, y0 + 1) is an unlabeled white pixel. If the determination result is TRUE, it is further determined in step S314 whether the flag F2 is FALSE. Only if F2 is FALSE,
The pixel (x, y0 + 1) is registered in the stack 12 (Step S316). When registration in the stack 12 is performed, the flag F2 is set to TRU in step S318.
Set to E. The flag F2 once set to TRUE is reset to FALSE when scanning proceeds and the lower adjacent pixel (x, y0 + 1) is no longer a white pixel with no label in step S312 (step S32).
0).

【0052】以上、図6を参照してスタック12への画
素座標の登録処理について説明した。図6には示さなか
ったが、ステップS302やS312で検査対象画素の
上隣や下隣の画素を参照する際、誤って2値画像の外の
値を読み込まないようにするためのエラー回避処理を行
っていることは言うまでもない。
The registration processing of the pixel coordinates in the stack 12 has been described with reference to FIG. Although not shown in FIG. 6, an error avoidance process for preventing a value outside the binary image from being erroneously read when referring to the pixel on the upper or lower side of the inspection target pixel in step S302 or S312. Needless to say that we are doing.

【0053】このようにして、検査対象画素(x,y
0)の上下の隣接画素についてのスタック処理が完了す
ると、ステップS224で検査対象画素の水平座標xを
1だけインクリメントし、検査対象画素を1つ右にずら
してステップS216からS224の処理を繰り返す。
このようにして、検査対象画素が2値画像の左端を超え
てしまったり(ステップS216)、検査対象画素がラ
ベルnを付すべき画素でなくなったり(ステップS21
8の結果がFALSE)すると、右方向処理(ステップ
S210)が完了し、左方向処理(ステップS250)
に移る。
In this way, the inspection target pixel (x, y
When the stacking process for the upper and lower adjacent pixels in (0) is completed, the horizontal coordinate x of the inspection target pixel is incremented by 1 in step S224, and the inspection target pixel is shifted right by one, and the processing of steps S216 to S224 is repeated.
In this way, the inspection target pixel exceeds the left end of the binary image (step S216), or the inspection target pixel is no longer a pixel to which the label n should be added (step S21).
If the result of step 8 is FALSE, the rightward processing (step S210) is completed and the leftward processing (step S250)
Move on to

【0054】左方向処理(ステップS250)は、図7
に示す手順に従って行われる。この処理は、走査開始座
標(x0,y0)の左隣の画素から処理を開始し、当該ラ
イン上を左方向に走査していくことを除けば、前述の右
方向処理と全く同じ内容の処理を行う。
The leftward processing (step S250) is the same as that shown in FIG.
Is performed according to the procedure shown in FIG. This processing is exactly the same as the above-described rightward processing except that the processing is started from the pixel on the left of the scanning start coordinate (x0, y0) and the line is scanned leftward. I do.

【0055】この処理では、まずステップS252で、
フラグF1をK(x0,y0−1)の判定結果に、F2を
K(x0,y0+1)の判定結果に、それぞれ初期化す
る。ここでは、走査開始座標(x0,y0)の上隣及び下
隣の画素に合わせてフラグを初期化しているわけであ
る。次にステップS254で水平座標xがx0−1に初
期化されることにより、走査開始座標の左隣の画素が最
初の検査対象画素に選ばれることになる。以降、ステッ
プS256にて水平座標xが0より小さくなったことが
検出されるまで、ステップS264にて順次水平座標が
1ずつデクリメントされ、これにより検査対象画素を1
つずつ左方向にずらしながら、右方向処理の場合と同様
のラベル付け及びスタック処理(ステップS218〜S
300)が行われる。
In this process, first, in step S252,
The flag F1 is initialized to the determination result of K (x0, y0-1), and the flag F2 is initialized to the determination result of K (x0, y0 + 1). Here, the flag is initialized in accordance with the pixels on the upper and lower sides of the scanning start coordinates (x0, y0). Next, in step S254, the horizontal coordinate x is initialized to x0-1 so that the pixel on the left of the scan start coordinate is selected as the first inspection target pixel. Thereafter, until it is detected in step S256 that the horizontal coordinate x has become smaller than 0, the horizontal coordinate is sequentially decremented by 1 in step S264.
The labeling and stacking process (steps S218 to S218) is performed in the same manner as in the case of the rightward processing, while shifting to the left one by one.
300) is performed.

【0056】このようにして左方向処理(ステップS2
50)が完了すると、1ラインについてのラベリング処
理(ステップS200)が完了し、図3の処理の流れに
戻ってスタック12から次の走査開始座標を取り出し
て、同じ処理を繰り返す。
The leftward processing (step S2)
When step 50) is completed, the labeling process for one line (step S200) is completed, and the process returns to the flow of FIG. 3 to retrieve the next scan start coordinate from the stack 12 and repeat the same process.

【0057】以上、本実施形態のラベリング処理部10
の処理手順を説明した。以上の手順では、点(x,y)
上の画素がラベル未付与かつ注目画素値か、という条件
判定K(x,y)を各所で行ったが、この処理は、ラベ
ル付画像用メモリ30に対して次のような初期化処理を
実行することにより簡略化できる。この初期化処理で
は、2値画像用メモリ20から各画素の値を読み出し、
その画素が注目画素値であるか否かに応じて、それぞれ
異なる仮ラベルを与えてラベル付画像用メモリ30に書
き込む。この際に用いる仮ラベルには、最終的なラベリ
ングには使用しない値(例えば自然数の連番でラベリン
グする場合は、0や−1など)を用いる。好適な例とし
ては、注目画素値の画素には“−1”の仮ラベル、注目
画素値でない画素には“0”の仮ラベルを与える。この
ようにすれば、図2のステップS20、図3のステップ
S112、図5のステップS218などにおけるK
(x,y)の条件判定が、結局その点(x,y)のラベ
ル値が“−1”であるか否かの判定になる。すなわち、
点(x,y)が“−1”であれば、ラベル未付与かつ注
目画素値であるからである(注目画素値でなければラベ
ル値は“0”であるし、ラベルが既に付与されていれば
ラベル値は“−1”ではない)。
As described above, the labeling processing unit 10 of the present embodiment
Has been described. In the above procedure, the point (x, y)
The condition determination K (x, y) that the upper pixel is unlabeled and the pixel value of interest was performed at various places. This processing is performed by performing the following initialization processing on the labeled image memory 30. It can be simplified by executing. In this initialization processing, the value of each pixel is read from the binary image memory 20 and
Depending on whether or not the pixel is a target pixel value, different temporary labels are given and written to the labeled image memory 30. As the temporary label used at this time, a value not used for final labeling (for example, 0 or -1 when labeling with a natural number serial number) is used. As a preferred example, a temporary label of “−1” is given to a pixel having a target pixel value, and a temporary label of “0” is given to a pixel having no target pixel value. By doing so, K in step S20 in FIG. 2, step S112 in FIG. 3, step S218 in FIG.
The condition determination of (x, y) is a determination as to whether or not the label value of that point (x, y) is “−1”. That is,
If the point (x, y) is “−1”, it is because the label has not been assigned and is the pixel value of interest (the label value is “0” if it is not the pixel value of interest, and the label has already been assigned). The label value is not "-1".

【0058】[処理具体例]次に、具体的な2値画像の
例を参照して、その処理手順の実行の様子を説明する。
[Processing Specific Example] Next, referring to a specific example of a binary image, how the processing procedure is executed will be described.

【0059】2値画像の具体例として、図8に示す画像
を考える。図8では、黒塗り正方形が黒画素、白抜き正
方形が白画素を示し、中に数字を含む白抜き正方形はラ
ベル付けされた白画素を示す。中の数字がラベルの値で
ある。そして、ハッチングが付された四角形は、スタッ
ク12に座標が登録された白画素を示すものとする。
As a specific example of the binary image, consider the image shown in FIG. In FIG. 8, a black square indicates a black pixel, a white square indicates a white pixel, and a white square including a numeral indicates a labeled white pixel. The number inside is the value of the label. The hatched rectangle indicates a white pixel whose coordinates are registered in the stack 12.

【0060】図8の状態は、ラベル1の連結成分(白画
素の塊)についてラベル付与が終わり、ステップS20
にて次のラベル付け始点が検出され、その始点をステッ
プS104でスタック12に登録した時点の様子を示し
ている。すなわち、スタックには座標(12,2)が積
まれており、以降、この座標の画素を始点として、この
画素に連結する画素のラベリングが行われる。
In the state shown in FIG. 8, labeling is completed for the connected component (lumps of white pixels) of label 1, and step S20 is performed.
Shows the state when the next labeling start point is detected and the start point is registered in the stack 12 in step S104. That is, coordinates (12, 2) are stacked on the stack, and thereafter, starting from the pixel at this coordinate, the labeling of the pixel connected to this pixel is performed.

【0061】この場合、まずスタック12から座標(1
2,2)が取り出され(ステップS110)、これはラ
ベル未付与の白画素なので、新たなラベル2が付与され
る(ステップS220)。この画素の上隣と下隣のう
ち、後者はラベル未付与の白画素なのでその座標(1
2,3)がスタック12に積まれる(ステップS31
6)。そのラベル付け始点(12,2)の左隣の画素を
調べると、その画素(13,2)はラベル未付与の白画
素なので、ラベル付け始点と同じラベル2が付与される
(ステップS220)。この画素の下隣の画素(13,
3)は、ラベル未付与の白画素であるが(ステップS3
02)、先ほど座標(12,3)をスタック12に積ん
だときにフラグF2がTRUEにセットされているの
で、スタック12へは登録されない。図9はこの時点の
様子を示す。
In this case, first, the coordinates (1
2, 2) are taken out (step S110), and since these are unlabeled white pixels, a new label 2 is given (step S220). Of the upper and lower neighbors of this pixel, the latter is an unlabeled white pixel, so its coordinates (1
2, 3) are stacked on the stack 12 (step S31).
6). When the pixel on the left of the labeling start point (12, 2) is examined, since the pixel (13, 2) is a white pixel without labeling, the same label 2 as the labeling start point is added (step S220). The pixel (13,
3) is a white pixel with no label (step S3).
02), since the flag F2 is set to TRUE when the coordinates (12, 3) are stacked on the stack 12 earlier, they are not registered in the stack 12. FIG. 9 shows the situation at this point.

【0062】更に処理を進め、y=2のラインについて
の走査が終わった時点では、ラベル付けの状態は図10
に示すようになる。ラインの走査が完了したので、次に
スタック12から先頭のエントリ、すなわち座標(1
2,3)を取り出し(ステップS110)、この座標を
起点としてy=3のラインについての走査を行う。ここ
ではまずラインの始点(12,3)にラベル2が付与さ
れる。その下隣(12,4)はラベル未付与の白画素な
ので、スタック12に積まれる。ラインの始点(12,
3)から右方向に処理を進めていくと、検査対象画素が
(15,3)に達した時点でその画素の下隣(15,
4)が黒画素となり、フラグF2がFALSEにリセッ
トされる(S320)。その後、検査対象画素が(1
9,3)に達した時点では、その下隣(19,4)はラ
ベル未付与の白画素であり、しかもこの時点ではフラグ
F2はFALSEなので、座標(19,4)がスタック
12に積まれることになる(ステップS316)。この
時点のラベリング状態を図11に示す。
Further processing is performed, and when the scanning for the line y = 2 is completed, the state of labeling is as shown in FIG.
It becomes as shown in. Since the scanning of the line has been completed, the next entry from the stack 12, that is, the coordinate (1
2, 3) are taken out (step S110), and scanning is performed on the line of y = 3 using the coordinates as a starting point. Here, first, the label 2 is added to the start point (12, 3) of the line. The lower neighbors (12, 4) are unlabeled white pixels and are stacked on the stack 12. Line start point (12,
When the process proceeds to the right from 3), when the pixel to be inspected reaches (15, 3), the pixel immediately below the pixel (15, 3)
4) becomes a black pixel, and the flag F2 is reset to FALSE (S320). Thereafter, the pixel to be inspected is (1
When the pixel reaches (9, 3), the lower pixel (19, 4) is an unlabeled white pixel, and since the flag F2 is FALSE at this point, the coordinates (19, 4) are stacked on the stack 12. (Step S316). The labeling state at this time is shown in FIG.

【0063】以降、処理を進め、y=3のラインの走査
が完了した時点では、ラベリング状態は図12に示すよ
うになる。この時点では、スタック12には上から順に
座標(19,4)、(12,4)が積まれている。これ
は、y=4より下では白画素の連結成分が、画素(1
9,4)に連結している部分と、画素(12,4)に連
結している部分の2つに分岐していることを示してい
る。
Thereafter, the processing is advanced, and when the scanning of the line of y = 3 is completed, the labeling state becomes as shown in FIG. At this point, the coordinates (19, 4) and (12, 4) are stacked on the stack 12 in order from the top. This is because, below y = 4, the connected component of the white pixel is
9 and 4) and a portion connected to the pixel (12, 4).

【0064】次は、スタック12から後に積まれた座標
(19,4)が取り出され、この座標をライン始点とし
て走査(ラベリング)が行われることになる。以降、上
記の処理の繰り返しにより、2分岐した連結成分のうち
画素(19,4)に連結した白画素にラベル2が付与さ
れていく。y=7のラインまで処理が完了した時点のラ
ベリング状態を図13に示す。
Next, the coordinates (19, 4) stacked later are taken out of the stack 12, and scanning (labeling) is performed using the coordinates as the line start point. Thereafter, by repeating the above-described processing, the label 2 is assigned to the white pixel connected to the pixel (19, 4) among the two branched connected components. FIG. 13 shows a labeling state at the time when the processing is completed up to the line of y = 7.

【0065】次は、座標(20,8)がスタック12か
ら取り出され、この点を始点としてy=8のラインのラ
ベリング走査が行われる。この走査により、新たに座標
(20,9)、(15,7)、(9,9)がこの順番で
スタック12に積まれる。y=8のラインの走査が終わ
った時点のラベリング状態を図14に示す。
Next, the coordinates (20, 8) are taken out of the stack 12, and labeling scanning of the line of y = 8 is performed with this point as a starting point. By this scanning, new coordinates (20, 9), (15, 7) and (9, 9) are stacked on the stack 12 in this order. FIG. 14 shows a labeling state at the time when scanning of the line of y = 8 is completed.

【0066】次にスタック12から座標(9,9)が取
り出され、この点から下に向かってラベリングが行われ
ていく。そして、(9,9)から下の連結成分の白画素
すべてにラベル付けが終わると、次にスタック12から
座標(15,7)が取り出され、この点から上に向かっ
てラベリングが行われていく。図15は、この上向きの
ラベリング走査がy=6のラインまで完了した時点のラ
ベリング状態を示している。
Next, coordinates (9, 9) are extracted from the stack 12, and labeling is performed downward from this point. When labeling is completed for all the white pixels of the connected component below (9, 9), the coordinates (15, 7) are extracted from the stack 12 and labeling is performed upward from this point. Go. FIG. 15 shows a labeling state at the time when the upward labeling scan is completed up to the line of y = 6.

【0067】図16は、更にもう1ライン上までラベリ
ングが完了した時点の状態を示す。この時点では、スタ
ック12の先頭には座標(13,4)が積まれている。
したがって、次は、この点(13,4)を始点としてy
=4のラインについてラベリングが行われる。図17
は、この処理結果を示している。この処理により、スタ
ック12の一番下に積まれている座標(12,4)の画
素にラベル2が付与される。図17では、このことを白
抜きラベルの四角形で表している。この処理では、新た
にスタック12に積まれる座標はない。
FIG. 16 shows a state at the time when the labeling is completed up to one more line. At this point, the coordinates (13, 4) are stacked at the top of the stack 12.
Therefore, next, starting from this point (13, 4), y
Labeling is performed on the line of = 4. FIG.
Shows the result of this processing. By this processing, the label 2 is assigned to the pixel at the coordinates (12, 4) stacked at the bottom of the stack 12. In FIG. 17, this is indicated by a square of a white label. In this process, no new coordinates are stacked on the stack 12.

【0068】次に、スタック12の先頭の座標(20,
9)を取り出し、これを始点として、下方向に向かって
この始点に連結する白画素をラベリングしていく。そし
て、その始点から下方向の連結成分のすべてにラベル付
けが終わると、図18に示す状態となる。この状態で
は、スタック12には、座標(12,4)の点のみが残
っている。最後に、この点をスタック12から取り出す
(ステップS110)。この点は既にラベル付けされて
いるので、ステップS112の判定結果はFALSEと
なり、ライン走査処理ステップS200は行われない。
したがって、スタック12へのエントリの追加が行われ
ないので、結局この結果スタック12が空になる。これ
により、ステップS118でループAの終了条件が成立
し、ラベル付け始点(12,2)から始まるラベル2の
ラベリングが完了したことになる。
Next, the coordinates (20,
9) is taken out, and using this as a starting point, white pixels connected to this starting point are labeled downward. When labeling is completed for all the connected components in the downward direction from the start point, the state shown in FIG. 18 is obtained. In this state, only the point at the coordinates (12, 4) remains in the stack 12. Finally, this point is taken out of the stack 12 (step S110). Since this point has already been labeled, the determination result of step S112 is FALSE, and the line scanning processing step S200 is not performed.
Therefore, no entry is added to the stack 12, and as a result, the stack 12 becomes empty as a result. Thus, the end condition of the loop A is satisfied in step S118, and the labeling of the label 2 starting from the labeling start point (12, 2) is completed.

【0069】以上の具体例からよく分かるように、各ラ
イン上で互いに連結する白画素の集合をノードと考える
と、同一ラベルが付される白画素の塊は、そのノード同
士を隣り合うライン同士で接続した多分木構造と考える
ことができる。本実施形態のラベリング手法は、この多
分木を深さ優先探索アルゴリズムに従って探索する処理
と等価であることが分かる。本実施形態の手法では、多
分木構造のすべての分岐の開始点(ラインの走査開始座
標)が確実にスタック12にスタックされるので、4連
結の連結成分をもれなく求めてラベリングすることがで
きる。
As can be clearly understood from the above specific example, when a set of white pixels connected to each other on each line is considered as a node, a cluster of white pixels having the same label is formed by connecting the node to the adjacent lines. Can be thought of as a tree structure connected by. It can be seen that the labeling method of the present embodiment is equivalent to a process of searching the multitree according to the depth-first search algorithm. In the method of the present embodiment, since the starting points (scanning start coordinates of lines) of all branches of the multi-tree structure are reliably stacked on the stack 12, it is possible to obtain and label four connected components without fail.

【0070】また、本実施形態は、各ライン上で互いに
連結する白画素の集合に対し1つの画素(走査開始座
標)のみが選択されスタック12に登録される構成であ
る。したがって、スタック12から取り出した画素を調
べたとき、それがラベル既付与のものならば、その画素
はある方向から(例えば上から)のアプローチで白画素
塊の分岐の開始点の候補としてスタックされたものが、
逆の方向からのアプローチで既にラベル付けされてしま
ったことを示し、これはすなわち白画素の塊の中に1つ
の穴(黒画素領域)があることを示す。したがって、ス
タック12から取り出した画素がラベル付与済みであっ
た回数をカウントすれば、その結果はラベル付けした白
画素の塊の中の穴の個数を求めることができる。穴の個
数という位相幾何学的な情報は、対象物認識のための有
力な情報となる。
In this embodiment, only one pixel (scanning start coordinate) is selected and registered in the stack 12 for a set of white pixels connected to each other on each line. Therefore, when examining a pixel taken out of the stack 12 and examining it, if it is already labeled, the pixel is stacked from a certain direction (for example, from the top) as a candidate of a starting point of the branch of the white pixel block. Is
It indicates that the label has already been labeled by the approach from the opposite direction, that is, there is one hole (black pixel area) in the mass of white pixels. Therefore, by counting the number of times that the pixels taken out of the stack 12 have been labeled, the result can be used to determine the number of holes in the labeled mass of white pixels. Topological information such as the number of holes is useful information for object recognition.

【0071】[効果]以上、本実施形態に係るラベリン
グ処理について説明した。本実施形態では、ラインに沿
って1画素ずつ連結性を調べると共にその画素の上下の
連結性を持つ画素をラベリング開始点の候補(走査開始
座標)としてスタックする構成なので、あるラインに注
目した場合、そのラインから上あるいは下方向に連結成
分が複雑に分岐するとしても、各分岐部分のいずれかの
画素が必ずスタックに積まれる。したがって、そのスタ
ックのエントリがなくなるまで処理を繰り返せば、必ず
すべての分岐部分について同じラベルが割り当てられる
ことになり、連結成分が複雑な形状でも各画素に確実に
同じラベルを付与することができる。
[Effects] The labeling processing according to the present embodiment has been described above. In the present embodiment, the connectivity is examined one pixel at a time along the line, and pixels having connectivity above and below the pixel are stacked as labeling start point candidates (scanning start coordinates). Even if the connected component is complicatedly branched upward or downward from the line, any pixel of each branch part is always stacked on the stack. Therefore, if the process is repeated until there are no more entries in the stack, the same label is always assigned to all branch portions, and the same label can be reliably assigned to each pixel even if the connected component has a complicated shape.

【0072】また、従来技術では複雑な形状の連結成分
に対応するためには様々な方向について走査を行う必要
があったため、処理に長い時間を要したが、本実施形態
では、複雑な形状についても高速にラベリング処理を行
うことができる。
Further, in the prior art, it was necessary to perform scanning in various directions in order to cope with a connected component having a complicated shape. Therefore, a long time was required for processing. Can also perform the labeling process at high speed.

【0073】例えば、発明者が図21に示す20×25
画素の2値画像を用いて行った実験では、白画素連結成
分のラベリングについて、従来手法に基づくプログラム
と本実施形態の手法に基づくプログラムとでは、処理時
間が約4:1(すなわち本実施形態は従来の約4倍の速
度)という結果が得られた。なおこの実験は、一般的な
パーソナルコンピュータを用いて行ったものである。
For example, the inventor has set a 20 × 25 shown in FIG.
In an experiment performed using a binary image of pixels, the processing time for labeling white pixel connected components between a program based on the conventional method and a program based on the method according to the present embodiment is about 4: 1 (that is, the processing time according to the present embodiment). Is about four times the speed of the prior art). This experiment was performed using a general personal computer.

【0074】また、従来技術では画像全体についてのラ
ベリング処理が完了するまで特徴量の算出を待たなけれ
ばならなかったのに対し、本実施形態では、1つの白画
素の塊(連結成分)のラベリングが終了した段階でその
塊の面積や重心などの特徴量を求めることができるの
で、特徴量の算出までを総合して考えれば高速化の効果
はさらに高いといえる。特に、侵入者検知など、画像中
から特定の条件を満たすものを1つ見つければよいとい
う用途では、高速化の効果はさらに顕著である。
In the prior art, the calculation of the feature amount had to be waited until the labeling process for the entire image was completed. On the other hand, in the present embodiment, the labeling of one white pixel block (connected component) was performed. Since the feature amount such as the area and the center of gravity of the block can be obtained at the stage when the calculation is completed, it can be said that the effect of speeding up is even higher if the calculation up to the feature amount is considered comprehensively. In particular, in applications where it is only necessary to find one that satisfies a specific condition from an image, such as intruder detection, the effect of speeding up is even more remarkable.

【0075】なお、以上の例では、ラベリングの対象と
なる注目画素値を白としたが、本発明は、注目画素値を
黒とする場合にも当然適用可能である。
In the above example, the target pixel value to be labeled is white, but the present invention is naturally applicable to a case where the target pixel value is black.

【0076】[侵入者検知装置]最後に図19を参照し
て、本実施形態の画像処理の侵入者検知装置への応用例
を説明する。図19において、図1と同様の構成要素に
は同じ符号を付す。
[Intruder Detecting Apparatus] Finally, an application example of the image processing of the present embodiment to an intruder detecting apparatus will be described with reference to FIG. 19, the same components as those in FIG. 1 are denoted by the same reference numerals.

【0077】この侵入者検知装置では、監視用のCCD
カメラ100からのNTSCコンポジット信号を画像入
力部40で受信し、画像入力部40で得た画像を第1原
画像用メモリ42及び第2原画像用メモリ44に対し、
1フレーム毎に交互に書き込んでいく。差分演算部46
では、1フレーム毎に、第1及び第2原画像用メモリ4
2及び44の画素毎の差分を計算し、その結果を差分画
像用メモリ48に書き込む。差分画像用メモリ48に形
成された、ある時刻とその1フレーム前の時刻との差分
画像は、2値化処理部50にて所定のしきい値を基準に
2値化され、その結果が2値画像用メモリ20に書き込
まれる。ラベリング処理部10は、2値画像用メモリ2
0内の2値画像に対し、前述の処理手順に従ってラベリ
ング及び特徴量の計算処理を行い、その結果をラベル付
画像用メモリ30に書き込む。なお、この図では、ラベ
リング処理に用いる制御用のスタックや各種カウンタの
図示は省略している。侵入者判定部52は、このラベリ
ング結果や特徴量の計算結果を受け取り、これらのデー
タから所定の判断基準に従って侵入者の有無を判定す
る。この判定結果は、侵入者判定装置全体を制御する制
御部54に伝えられ、例えば侵入者有りと判定された場
合は、この制御部54が所定の警報装置を作動させる。
In this intruder detection device, a monitoring CCD
The NTSC composite signal from the camera 100 is received by the image input unit 40, and the image obtained by the image input unit 40 is transmitted to the first original image memory 42 and the second original image memory 44.
Writing is performed alternately for each frame. Difference calculation unit 46
Then, the first and second original image memories 4 are stored for each frame.
The difference for each pixel of 2 and 44 is calculated, and the result is written to the difference image memory 48. The difference image between a certain time and the time one frame before the time formed in the difference image memory 48 is binarized by a binarization processing unit 50 based on a predetermined threshold, and the result is binarized. The data is written to the value image memory 20. The labeling processing unit 10 stores the binary image memory 2
Labeling and feature value calculation processing are performed on the binary image within 0 according to the above-described processing procedure, and the result is written to the labeled image memory 30. In this figure, illustration of a control stack and various counters used for the labeling process is omitted. The intruder determination unit 52 receives the labeling result and the calculation result of the feature amount, and determines the presence or absence of an intruder from these data according to a predetermined criterion. This determination result is transmitted to the control unit 54 that controls the entire intruder determination device. For example, when it is determined that there is an intruder, the control unit 54 activates a predetermined alarm device.

【0078】<実施形態2> [概要]次に、本発明に係る画像処理の別の実施形態に
ついて説明する。上記実施形態1が4連結成分のラベリ
ングであったのに対し、本実施形態では8連結成分のラ
ベリングのための構成を説明する。
<Embodiment 2> [Overview] Next, another embodiment of the image processing according to the present invention will be described. In contrast to the first embodiment in which four connected components are labeled, this embodiment will describe a configuration for eight connected components.

【0079】本実施形態を実現する装置構成は、図1に
示した上記実施形態1の装置構成と同様でよく、基本的
な処理の手順も実施形態1のものとほぼ同様である。た
だ本実施形態では、8連結成分のラベリングを可能とす
るために、隣接ラインの開始点のスタック処理の仕方
を、上記実施形態1の方式から少し変更している。
The configuration of the apparatus for realizing this embodiment may be the same as that of the first embodiment shown in FIG. 1, and the basic processing procedure is almost the same as that of the first embodiment. However, in the present embodiment, in order to enable labeling of eight connected components, the method of stacking the starting points of adjacent lines is slightly changed from the method of the first embodiment.

【0080】上記実施形態1では、ラインの開始点から
1画素ずつ隣を調べてラベリングしていく際、調べる対
象の画素にラベリングを行った後、その画素の上下の隣
接画素についてスタック処理を行っていた(例えば図5
のS218〜S300参照)。この方式では、対象画素
がラベル付けされなければ、その上下の隣接画素が、ラ
ベリング開始点の候補としてスタック12(図1)に積
まれることはない。この方式は、隣接ラインの走査開始
点としてスタックに積まれる画素は、ラベル付けされた
画素の上下の隣接画素に限られるので、対象画素の上下
左右の4つの隣接画素との連結性を見る4連結成分の方
式に合致している。例えば、図22に示すような画像2
00の場合、実施形態1の方式では、白画素の塊210
と塊220とが(4連結性の観点では)非連結と判断さ
れ、別のラベルが与えられてしまう。例えば左から右
へ、上から下へと画素を走査して連結性を調べていく場
合、6ライン目にて(7,6)から順に右方向へと走査
していった場合、(9,6)の画素は黒画素なのでラベ
ル条件を満たさず、したがってラベリングが施されな
い。このため、その下の(9,7)は白画素であるもの
の、スタック12には追加されない。したがって、ラベ
リング走査は7ライン目に続くことができず、塊220
には、塊210とは別のラベルが与えられることにな
る。
In the first embodiment, when the next pixel is examined and labeled one by one from the start point of the line, after the labeling is performed on the pixel to be examined, the stack processing is performed on the adjacent pixels above and below the pixel. (For example, FIG. 5
S218 to S300). In this method, unless the target pixel is labeled, adjacent pixels above and below the target pixel are not stacked on the stack 12 (FIG. 1) as candidates for a labeling start point. In this method, since the pixels stacked on the stack as the scanning start point of the adjacent line are limited to the upper and lower adjacent pixels of the labeled pixel, the connectivity with the four adjacent pixels of the target pixel is determined. It conforms to the method of connected components. For example, image 2 as shown in FIG.
In the case of 00, according to the method of the first embodiment, the cluster of white pixels 210
And the chunk 220 are determined to be unconnected (in terms of 4-connectivity), and another label is given. For example, when scanning the pixels from left to right and from top to bottom to check the connectivity, when scanning in the right direction from (7, 6) on the sixth line, (9, Since the pixel 6) is a black pixel, the label condition is not satisfied, and thus no labeling is performed. Therefore, although (9, 7) below it is a white pixel, it is not added to the stack 12. Therefore, the labeling scan cannot continue to line 7 and the block 220
Will be given a different label than the chunk 210.

【0081】これに対し、8連結成分を考慮する本実施
形態2では、図22のようなケースにおいて塊210と
220とに同じラベルを与えるために、6ライン目の走
査の際に、隣接ラインの(9,7)がスタック12に積
まれるようにアルゴリズムを変更する。すなわち、本実
施形態では、実施形態1と異なり、ラベリング走査の対
象画素にラベルが付与されるか否かによらず、その対象
画素の上下の隣接画素がラベル条件を満足すればスタッ
ク12に追加するようにする。例えば図22の例で言え
ば、6ライン目の走査において、対象画素が(9,6)
となったとき、その下側の隣接画素(9,7)はラベル
条件(ラベル未付与且つ白画素)を満足するので、その
画素をスタック12に積む(対象画素がラベル条件を満
足するか否かは考慮しない)。ライン走査において対象
画素(9,6)の直前の画素(86)までは連結性が保
証されており、この画素(8,6)とスタックに積んだ
画素(9,7)とは8連結性がある。したがって、スタ
ック12に積んだ画素(9,7)から隣接ラインのラベ
リング走査を再開すれば、8連結性を満足したラベリン
グが行える。
On the other hand, in the second embodiment in which the eight connected components are considered, in order to give the same label to the blocks 210 and 220 in the case shown in FIG. The algorithm is changed so that (9, 7) is stacked on the stack 12. That is, in the present embodiment, unlike the first embodiment, regardless of whether or not a label is given to the target pixel of the labeling scan, if the adjacent pixels above and below the target pixel satisfy the label condition, they are added to the stack 12. To do it. For example, in the example of FIG. 22, in the scanning of the sixth line, the target pixel is (9, 6).
Is satisfied, the lower adjacent pixel (9, 7) satisfies the label condition (unlabeled and white pixel), so that pixel is stacked on the stack 12 (whether the target pixel satisfies the label condition or not). Is not considered). In the line scanning, connectivity is guaranteed up to the pixel (86) immediately before the target pixel (9, 6), and this pixel (8, 6) and the pixel (9, 7) stacked on the stack have eight connectivity. There is. Therefore, if the labeling scan of the adjacent line is restarted from the pixels (9, 7) stacked on the stack 12, labeling satisfying the 8 connectivity can be performed.

【0082】[処理手順]次に、フローチャートを参照
して本実施形態のラベリング手順を説明する。この手順
では、スタック処理を上述の如く変更する以外に、ラベ
ル付画像用メモリ30に対して初期化処理を施すことに
より、ラベル条件の判断を容易にしている。
[Processing Procedure] Next, a labeling procedure of the present embodiment will be described with reference to a flowchart. In this procedure, besides changing the stack processing as described above, the label condition is easily determined by performing an initialization process on the labeled image memory 30.

【0083】図23は、全体的な処理手順のフローチャ
ートである。この手順では、まずラベリング処理対象の
2値画像を2値画像用メモリ20に用意し(S50)、
この2値画像に応じてラベル付画像用メモリ30を初期
化する(S500)。この初期化処理の詳細を図24に
示す。
FIG. 23 is a flowchart of the overall processing procedure. In this procedure, first, a binary image to be labeled is prepared in the binary image memory 20 (S50).
The labeled image memory 30 is initialized according to the binary image (S500). FIG. 24 shows the details of this initialization processing.

【0084】ラベル付画像用メモリ30の初期化処理で
は、まず2値画像を用意し(S502)、走査位置を示
す座標のインデックスx、yをそれぞれ0に初期化する
(S504)。以降ステップS506からS518まで
の処理ループで、鉛直方向についての走査が制御され、
ステップS508からS516までの処理ループで、水
平方向についての走査が制御される。このラスタ走査に
従って、2値画像の各画素(x,y)の値B(x,y)
を調べていく(S510)。
In the initialization processing of the labeled image memory 30, first, a binary image is prepared (S502), and the coordinates x and y of the coordinates indicating the scanning position are initialized to 0 (S504). Thereafter, in the processing loop from step S506 to S518, scanning in the vertical direction is controlled,
In the processing loop from step S508 to S516, scanning in the horizontal direction is controlled. According to this raster scanning, the value B (x, y) of each pixel (x, y) of the binary image
Are checked (S510).

【0085】S510でB(x,y)=0(すなわち
黒)ならば、ラベル付画像用メモリ30の当該画素
(x,y)の値L(x,y)を“0”にセットし(S5
12)、B(x,y)=0でなければ(すなわち黒画
素)であれば、当該画素のラベル値L(x,y)を“−
1”にセットする(S514)。
If B (x, y) = 0 (that is, black) in S510, the value L (x, y) of the pixel (x, y) in the labeled image memory 30 is set to “0” ( S5
12), if B (x, y) = 0 (that is, a black pixel), the label value L (x, y) of the pixel is set to “−”.
It is set to 1 "(S514).

【0086】すなわち、この例では、白画素の塊に対し
て自然数(1,2,3,…)のラベルを付与していくた
め、この初期化処理では、黒画素についてはラベル値
“0”を与え、各白画素には仮のラベル値“−1”を与
える。この仮のラベル値“−1”は、後に正式のラベル
値に置き換えられる。逆に言えば、後のラベリング処理
において、ラベル値が“−1”である画素を見つけれ
ば、その画素は、ラベル条件(白画素且つラベル未付
与)を満足するということが即座に分かり、各画素がラ
ベル条件を満足するか否かの判断が容易になる。
That is, in this example, a label of a natural number (1, 2, 3,...) Is given to a cluster of white pixels. And a temporary label value “−1” is given to each white pixel. This temporary label value "-1" is later replaced with a formal label value. Conversely, in the subsequent labeling process, if a pixel with a label value of “−1” is found, it is immediately known that the pixel satisfies the label condition (white pixel and no label attached). It is easy to determine whether a pixel satisfies the label condition.

【0087】このようにしてラベル付画像用メモリ30
の初期化が完了すると、ラベル値nを0に初期化し(S
52)、走査点の座標インデックスx、yをそれぞれ0
に初期化した上で(S54)、ラベル付画像用メモリ3
0をラスタ走査する(x方向はS58〜S64、y方向
はS56〜S66)。この走査は、ラベル未付与の新た
な白画素の塊の最初の点を見つけるための走査であり、
S60でメモリ30の調査対象画素(x,y)の値L
(x,y)を調べ、その値が−1であれば、ラベル未付
与の白画素が見つかったということなので、ラベル値n
をインクリメントし(S62)、その画素を始点として
連結成分のラベル付け処理を行う(S600)。1つの
塊のラベル付け(S600)が終わる毎に、S56〜S
66の処理ループが繰り返され、画像の最後の画素まで
走査が終わると処理が終了する。
In this way, the labeled image memory 30
Is completed, the label value n is initialized to 0 (S
52), the coordinate index x and y of the scanning point are each set to 0
(S54), and the labeled image memory 3 is initialized.
0 is raster-scanned (S58 to S64 in the x direction, S56 to S66 in the y direction). This scan is to find the first point of a new unlabeled cluster of white pixels,
In S60, the value L of the pixel to be investigated (x, y) in the memory 30
(X, y) is checked, and if the value is -1, it means that an unlabeled white pixel has been found, and the label value n
Is incremented (S62), and the connected component is labeled with the pixel as a start point (S600). Each time the labeling of one block (S600) is completed, S56 to S
The processing loop of 66 is repeated, and the process ends when scanning is completed up to the last pixel of the image.

【0088】ラベル付け処理(S600)の詳細な手順
は、図3に示した実施形態1の手順とほぼ同様である。
ただし、実施形態1では、S112でスタック12から
取り出した画素(x0,y0)がラベル条件を満足するか
どうかの条件判断K(x0,y0)を行っていたが、本実
施形態ではこの代わりに、当該画素のラベル値L(x
0,y0)が“−1”であるか否かを調べる。L=−1で
あればラベル条件を満足するということなのでライン走
査処理(S200)に進み、そうでなければスタック1
2から次の画素を取り出して処理を繰り返す。
The detailed procedure of the labeling process (S600) is almost the same as the procedure of the first embodiment shown in FIG.
However, in the first embodiment, the condition determination K (x0, y0) is performed to determine whether or not the pixel (x0, y0) extracted from the stack 12 in S112 satisfies the label condition. , The label value L (x
(0, y0) is "-1". If L = -1, it means that the label condition is satisfied, so the process proceeds to the line scanning process (S200).
The next pixel is taken out from 2 and the process is repeated.

【0089】さて、S200のライン走査処理では、実
施形態1と同様右方向処理(S210)と左方向処理
(S250)を順に行う(図4参照)。本実施形態にお
ける右方向処理と左方向処理の詳細な手順を図25、図
26にそれぞれ示す。これらの図において、図5、図7
と同様の処理を行うステップについては、同じ符号を付
してその説明を省略する。
Now, in the line scanning process of S200, the rightward process (S210) and the leftward process (S250) are sequentially performed as in the first embodiment (see FIG. 4). Detailed procedures of rightward processing and leftward processing in the present embodiment are shown in FIGS. 25 and 26, respectively. In these figures, FIG. 5, FIG.
Steps for performing the same processing as in the above are denoted by the same reference numerals, and description thereof is omitted.

【0090】本実施形態の右方向処理(図25参照)
は、対象画素(x,y0)がライン条件を満足するか否
かを判定する(S232)前に、その対象画素の上下の
隣接画素について隣接ライン開始点スタック処理(S3
00)を実行する点が実施形態1と異なる(実施形態1
では、対象画素がライン条件を満足する場合にのみ、そ
の上下の隣接画素についてスタック処理(S300)を
行った)。そして、S232の判定で対象画素がライン
条件を満足すると判定された場合、その対象画素(x,
y0)のラベル値L(x,y0)をnにセットし(S23
4)、面積や重心の計算のための処理を行う(S22
4)。
Rightward processing in this embodiment (see FIG. 25)
Before judging whether or not the target pixel (x, y0) satisfies the line condition (S232), the adjacent line start point stacking process (S3) is performed on the adjacent pixels above and below the target pixel.
00) is different from the first embodiment (first embodiment).
Then, only when the target pixel satisfies the line condition, the stack processing (S300) is performed on the upper and lower adjacent pixels). If it is determined in S232 that the target pixel satisfies the line condition, the target pixel (x,
The label value L (x, y0) of (y0) is set to n (S23).
4) Perform processing for calculating the area and the center of gravity (S22)
4).

【0091】なお、本実施形態のスタック処理(S30
0)の処理内容は、上下隣接画素がライン条件を満たす
かどうかの判定(S302、S312)を、それら画素
の画素値L(x,y0-1)、L(x,y0+1)が“−1”
であるか否かによって判定する点を除いては、図6に示
した実施形態1の処理と同様でよい。
The stack processing of this embodiment (S30
The processing content of (0) is to determine whether the upper and lower adjacent pixels satisfy the line condition (S302, S312), and to determine whether the pixel values L (x, y0-1) and L (x, y0 + 1) of those pixels are " -1 "
The process may be the same as the process of the first embodiment shown in FIG.

【0092】左方向処理(図26参照)では、まずフラ
グ調整処理(S270)を行う。このフラグ調整処理の
詳細は図27に示される。すなわち、フラグ調整処理で
は、まずy0(走査中のラインの番号)が0より大きい
か否か(すなわち上方に隣接ラインが存在しうるか否
か)を判定し(S700)、y0>0であれば上側隣接
ラインの開始点画素判定のためのフラグF1にL(x
0,y0-1)をセットする。この値L(x0,y0-1)は、
現在走査中のラインの始点画素(x0,y0)の上隣の画
素のラベル値である。ただし、フラグF1は0,1の2
値なので、L=0以外のケースはF1=1になる。この
S702により、ライン始点画素の上隣画素がL=0で
ある時のみ、F1=0(FALSE、すなわちリセット
状態)となり、それ以外のケースではF1=1(TRU
E)となる。
In the leftward process (see FIG. 26), first, a flag adjustment process (S270) is performed. Details of this flag adjustment processing are shown in FIG. That is, in the flag adjustment processing, first, it is determined whether or not y0 (the number of the line being scanned) is greater than 0 (that is, whether or not there is an adjacent line above) (S700). The flag F1 for determining the start point pixel of the upper adjacent line is set to L (x
0, y0-1) is set. This value L (x0, y0-1) is
This is the label value of the pixel immediately above the start pixel (x0, y0) of the line currently being scanned. However, the flag F1 is 2 of 0 and 1
Since it is a value, F1 = 1 in cases other than L = 0. By this S702, F1 = 0 (FALSE, that is, reset state) only when the pixel immediately above the line start pixel is L = 0, and in other cases, F1 = 1 (TRU
E).

【0093】L(x0,y0-1)=0ということは、ライ
ン始点の上隣画素(x0,y0-1)がラベル条件を満足し
ていないことを意味し、これは言い換えれば、走査中の
ラインの上隣ラインのラベル条件を満足する画素は、少
なくとも(x0,y0-1)で連結を切断されていることを
意味する。したがって、ここでF1をFALSEにリセ
ットすることで、以降の左方向のライン走査において最
初に見つかる上隣ラインのラベル条件満足画素をスタッ
クに積むことができる。
When L (x0, y0-1) = 0, it means that the pixel (x0, y0-1) above the line start point does not satisfy the label condition. A pixel that satisfies the label condition of the line adjacent to the line above is disconnected at least at (x0, y0-1). Therefore, by resetting F1 to FALSE, it is possible to stack the label condition satisfying pixels of the upper adjacent line, which are found first in the subsequent leftward line scanning, on the stack.

【0094】一方、L(x0,y0-1)が0でない場合に
は、次の2つのケースが考えられる。第1のケースはL
(x0,y0-1)=−1の場合であり、この場合、既に画
素(x0,y0-1)は右方向処理(図25)のときにスタ
ックにつまれているはずなので、F1がTRUEで問題
がない。
On the other hand, when L (x0, y0-1) is not 0, the following two cases can be considered. The first case is L
(X0, y0-1) =-1. In this case, since the pixel (x0, y0-1) must already be in the stack at the time of the rightward processing (FIG. 25), F1 is TRUE. There is no problem.

【0095】第2のケースはL(x0,y0-1)がn(自
然数)、すなわち画素(x0,y0-1)に既にラベルが付
与されている場合であり、この値nは、連結性から始点
画素(x0,y0)のラベルと同じ値である。この場合、
上隣ラインでラベル未付与画素の連結が切れているの
で、本来ならばフラグF1はFALSEにリセットされ
るべきであるが、このS702ではTRUEにセットさ
れる。しかし、これはこれで問題がない。なぜなら、そ
の画素(x0,y0-1)のラベルがn(自然数)である以
上、左隣の画素(x0-1,y0-1)のラベルL(x0-1,
y0-1)は、白画素ならば連結性によりnにセットされ
ているはずであり、黒画素ならば0にセットされている
はずだからである。したがって、仮にこの第2のケース
においてS702でF1=TRUEに設定したとして
も、次の画素に進んでスタック処理(図6参照)を行っ
たときにF1はFALSEにリセットされるので、問題
が起こらない。
The second case is a case where L (x0, y0-1) is n (natural number), that is, a pixel (x0, y0-1) has already been labeled, and this value n is Has the same value as the label of the starting pixel (x0, y0). in this case,
Since the connection of the unlabeled pixel is disconnected in the upper adjacent line, the flag F1 should be reset to FALSE normally, but is set to TRUE in S702. But this is no problem. Because the label of the pixel (x0, y0-1) is n (natural number), the label L (x0-1,
This is because y0-1) should be set to n for a white pixel and to 0 for a black pixel. Therefore, even if F1 is set to TRUE in S702 in the second case, F1 is reset to FALSE when the next pixel is processed and the stack processing (see FIG. 6) is performed. Absent.

【0096】次にフラグF2についても同様にフラグ調
整を行う。すなわち、まず走査中のラインが画像の最終
行でないことを確認し(S704)、最終行でないこと
が確認できた場合に、フラグF2を前述のF1と同様に
して、F2=L(x0,y0+1)に調整する。なおS70
4の判定において、走査中のラインが最終行であると判
断されれば、フラグF2は必要ないので調整も行わな
い。
Next, the flag is adjusted similarly for the flag F2. That is, first, it is confirmed that the line being scanned is not the last line of the image (S704). If it is confirmed that the line is not the last line, the flag F2 is set to F2 = L (x0, y0) in the same manner as the aforementioned F1. +1). S70
In the determination of 4, if it is determined that the line being scanned is the last line, the flag F2 is not required, and no adjustment is performed.

【0097】このように本実施形態では、右方向処理か
ら左方向処理に移行する際のフラグ調整を、簡単な処理
で実現している。
As described above, in the present embodiment, the flag adjustment at the time of shifting from rightward processing to leftward processing is realized by simple processing.

【0098】このようにしてフラグ調整が終わると、前
述の右方向処理と同様にして、始点から左方向にラベリ
ング処理を行っていく(S254〜S264)。この左
方向処理も、右方向処理と同様、対象画素(x,y0)
がライン条件を満足するか否かを判定する(S232)
前に、その対象画素の上下の隣接画素について隣接ライ
ン開始点スタック処理(S300)を実行する。以降の
処理は右方向処理と基本的に同じでよい。
When the flag adjustment is completed in this manner, labeling processing is performed leftward from the start point in the same manner as in the above-described rightward processing (S254 to S264). This leftward processing is also similar to the rightward processing in that the target pixel (x, y0)
It is determined whether or not satisfies the line condition (S232).
First, the adjacent line start point stacking process (S300) is performed on the adjacent pixels above and below the target pixel. Subsequent processing may be basically the same as the rightward processing.

【0099】このようにして左方向処理(ステップS2
50)が完了すると、1ラインについてのラベリング処
理(ステップS600)が完了し、図23の処理の流れ
に戻ってスタック12から次の走査開始座標を取り出し
て、同じ処理を繰り返す。これにより、上記実施形態1
の場合と同様にして、8連結性を考慮したラベリング処
理が行える。また、本実施形態でも、実施形態1と同
様、白画素の塊の面積Sや重心、白画素塊の中にある穴
の数、などをラベリング処理と並行して求めることがで
きる。また、ラベリングの走査の際に、走査した画素の
x、y座標の最大値、最小値を記憶していくようにすれ
ば、白画素塊の幅や高さなどをラベリング処理と並行し
て求めることも可能である。
Thus, the leftward processing (step S2)
When step 50) is completed, the labeling process for one line (step S600) is completed, and the process returns to the flow of FIG. 23, the next scanning start coordinate is extracted from the stack 12, and the same process is repeated. Thus, the first embodiment
In the same way as in the case of, the labeling process in consideration of the 8 connectivity can be performed. Also in the present embodiment, similarly to the first embodiment, the area S and the center of gravity of the cluster of white pixels, the number of holes in the cluster of white pixels, and the like can be obtained in parallel with the labeling process. If the maximum and minimum values of the x and y coordinates of the scanned pixel are stored during the scanning for labeling, the width and height of the white pixel block are obtained in parallel with the labeling process. It is also possible.

【0100】このように、本実施形態では、隣接ライン
の走査開始点をスタックする際に、ライン走査における
対象画素がラベル付けされるか否かによらず、その対象
ラインの上下の隣接画素がラベル条件を満足するか否か
のみでスタックするか否かを判断するようにした。これ
により、8連結における斜め方向の連結(図22におけ
る(8,6)と(9、7)の関係など)の場合も正しく
スタックすることができるので、8連結成分のラベリン
グ処理を実現することができる。
As described above, in this embodiment, when stacking the scanning start points of the adjacent lines, regardless of whether or not the target pixels in the line scanning are labeled, the adjacent pixels above and below the target line are The determination as to whether or not stacking is made only based on whether or not the label condition is satisfied is made. Thereby, even in the case of the diagonal connection in the eight connection (such as the relationship between (8, 6) and (9, 7) in FIG. 22), stacking can be performed correctly, so that the labeling processing of the eight connected components can be realized. Can be.

【0101】しかも、本実施形態の処理手順は、上記実
施形態1の処理手順とほとんど同じなので、計算量も実
施形態1の場合とほとんど変わらない。本実施形態は、
実施形態1の4近傍ラベリングの場合と比べると、ライ
ン1本のラベリングにつき、当該ラインの両端の斜め隣
の4画素を余計に検査するだけであり、ラインがある程
度長い状況であればこの差はほとんど無視できるほどに
なる。
Further, since the processing procedure of the present embodiment is almost the same as the processing procedure of the first embodiment, the amount of calculation is almost the same as that of the first embodiment. In this embodiment,
Compared with the case of the four-neighbor labeling of the first embodiment, for each labeling of one line, only four pixels diagonally adjacent to both ends of the line are additionally inspected. Almost negligible.

【0102】すなわち、実施形態1の4近傍ラベリング
では、長さL(画素)のライン1本をラベリングする際
にラベル条件を判定する画素の数は3L+2個(対象ラ
イン及びその上下両隣のラインでL×3、これに対象ラ
インの左右両隣の画素2個を加えたもの)である。これ
に対し、本実施形態の8近傍ラベリングでは、同じライ
ン1本につきラベル条件を判定する画素数は3L+6個
である。最悪のケースは、白黒が1画素ずつ市松模様に
なっている場合であり、この場合はL=1なので、本実
施形態の8近傍ラベリングの1ライン当たりの検査画素
数は、実施形態1の場合の1.8倍となる。しかしなが
ら、実際の応用分野(例えば侵入者検知など)では、画
像がこのような極端なものになることはなく、一般に十
分なライン長さになるので、4近傍ラベリングに比べて
4画素分増加したとしても、それは無視できる(例えば
L=50の場合、2.6%の増加に過ぎない)。したが
って、本実施形態の手法は、4近傍ラベリングである実
施形態1とほぼ同様の計算量で、8近傍ラベリングを実
現できるというメリットがある。
That is, in the 4-neighbor labeling of the first embodiment, when labeling one line of length L (pixel), the number of pixels for which the label condition is determined is 3L + 2 (the target line and the lines immediately above and below the target line). L × 3, plus two pixels on the left and right sides of the target line). On the other hand, in the eight-neighbor labeling according to the present embodiment, the number of pixels for which the label condition is determined for one same line is 3L + 6. The worst case is when black and white are in a checkered pattern one pixel at a time, and in this case L = 1, so the number of inspection pixels per line for 8-neighbor labeling in the present embodiment is 1.8 times of However, in practical applications (eg, intruder detection, etc.), the image does not become such an extreme and generally has a sufficient line length, so that the number of pixels is increased by four pixels as compared with four neighbor labeling. Even so, it is negligible (eg, only 2.6% increase for L = 50). Therefore, the method of the present embodiment has an advantage that 8-neighbor labeling can be realized with substantially the same calculation amount as that of the first embodiment in which 4-neighbor labeling is performed.

【0103】以上説明した本実施形態の手法は、実施形
態1の場合と同様、侵入者検知装置など様々な応用分野
に応用できる。
The method of the present embodiment described above can be applied to various application fields such as an intruder detection device as in the case of the first embodiment.

【0104】[効果検証]本実施形態の効果を実例を用
いて検証した。用いた画像は図28に示した(a)〜
(c)の3つの画像であり、これらの画像に対して(a
1)従来手法による4近傍ラベリング(従来技術に記
載)、(a2)従来手法による8近傍ラベリング(従来
技術に示した手法を8近傍を考慮するように拡張したも
の)、(a3)実施形態1による4近傍ラベリング、
(a4)実施形態2による8近傍ラベリング、の4つの
手法でラベリングを行い、その処理時間を計測した。処
理は、CPUとしてPentium2(登録商標)の2
66MHzを搭載したパーソナルコンピュータで行っ
た。その際の処理時間を図29に示す。
[Effect Verification] The effects of the present embodiment were verified using actual examples. The images used are shown in FIGS.
(C) three images, and (a)
1) Four-neighbor labeling according to the conventional method (described in the prior art), (a2) eight-neighbor labeling according to the conventional method (the method shown in the prior art is expanded to take into account eight neighbors), (a3) Embodiment 1 4-neighbor labeling by
(A4) Labeling was performed by four methods of eight neighborhood labeling according to the second embodiment, and the processing time was measured. The processing is performed on the Pentium 2 (registered trademark) 2 as a CPU.
The measurement was performed on a personal computer equipped with 66 MHz. The processing time at that time is shown in FIG.

【0105】画像(a)は単純な画像なので、従来手法
でも仮ラベルの更新を1〜2回行えば最終的なラベルが
決まってしまう。それでも、実施形態1に示した手法
(a3)の方が従来手法(a1)よりも4倍以上速いこ
とが分かる。また、実施形態2の手法(a4)も従来手
法(a2)よりも4倍以上速く、実施形態1(a3)と
ほぼ同程度の速さであることが分かる。
Since the image (a) is a simple image, the final label is determined by updating the temporary label once or twice in the conventional method. Nevertheless, it can be seen that the method (a3) shown in the first embodiment is four times or more faster than the conventional method (a1). In addition, it can be seen that the method (a4) of the second embodiment is at least four times faster than the conventional method (a2), and is almost the same speed as the first embodiment (a3).

【0106】画像(b)はいささか複雑な画像である。
侵入者監視などの応用分野においては、この程度の複雑
さの画像をラベリングすることはめずらしくなく、この
程度の複雑さの画像は実用的な画像の範疇である。この
程度の複雑さになると、従来手法(a1)、(a2)で
は最終的なラベルを決定するのに何度も仮ラベルの付け
直しを必要とするため、処理時間が非常に長くなる。こ
れに対し、実施形態1、2の手法(a3)、(a4)
は、単純な画像(a)の場合と変わらない時間で処理が
完了しており、本発明に係る手法の高速性が如実に示さ
れている。この例でも、実施形態2による処理時間は実
施形態1と比べて遜色ない程度である。
Image (b) is a rather complicated image.
In applications such as intruder surveillance, labeling images of this complexity is not uncommon, and images of this complexity are a category of practical images. At such a level of complexity, the conventional methods (a1) and (a2) require re-assignment of temporary labels many times to determine the final label, so that the processing time becomes extremely long. On the other hand, the methods (a3) and (a4) of the first and second embodiments
Shows that the processing is completed in the same time as the case of the simple image (a), which clearly shows the high speed of the method according to the present invention. Also in this example, the processing time according to the second embodiment is comparable to that of the first embodiment.

【0107】画像(c)は非常に複雑な画像であり、実
際の応用分野でこのような複雑な画像を扱うことはあま
り考えられない。しかしながら、ここでは、本発明に係
る手法の有効性を調べるため、このような複雑な画像に
ついても検証を行った。従来手法(a1)、(a2)で
は、仮ラベルの付け直しを何度も何度も繰り返す必要が
あるため、非常に長い処理時間を要している。しかも、
従来の4近傍処理では、連結を判定する画素が少ないの
で、ラベル付け直しで正当なラベルが塊内を伝搬する速
度が遅くなるため、ここまで画像が複雑になると8近傍
処理の方が処理速度が速くなっている。しかしながら、
いずれにしても、本発明に係る手法(a3)、(a4)
ではいずれも、単純な画像と変わらない処理時間で処理
が完了している。この例でも、実施形態2は、実施形態
1と変わらない処理時間で8近傍ラベリングが可能なこ
とが分かる。
The image (c) is a very complicated image, and it is unlikely to handle such a complicated image in an actual application field. However, in order to examine the effectiveness of the method according to the present invention, such a complicated image was also verified. In the conventional methods (a1) and (a2), it is necessary to repeat the re-attachment of the temporary label over and over again, so that a very long processing time is required. Moreover,
In the conventional 4-neighbor processing, since the number of pixels for which connection is determined is small, the speed at which a valid label propagates through the block by re-labeling becomes slow. Is getting faster. However,
In any case, the methods (a3) and (a4) according to the present invention
In each case, the processing is completed in the same processing time as a simple image. Also in this example, it is understood that the neighborhood of eight can be labeled in the second embodiment in the same processing time as the first embodiment.

【0108】このように、本実施形態によれば、従来技
術よりもはるかに速い処理速度で、しかも4近傍ラベリ
ングを行う実施形態1の場合とほとんど変わらぬ速度
で、8近傍ラベリングを実現することができる。しか
も、その処理に要する時間は、画像の複雑さにあまり影
響されず、ある程度複雑な画像でも高速に処理すること
ができる。これにより、画像処理のリアルタイム性を一
層高めることができる。このようなラベリングの高速化
により生じる時間の余裕により、これまで処理時間の観
点から見送っていた他の処理に時間を割くことも可能に
なると考えられる。
As described above, according to the present embodiment, 8-neighbor labeling can be realized at a processing speed much higher than that of the prior art and at a speed almost equal to that of the first embodiment in which four-neighbor labeling is performed. Can be. In addition, the time required for the processing is not so affected by the complexity of the image, and even a somewhat complicated image can be processed at a high speed. Thereby, the real-time property of the image processing can be further enhanced. It is considered that such a margin of time caused by the speeding up of the labeling makes it possible to devote time to other processing which has been postponed from the viewpoint of the processing time.

【図面の簡単な説明】[Brief description of the drawings]

【図1】 本発明に係る画像処理装置の概略構成図であ
る。
FIG. 1 is a schematic configuration diagram of an image processing apparatus according to the present invention.

【図2】 実施形態1のラベリング処理部の全体処理手
順を示すフローチャートである。
FIG. 2 is a flowchart illustrating an overall processing procedure of a labeling processing unit according to the first embodiment.

【図3】 1つの塊(連結成分)をラベリングする処理
の手順を示すフローチャートである。
FIG. 3 is a flowchart illustrating a procedure of a process of labeling one lump (connected component).

【図4】 図3の手順における1ラインの走査処理の手
順を示すフローチャートである。
FIG. 4 is a flowchart showing the procedure of one-line scanning in the procedure of FIG. 3;

【図5】 1ラインの走査のうち、走査開始座標から右
方向への走査処理の手順を示すフローチャートである。
FIG. 5 is a flowchart showing a procedure of a scanning process in a rightward direction from scanning start coordinates in one-line scanning.

【図6】 隣接ラインの走査開始座標をスタックに登録
する処理の手順を示すフローチャートである。
FIG. 6 is a flowchart illustrating a procedure of a process of registering a scan start coordinate of an adjacent line in a stack.

【図7】 1ラインの走査のうち、走査開始座標から左
方向への走査処理の手順を示すフローチャートである。
FIG. 7 is a flowchart illustrating a procedure of a scanning process in a leftward direction from scanning start coordinates in one-line scanning.

【図8】 具体的な2値画像に対して実施形態のラベリ
ング処理を適用した場合の、ある時点での処理状態を示
す図である。
FIG. 8 is a diagram illustrating a processing state at a certain point in time when the labeling processing of the embodiment is applied to a specific binary image.

【図9】 具体的な2値画像に対して実施形態のラベリ
ング処理を適用した場合の、ある時点での処理状態を示
す図である。
FIG. 9 is a diagram illustrating a processing state at a certain point in time when the labeling processing of the embodiment is applied to a specific binary image.

【図10】 具体的な2値画像に対して実施形態のラベ
リング処理を適用した場合の、ある時点での処理状態を
示す図である。
FIG. 10 is a diagram showing a processing state at a certain point in time when the labeling processing of the embodiment is applied to a specific binary image.

【図11】 具体的な2値画像に対して実施形態のラベ
リング処理を適用した場合の、ある時点での処理状態を
示す図である。
FIG. 11 is a diagram showing a processing state at a certain point in time when the labeling processing of the embodiment is applied to a specific binary image.

【図12】 具体的な2値画像に対して実施形態のラベ
リング処理を適用した場合の、ある時点での処理状態を
示す図である。
FIG. 12 is a diagram illustrating a processing state at a certain point in time when the labeling processing of the embodiment is applied to a specific binary image.

【図13】 具体的な2値画像に対して実施形態のラベ
リング処理を適用した場合の、ある時点での処理状態を
示す図である。
FIG. 13 is a diagram illustrating a processing state at a certain point in time when the labeling processing of the embodiment is applied to a specific binary image.

【図14】 具体的な2値画像に対して実施形態のラベ
リング処理を適用した場合の、ある時点での処理状態を
示す図である。
FIG. 14 is a diagram illustrating a processing state at a certain point in time when the labeling processing of the embodiment is applied to a specific binary image.

【図15】 具体的な2値画像に対して実施形態のラベ
リング処理を適用した場合の、ある時点での処理状態を
示す図である。
FIG. 15 is a diagram showing a processing state at a certain point in time when the labeling processing of the embodiment is applied to a specific binary image.

【図16】 具体的な2値画像に対して実施形態のラベ
リング処理を適用した場合の、ある時点での処理状態を
示す図である。
FIG. 16 is a diagram illustrating a processing state at a certain point in time when the labeling processing of the embodiment is applied to a specific binary image.

【図17】 具体的な2値画像に対して実施形態のラベ
リング処理を適用した場合の、ある時点での処理状態を
示す図である。
FIG. 17 is a diagram illustrating a processing state at a certain point in time when the labeling processing of the embodiment is applied to a specific binary image.

【図18】 具体的な2値画像に対して実施形態のラベ
リング処理を適用した場合の、ある時点での処理状態を
示す図である。
FIG. 18 is a diagram illustrating a processing state at a certain point in time when the labeling processing of the embodiment is applied to a specific binary image.

【図19】 本発明を応用した侵入者検知装置の構成を
示す図である。
FIG. 19 is a diagram showing a configuration of an intruder detection device to which the present invention is applied.

【図20】 複雑に分岐した連結成分を含んだ画像の例
を示す図である。
FIG. 20 is a diagram illustrating an example of an image including a connected component that is complicatedly branched.

【図21】 従来手法と実施形態の手法の処理時間の比
較実験に用いた画像を示す図である。
FIG. 21 is a diagram showing images used in a comparison experiment of processing time between the conventional method and the method of the embodiment.

【図22】 8近傍連結性のある画像の例を示す図であ
る。
FIG. 22 is a diagram illustrating an example of an image having 8-neighbor connectivity.

【図23】 実施形態2のラベリングの全体処理手順を
示すフローチャートである。
FIG. 23 is a flowchart illustrating an overall processing procedure of labeling according to the second embodiment.

【図24】 ラベル付画像用メモリの初期化処理の手順
を示すフローチャートである。
FIG. 24 is a flowchart illustrating a procedure of an initialization process of a memory for a labeled image.

【図25】 実施形態2における右方向への走査処理の
手順を示すフローチャートである。
FIG. 25 is a flowchart illustrating a procedure of a rightward scanning process according to the second embodiment.

【図26】 実施形態2における左方向への走査処理の
手順を示すフローチャートである。
FIG. 26 is a flowchart illustrating a procedure of a leftward scanning process according to the second embodiment.

【図27】 フラグ調整処理の手順を示すフローチャー
トである。
FIG. 27 is a flowchart illustrating a procedure of a flag adjustment process.

【図28】 各実施形態の手法の効果の検証に用いた画
像の例を示す図である。
FIG. 28 is a diagram illustrating an example of an image used for verifying the effect of the method of each embodiment.

【図29】 図28の画像に対する従来手法及び各実施
形態の手法によるラベリングの処理時間の計測結果を示
す図である。
29 is a diagram illustrating measurement results of labeling processing times for the image of FIG. 28 according to the conventional method and the method of each embodiment.

【符号の説明】[Explanation of symbols]

10 ラベリング処理部、12 スタック、14 面積
カウンタ、16 Xカウンタ、18 Yカウンタ、20
2値画像用メモリ、30 ラベル付画像用メモリ。
10 labeling processing unit, 12 stacks, 14 area counter, 16 X counter, 18 Y counter, 20
Binary image memory, 30 Labeled image memory.

Claims (7)

【特許請求の範囲】[Claims] 【請求項1】 画像を所定の走査順序で調べ、ラベル未
付与でかつ注目画素値を有するというラベル条件を満足
する画素を検出し、ラベル付け始点画素に定める始点検
出ステップと、 ラベル付け始点画素及びこれに連結性を有する画素にラ
ベルを付与するラベル付与ステップと、 を含み、 前記ラベル付与ステップは、(a)ラベル付け始点画素
をライン始点とするステップと、(b)ライン始点を最
初の対象画素とし、対象画素を右及び左のうち所定の一
方向に順次1画素ずつ移動させながら、対象画素が前記
ラベル条件を満足する場合はその対象画素に前記ラベル
を付与すると共に、その対象画素の上下の隣接画素が前
記ラベル条件を満足する場合その隣接画素をスタックに
追加するステップと、(c)ステップ(b)にて対象画
素が前記ラベル条件を満足しなくなるか又は画像端部に
達すると、ラベル付け始点画素から前記ステップ(b)
とは逆方向に順次対象画素を1画素ずつ移動させなが
ら、対象画素が前記ラベル条件を満足する場合はその対
象画素に前記ラベルを付与すると共に、その対象画素の
上下の隣接画素が前記ラベル条件を満足する場合その隣
接画素を前記スタックに追加するステップと、(d)ス
テップ(c)にて対象画素が前記ラベル条件を満足しな
くなるか又は画像端部に達すると、前記スタックの先頭
の画素を取り出して新たなライン始点として前記ステッ
プ(b)及び(c)を実行するステップと、(e)前記
スタックから画素がなくなるまで上記ステップ(d)を
繰り返すステップと、 を含み、画像の全画素について走査が終わるまで前記始
点検出ステップ及びラベル付与ステップを繰り返す画像
処理方法。
1. A starting point detecting step of examining an image in a predetermined scanning order, detecting a pixel that satisfies a label condition that a label is unassigned and has a pixel value of interest, and that determines a labeling start pixel; And a label assigning step of assigning a label to a pixel having connectivity thereto, wherein the label assigning step comprises: (a) a step of setting a labeling start pixel as a line start point; When the target pixel satisfies the label condition while sequentially moving the target pixel one pixel at a time in a predetermined one of right and left directions, the label is assigned to the target pixel, and the target pixel is Adding adjacent pixels to the stack when adjacent pixels above and below satisfy the label condition; and (c) in step (b), when the target pixel is When the label condition is not satisfied or the end of the image is reached, the step (b) is performed from the labeling start pixel.
When the target pixel satisfies the label condition while sequentially moving the target pixel one pixel at a time in the reverse direction, the label is given to the target pixel, and adjacent pixels above and below the target pixel are set to the label condition. If the target pixel no longer satisfies the label condition or reaches the end of the image in step (c), the pixel at the top of the stack is added. And performing steps (b) and (c) as a new line start point, and (e) repeating step (d) until there are no more pixels from the stack. An image processing method in which the start point detecting step and the label assigning step are repeated until scanning is completed.
【請求項2】 画像を所定の走査順序で調べ、ラベル未
付与でかつ注目画素値を有するというラベル条件を満足
する画素を検出し、ラベル付け始点画素に定める始点検
出ステップと、 ラベル付け始点画素及びこれに連結性を有する画素にラ
ベルを付与するラベル付与ステップと、 を含み、 前記ラベル付与ステップは、(a)ラベル付け始点画素
をライン始点とするステップと、(b)ライン始点を最
初の対象画素とし、対象画素が前記ラベル条件を満足し
なくなるか又は画像端部に達するまで、対象画素を右及
び左のうち所定の一方向に順次1画素ずつ移動させなが
らその都度対象画素及びその上下の隣接画素を調べ、隣
接画素が前記ラベル条件を満足する場合はその隣接画素
をスタックに追加し、対象画素が前記ラベル条件を満足
する場合はその対象画素に前記ラベルを付与するステッ
プと、(c)ステップ(b)にて対象画素が前記ラベル
条件を満足しなくなるか又は画像端部に達すると、対象
画素が前記ラベル条件を満足しなくなるか又は画像端部
に達するまで、ラベル付け始点画素から前記ステップ
(b)とは逆方向に順次対象画素を1画素ずつ移動させ
その都度対象画素その上下の隣接画素を調べ、隣接画素
が前記ラベル条件を満足する場合その隣接画素を前記ス
タックに追加し、対象画素が前記ラベル条件を満足する
場合はその対象画素に前記ラベルを付与するステップ
と、(d)ステップ(c)にて対象画素が前記ラベル条
件を満足しなくなるか又は画像端部に達すると、前記ス
タックの先頭の画素を取り出して新たなライン始点とし
て前記ステップ(b)及び(c)を実行するステップ
と、(e)前記スタックから画素がなくなるまで上記ス
テップ(d)を繰り返すステップと、 を含み、画像の全画素について走査が終わるまで前記始
点検出ステップ及びラベル付与ステップを繰り返す画像
処理方法。
2. A starting point detecting step for examining an image in a predetermined scanning order, detecting a pixel which satisfies a label condition that a label is unassigned and has a target pixel value, and determines a starting point pixel for labeling; And a label assigning step of assigning a label to a pixel having connectivity thereto, wherein the label assigning step comprises: (a) a step of setting a labeling start pixel as a line start point; Until the target pixel no longer satisfies the label condition or reaches the edge of the image, the target pixel is sequentially moved one pixel at a time in one of right and left directions, and the target pixel and its upper and lower portions Is checked, and if the adjacent pixel satisfies the label condition, the adjacent pixel is added to the stack, and the target pixel satisfies the label condition. Assigning the label to the target pixel, and (c) when the target pixel no longer satisfies the label condition or reaches the end of the image in step (b), the target pixel satisfies the label condition. Until the pixel disappears or reaches the end of the image, the target pixel is sequentially moved one pixel at a time from the labeling start pixel in the direction opposite to the step (b), and the adjacent pixel above and below the target pixel is checked each time. Adding a label to the stack if the label condition is satisfied, and adding the label to the target pixel if the target pixel satisfies the label condition; Satisfies the label condition or reaches the end of the image, fetches the top pixel of the stack and sets it as a new line start point in steps (b) and (c) And (e) repeating the above step (d) until there are no more pixels in the stack, wherein the starting point detecting step and the labeling step are repeated until scanning is completed for all the pixels of the image. Method.
【請求項3】 前記ステップ(b)及び(c)では、 対象画素の上の隣接画素を前記スタックに追加するとセ
ットされ、対象画素の上の隣接画素が前記ラベル条件を
満足しなくなるとリセットされるフラグと、 対象画素の下の隣接画素を前記スタックに追加するとセ
ットされ、対象画素の下の隣接画素が前記ラベル条件を
満足しなるとリセットされるフラグと、 を用い、対象画素の上下の隣接画素のスタックへの追加
は、各々対応するフラグがリセットされている場合のみ
に行うことを特徴とする請求項1又は請求項2に記載の
画像処理方法。
3. The steps (b) and (c) are set when an adjacent pixel above the target pixel is added to the stack, and reset when the adjacent pixel above the target pixel no longer satisfies the label condition. And a flag that is set when an adjacent pixel below the target pixel is added to the stack, and is reset when the adjacent pixel below the target pixel satisfies the label condition. 3. The image processing method according to claim 1, wherein the addition of the pixel to the stack is performed only when the corresponding flag is reset.
【請求項4】 前記ステップ(b)及び(c)で対象画
素にラベルを付与する際に面積カウンタをカウントアッ
プし、前記ステップ(e)で前記スタックから画素がな
くなった時点での前記面積カウンタのカウント値を、前
記ラベル付け始点画素に連結性を有する画素群の面積と
して出力することを特徴とする請求項3記載の画像処理
方法。
4. An area counter is counted up when a label is given to a target pixel in the steps (b) and (c), and the area counter at the point when no pixels are left from the stack in the step (e). 4. The image processing method according to claim 3, wherein the count value is output as an area of a pixel group having connectivity to the labeling start pixel.
【請求項5】 前記ステップ(b)及び(c)で対象画
素にラベルを付与する際にその対象画素のx,y座標を
それぞれxカウンタ及びyカウンタに加え、前記ステッ
プ(e)で前記スタックから画素がなくなった時点での
前記xカウンタ及びyカウンタのカウント値をそれぞれ
前記面積カウンタのカウント値で除することにより、前
記ラベル付け始点画素に連結性を有する画素群の重心位
置を算出して出力することを特徴とする請求項4記載の
画像処理方法。
5. When assigning a label to a target pixel in the steps (b) and (c), the x and y coordinates of the target pixel are added to an x counter and a y counter, respectively. By dividing the count value of the x counter and the count value of the y counter at the time when there are no more pixels from the count value of the area counter, the center of gravity of a group of pixels having connectivity to the labeling start pixel is calculated. The image processing method according to claim 4, wherein outputting is performed.
【請求項6】 前記ステップ(d)で前記スタックから
取り出した画素が前記ステップ(b)で前記ラベル条件
を満足しないと判断された回数をカウントするカウンタ
を有し、前記ステップ(e)で前記スタックから画素が
なくなった時点でのこのカウンタのカウント値を、前記
ラベル付け始点画素に連結性を有する画素領域に含まれ
る穴の数として出力することを特徴とする請求項3から
請求項5のいずれかに記載の画像処理方法。
6. A counter for counting the number of times that the pixel extracted from the stack in the step (d) is determined not to satisfy the label condition in the step (b), and the counter is provided in the step (e). The count value of this counter at the time when there are no more pixels from the stack is output as the number of holes included in a pixel area having connectivity to the labeling start pixel. The image processing method according to any one of the above.
【請求項7】 画像を所定の走査順序で調べ、ラベル未
付与でかつ注目画素値を有するというラベル条件を満足
する画素を検出し、ラベル付け始点画素に定める始点検
出ステップと、 ラベル付け始点画素及びこれに連結性を有する画素にラ
ベルを付与するラベル付与ステップと、 を含み、 前記ラベル付与ステップは、 ラベル付け始点画素をライン始点とする開始ステップ
と、 前記ライン始点を含むライン上の画素を1画素ずつ走査
し、前記ライン始点に対して連結性を有し前記ラベル条
件を満足する画素を見つける毎に前記ラベルを付与する
と共に、その走査ラインの上下の隣接ラインにおいて、
その走査ラインの画素に対して前記ラベル条件を満足す
る画素を連結候補画素として所定の記憶手段に記憶する
ライン走査ステップと、 前記ライン走査ステップにおいて前記走査ライン上での
ラベル付け処理が完了すると、前記記憶手段から連結候
補画素を1つ取り出し、これを新たなライン始点として
前記ライン走査ステップを反復する走査反復ステップ
と、 を含む画像処理方法。
7. A starting point detecting step of examining an image in a predetermined scanning order, detecting a pixel that satisfies a label condition that a label is unassigned and has a pixel value of interest, and that determines a labeling start pixel. And a label applying step of applying a label to a pixel having connectivity thereto, and wherein the label applying step includes: a starting step in which a labeling starting pixel is a line starting point; and a pixel on a line including the line starting point. Scanning one pixel at a time, applying the label each time a pixel that has connectivity to the line start point and satisfies the label condition is added, and in adjacent lines above and below the scan line,
A line scanning step of storing a pixel satisfying the label condition for a pixel of the scan line as a connection candidate pixel in a predetermined storage unit, and when the labeling process on the scan line is completed in the line scanning step, A scanning repetition step of retrieving one connection candidate pixel from the storage unit and repeating the line scanning step using this as a new line start point.
JP2000008783A 1999-03-19 2000-01-18 Image processing method Expired - Fee Related JP3840025B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP2000008783A JP3840025B2 (en) 1999-03-19 2000-01-18 Image processing method

Applications Claiming Priority (3)

Application Number Priority Date Filing Date Title
JP7686799 1999-03-19
JP11-76867 1999-03-19
JP2000008783A JP3840025B2 (en) 1999-03-19 2000-01-18 Image processing method

Publications (2)

Publication Number Publication Date
JP2000339456A true JP2000339456A (en) 2000-12-08
JP3840025B2 JP3840025B2 (en) 2006-11-01

Family

ID=26417990

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2000008783A Expired - Fee Related JP3840025B2 (en) 1999-03-19 2000-01-18 Image processing method

Country Status (1)

Country Link
JP (1) JP3840025B2 (en)

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2002035474A1 (en) * 2000-10-27 2002-05-02 Praelux Incorporated Method and apparatus for screening chemical compounds
JP2005267362A (en) * 2004-03-19 2005-09-29 Ricoh Co Ltd Image processing method using simd processor and image processor
JP2008225739A (en) * 2007-03-12 2008-09-25 Mitsubishi Electric Corp Feature amount measuring method and feature amount measuring apparatus
US7706595B2 (en) 2003-11-07 2010-04-27 Cyberoptics Corporation Pick and place machine with workpiece motion inspection
US7813559B2 (en) 2001-11-13 2010-10-12 Cyberoptics Corporation Image analysis for pick and place machines with in situ component placement inspection
JP2015041166A (en) * 2013-08-21 2015-03-02 国立大学法人富山大学 Object tracking method and object tracking system
WO2018073888A1 (en) * 2016-10-18 2018-04-26 オリンパス株式会社 Image processing method and image processing device
JP2020087356A (en) * 2018-11-30 2020-06-04 コイト電工株式会社 Image processor and method for processing image

Cited By (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2002035474A1 (en) * 2000-10-27 2002-05-02 Praelux Incorporated Method and apparatus for screening chemical compounds
US7813559B2 (en) 2001-11-13 2010-10-12 Cyberoptics Corporation Image analysis for pick and place machines with in situ component placement inspection
US7706595B2 (en) 2003-11-07 2010-04-27 Cyberoptics Corporation Pick and place machine with workpiece motion inspection
JP2005267362A (en) * 2004-03-19 2005-09-29 Ricoh Co Ltd Image processing method using simd processor and image processor
JP4482356B2 (en) * 2004-03-19 2010-06-16 株式会社リコー Image processing method and image processing apparatus using SIMD processor
JP2008225739A (en) * 2007-03-12 2008-09-25 Mitsubishi Electric Corp Feature amount measuring method and feature amount measuring apparatus
JP2015041166A (en) * 2013-08-21 2015-03-02 国立大学法人富山大学 Object tracking method and object tracking system
WO2018073888A1 (en) * 2016-10-18 2018-04-26 オリンパス株式会社 Image processing method and image processing device
US10846862B2 (en) 2016-10-18 2020-11-24 Olympus Corporation Image processing method and image processing device
JP2020087356A (en) * 2018-11-30 2020-06-04 コイト電工株式会社 Image processor and method for processing image
JP7242273B2 (en) 2018-11-30 2023-03-20 コイト電工株式会社 Image processing device and image processing method

Also Published As

Publication number Publication date
JP3840025B2 (en) 2006-11-01

Similar Documents

Publication Publication Date Title
JP4970195B2 (en) Person tracking system, person tracking apparatus, and person tracking program
JPH0312750B2 (en)
JP6095817B1 (en) Object detection device
KR20200137219A (en) Method and apparatus for wafer defect pattern detection based on unsupervised learning
CN108537286A (en) A kind of accurate recognition methods of complex target based on key area detection
JP3840025B2 (en) Image processing method
JP5264457B2 (en) Object detection device
EP1679655A1 (en) Face image candidate area search method, face image candidate area search system, and face image candidate area search program
JP3598878B2 (en) Defect inspection method and defect inspection device
JP2010170201A (en) Object detection device
CN111160292A (en) Human eye detection method
US6556701B1 (en) Method of and apparatus for extracting dotted line, and storage medium thereof
JP5137862B2 (en) Object detection device
JP2858530B2 (en) Edge enhancement device
JPH0522164B2 (en)
JP3307782B2 (en) Character mark recognition device
JP2002162366A (en) Defect inspection method and its system, and defective area detection method for automatic defect classification
JP3675366B2 (en) Image extraction processing device
JP2979089B2 (en) Character recognition method for scene images
CN113870332A (en) Optical image and SAR image registration method based on linear features
JP2022060505A (en) Fingerprint processing device, fingerprint processing method, program, and fingerprint processing circuit
JP2021043997A (en) Fingerprint processing device, fingerprint processing method, program, and fingerprint processing circuit
JPH024032B2 (en)
KR0158416B1 (en) Object locating method using contraction of visual data
CN115760703A (en) Image detection model training method, difference detection method and related device

Legal Events

Date Code Title Description
A621 Written request for application examination

Free format text: JAPANESE INTERMEDIATE CODE: A621

Effective date: 20040119

RD04 Notification of resignation of power of attorney

Free format text: JAPANESE INTERMEDIATE CODE: A7424

Effective date: 20040119

A977 Report on retrieval

Free format text: JAPANESE INTERMEDIATE CODE: A971007

Effective date: 20060707

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: 20060801

A61 First payment of annual fees (during grant procedure)

Free format text: JAPANESE INTERMEDIATE CODE: A61

Effective date: 20060804

R150 Certificate of patent or registration of utility model

Free format text: JAPANESE INTERMEDIATE CODE: R150

Ref document number: 3840025

Country of ref document: JP

Free format text: JAPANESE INTERMEDIATE CODE: R150

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20100811

Year of fee payment: 4

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20110811

Year of fee payment: 5

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20110811

Year of fee payment: 5

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20120811

Year of fee payment: 6

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20130811

Year of fee payment: 7

LAPS Cancellation because of no payment of annual fees