CN102737361B - Method for transforming full distance of three-dimensional binary image - Google Patents

Method for transforming full distance of three-dimensional binary image Download PDF

Info

Publication number
CN102737361B
CN102737361B CN201210205736.3A CN201210205736A CN102737361B CN 102737361 B CN102737361 B CN 102737361B CN 201210205736 A CN201210205736 A CN 201210205736A CN 102737361 B CN102737361 B CN 102737361B
Authority
CN
China
Prior art keywords
pixel
dimensional
closest
background
function
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Expired - Fee Related
Application number
CN201210205736.3A
Other languages
Chinese (zh)
Other versions
CN102737361A (en
Inventor
李均利
魏平
孙宇红
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
CHENGDU RUIMING MEDICAL INFORMATION TECHNOLOGY Co Ltd
Sichuan Normal University
Original Assignee
CHENGDU RUIMING MEDICAL INFORMATION TECHNOLOGY Co Ltd
Sichuan Normal University
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 CHENGDU RUIMING MEDICAL INFORMATION TECHNOLOGY Co Ltd, Sichuan Normal University filed Critical CHENGDU RUIMING MEDICAL INFORMATION TECHNOLOGY Co Ltd
Priority to CN201210205736.3A priority Critical patent/CN102737361B/en
Publication of CN102737361A publication Critical patent/CN102737361A/en
Application granted granted Critical
Publication of CN102737361B publication Critical patent/CN102737361B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Image Analysis (AREA)

Abstract

本发明实施例提供了一种三维二值图像完全距离变换的方法,该方法包括:将所述三维二值图像沿其中一轴分割成相应个数的二维二值图片;分别计算分割的每一二维二值图片中各个像素的二维完全距离变换;确定所述第一像素的第一最近背景像素范围;确定所述第一像素在所述第一最近背景像素范围中的各个二维二值图片中的投影像素的二维完全距离变换值;根据所述确定的第一像素在所述第一背景像素中各个二维二值图像的投影像素的二维完全距离变换值,确定出所述三维二值图像中距离所述第一背景像素最近的第一背景像素,计算所述第一背景像素与所述第一像素的第一完全距离。采用本方实施例可以提高计算速度以及精确性。

An embodiment of the present invention provides a method for complete distance transformation of a three-dimensional binary image. The method includes: dividing the three-dimensional binary image into a corresponding number of two-dimensional binary pictures along one axis; Two-dimensional complete distance transformation of each pixel in a two-dimensional binary image; determining the first closest background pixel range of the first pixel; determining each two-dimensional distance of the first pixel in the first closest background pixel range The two-dimensional complete distance transformation value of the projection pixel in the binary image; according to the two-dimensional complete distance transformation value of the first pixel in the first background pixel in the projection pixel of each two-dimensional binary image, determine the For the first background pixel closest to the first background pixel in the three-dimensional binary image, calculate a first complete distance between the first background pixel and the first pixel. The calculation speed and accuracy can be improved by adopting this embodiment.

Description

一种三维二值图像完全距离变换的方法A Method for Complete Distance Transformation of 3D Binary Image

技术领域 technical field

本发明涉及图像处理领域,更具体的说,是涉及一种三维二值图像完全距离变换的方法。The invention relates to the field of image processing, and more specifically relates to a method for complete distance transformation of a three-dimensional binary image.

背景技术 Background technique

距离变换是对数字图像的一项重要的预处理操作,经距离变换后的数字图像具有良好的旋转、平移及比例不变性,因而它在图像处理技术各个领域中都起着重要作用。Distance transformation is an important preprocessing operation for digital images. The digital images after distance transformation have good rotation, translation and scale invariance, so it plays an important role in various fields of image processing technology.

对二值图像进行距离变换是指把二值图像中的每一个像素的像素值变换成离其最近的背景像素与该像素的距离的过程。二值图像中的像素可分为背景像素(像素值为0)和目标像素(像素值为1)两类,而背景像素的距离变换值为零。Performing distance transformation on a binary image refers to the process of transforming the pixel value of each pixel in the binary image into the distance between the nearest background pixel and the pixel. The pixels in the binary image can be divided into background pixels (pixel value 0) and target pixels (pixel value 1), and the distance transformation value of the background pixels is zero.

可以利用近似距离变换方法以及完全距离变换方法对二值图像进行距离变换,近似距离变换方法的基本思想是:利用图像处理里常用到的一个近似模板运算,计算从图形外移动到图形内某点的最短距离,模板内标识的距离值通常是欧式距离的取整近似值,同时模板也不可能始终沿着边界轮廓的法向方向移动,因此这类方法一定是有误差,如城市街区距离、棋盘距离、倒角距离等。The approximate distance transformation method and the complete distance transformation method can be used to perform distance transformation on binary images. The basic idea of the approximate distance transformation method is to use an approximate template operation commonly used in image processing to calculate the movement from outside the graph to a certain point in the graph. The distance value marked in the template is usually the rounded approximate value of the Euclidean distance, and the template cannot always move along the normal direction of the boundary contour, so this kind of method must have errors, such as city block distance, chessboard distance, chamfer distance, etc.

完全距离变换是求取每一个像素距离其最近的背景像素的精确欧式距离。传统方法分别计算每个像素与所有背景像素的距离,导致计算时间较长,完全距离变换方法包括:边界传播方法以及降维方法。The complete distance transformation is to calculate the exact Euclidean distance between each pixel and its nearest background pixel. The traditional method calculates the distance between each pixel and all background pixels separately, resulting in a long calculation time. The complete distance transformation method includes: boundary propagation method and dimensionality reduction method.

综上,现有距离变换的方法具有如下缺点:第一,近似方法存在误差而不适用于对精度要求严格的图像进行处理,如医学图像;第二,传统完全距离变换方法运行时间较长。In summary, the existing distance transformation methods have the following disadvantages: first, the approximation method has errors and is not suitable for processing images with strict precision requirements, such as medical images; second, the traditional complete distance transformation method takes a long time to run.

发明内容Contents of the invention

有鉴于此,本发明提供了一种三维二值图像完全距离变换的方法及装置,以克服现有技术中计算距离变换的方法存在误差而不适用于对精度要求严格的图像进行处理以及运算时间长的问题。In view of this, the present invention provides a method and device for complete distance transformation of a three-dimensional binary image, to overcome the error in the method of calculating distance transformation in the prior art, which is not suitable for processing images with strict precision requirements and the calculation time long question.

为实现上述目的,本发明提供如下技术方案:To achieve the above object, the present invention provides the following technical solutions:

一种三维二值图像完全距离变换的方法,所述三维二值图像的尺寸为m×n×s,包括:A method for complete distance transformation of a three-dimensional binary image, the size of the three-dimensional binary image is m × n × s, comprising:

将所述三维二值图像沿其中一轴分割成相应个数的二维二值图片;dividing the three-dimensional binary image into a corresponding number of two-dimensional binary images along one of the axes;

分别计算分割的每一二维二值图片中各个像素的二维完全距离变换;Calculating the two-dimensional complete distance transform of each pixel in each segmented two-dimensional binary image;

根据第二目标像素与需要计算三维完全距离变换的第一像素的完全距离,及所述第二目标像素在所述三维二值图像中的三维完全距离变换值,确定所述第一像素的第一最近背景像素范围;According to the complete distance between the second target pixel and the first pixel for which three-dimensional complete distance transformation needs to be calculated, and the three-dimensional complete distance transformation value of the second target pixel in the three-dimensional binary image, determine the first pixel of the first pixel. a nearest background pixel range;

确定所述第一像素在所述第一最近背景像素范围中的各个二维二值图片中的投影像素的二维完全距离变换值;determining the two-dimensional complete distance transform value of the projected pixel of the first pixel in each two-dimensional binary image within the range of the first nearest background pixel;

根据所述确定的第一像素在所述第一最近背景像素范围中各个二维二值图像的投影像素的二维完全距离变换值,确定出所述三维二值图像中距离所述第一像素最近的第一背景像素,计算所述第一背景像素与所述第一像素的第一完全距离,并将所述第一完全距离作为所述第一像素的三维完全距离变换值。According to the determined two-dimensional complete distance transformation value of the first pixel in the range of the first closest background pixel of each projected pixel of the two-dimensional binary image, determine the distance from the first pixel in the three-dimensional binary image The nearest first background pixel, calculating a first complete distance between the first background pixel and the first pixel, and using the first complete distance as a three-dimensional complete distance transformation value of the first pixel.

优选地,所述第二目标像素在所述三维二值图像中的三维完全距离变换值为r1,所述根据第二目标像素与第一像素的完全距离,及所述第二目标像素在所述三维二值图像中的三维完全距离变换值,确定所述第一像素的第一最近背景像素范围具体包括:Preferably, the three-dimensional complete distance transformation value of the second target pixel in the three-dimensional binary image is r 1 , according to the complete distance between the second target pixel and the first pixel, and the second target pixel in The three-dimensional complete distance transformation value in the three-dimensional binary image, determining the first nearest background pixel range of the first pixel specifically includes:

确定所述第一像素与所述第二目标像素的完全距离r2determining a full distance r 2 of the first pixel to the second target pixel;

所述第一最近背景像素范围为以所述第一像素为球心,以r1+r2为半径的球O1的外切正方体所围成的区域;或,所述第一最近背景像素范围为以所述第二目标像素为球心,以r1为半径的球O2的内接正方体与所述球O1的外切正方体所围成的区域;或,所述第一最近背景像素范围为以所述第一像素为球心,以|r1-r2|为半径的球O3的内接正方体与所述球O1的外切正方体所围成的区域。The first closest background pixel range is the area surrounded by a circumscribed cube of a ball O 1 with the first pixel as the center and r 1 +r 2 as the radius; or, the first closest background pixel The range is the area enclosed by the inscribed cube of the ball O2 and the circumscribed cube of the ball O1 with the second target pixel as the center and r1 as the radius; or, the first closest background The pixel range is the area surrounded by the inscribed cube of the ball O 3 and the circumscribed cube of the ball O 1 with the first pixel as the center and |r 1 -r 2 | as the radius.

优选地,所述三维二值图像沿z轴分割成s张二维二值图片,所述第一最近背景像素范围是以所述第一像素为球心,以r1+r2为半径的球O1的外切正方体所围成的区域,所述第一像素所在的二维二值图片为z0,所述确定所述第一像素在所述第一最近背景像素范围中的各个二维二值图片中的投影像素的二维完全距离变换值具体包括:Preferably, the three-dimensional binary image is divided into s two-dimensional binary images along the z-axis, and the first nearest background pixel range is a sphere O with the first pixel as the center and r 1 +r 2 as the radius The area enclosed by the circumscribed cube of 1 , the two-dimensional binary image where the first pixel is located is z 0 , and the determination of each two-dimensional binary image of the first pixel in the range of the first closest background pixel The two-dimensional complete distance transform values of the projected pixels in the value image specifically include:

以所述二维二值图片z0为对称中心沿z轴方向从里到外依次确定所述第一像素在二维二值图片z0+rx中的投影像素的二维完全距离变换值的平方DRx 2,并记录确定的二维完全距离变换值的平方,rx=0,±1,±2,…,±(r1+r2);Taking the two-dimensional binary picture z0 as the center of symmetry and sequentially determining the two-dimensional complete distance transformation value of the projected pixel of the first pixel in the two-dimensional binary picture z0 + rx from the inside to the outside along the z-axis direction The square of DR x 2 , and record the square of the determined two-dimensional complete distance transformation value, r x =0,±1,±2,…,±(r 1 +r 2 );

判断DRx 2是否满足如果是,则停止确定第一像素分别在二维二值图片z0±(rx+1)直至二维二值图片z0±(r1+r2)中投影像素的二维完全距离变换值,如果否,则继续确定第一像素分别在二维二值图片z0±(rx+1)中投影像素的二维完全距离变换值,直至确定出所述第一像素在二维二值图片z0±(r1+r2)中的投影像素的二维完全距离变换值为止。Determine whether DR x 2 is satisfied If yes, stop determining the two-dimensional complete distance transformation of the projected pixels of the first pixel in the two-dimensional binary image z 0 ±(r x +1) to the two-dimensional binary image z 0 ±(r 1 +r 2 ) value, if not, continue to determine the two-dimensional complete distance transformation value of the projected pixel of the first pixel in the two-dimensional binary image z 0 ±(r x +1), until the first pixel is determined to be in the two-dimensional binary image z 0 ±(r x +1) up to the two-dimensional complete distance transformed value of the projected pixel in the value picture z 0 ±(r 1 +r 2 ).

优选地,所述根据所述第一像素在所述第一最近背景像素范围中各个二维二值图像的投影像素的二维完全距离变换值,确定出所述三维二值图像中距离所述第一像素最近的第一背景像素具体包括:Preferably, according to the two-dimensional complete distance transformation value of the projected pixel of each two-dimensional binary image of the first pixel in the range of the first closest background pixel, the distance in the three-dimensional binary image is determined The nearest first background pixel of the first pixel specifically includes:

利用公式min{DRx 2+|zx-z0|2},其中zx∈第一最近背景像素范围中z的取值范围,确定出与第一像素距离最近的第一背景像素;Using the formula min{DR x 2 +|z x -z 0 | 2 }, where z x ∈ the value range of z in the first nearest background pixel range, determine the first background pixel closest to the first pixel;

利用公式计算出第一完全距离。use the formula Calculate the first complete distance.

优选地,计算每一二维二值图片的二维完全距离变换具体包括:Preferably, calculating the two-dimensional complete distance transformation of each two-dimensional binary image specifically includes:

预处理步骤,所述预处理步骤为确定第一函数或者确定第二函数,所述第一函数用于确定二维二值图片第i行中距离第四像素最近的背景像素的位置,所述第二函数用于确定二维二值图片第j列中距离所述第四像素最近的背景像素的位置,其中,1≤i≤m,1≤j≤n,i与j均为整数;A preprocessing step, the preprocessing step is to determine the first function or determine the second function, the first function is used to determine the position of the background pixel closest to the fourth pixel in the i-th row of the two-dimensional binary image, the The second function is used to determine the position of the background pixel closest to the fourth pixel in the jth column of the two-dimensional binary image, wherein, 1≤i≤m, 1≤j≤n, i and j are both integers;

根据第三目标像素与需要计算二维完全距离的所述第四像素的完全距离,及所述第三目标像素在二维二值图片中的二维完全距离,确定所述第四像素的第二最近背景像素范围,所述第四像素与所述第三目标像素均位于同一二维二值图片中;According to the complete distance between the third target pixel and the fourth pixel for which the two-dimensional complete distance needs to be calculated, and the two-dimensional complete distance of the third target pixel in the two-dimensional binary image, determine the first position of the fourth pixel 2. The closest background pixel range, the fourth pixel and the third target pixel are located in the same two-dimensional binary image;

利用所述第一函数分别在所述第二最近背景像素范围的每行中搜索距离所述第四像素最近的背景像素,或利用所述第二函数分别在所述第二最近背景像素范围的每列中搜索距离所述第四像素最近的背景像素;Use the first function to search for the background pixel closest to the fourth pixel in each row of the second closest background pixel range, or use the second function to search for the background pixel in the second closest background pixel range Search for the nearest background pixel to the fourth pixel in each column;

从搜索出的距离所述第四像素最近的背景像素中确定出与所述第四像素距离最近的第二背景像素,计算所述第二背景像素与所述第四像素的第二二维完全距离,并将所述第二二维完全距离作为所述第四像素在其所在的二维二值图片中的二维完全距离变换值。Determine the second background pixel closest to the fourth pixel from the searched background pixels closest to the fourth pixel, and calculate the second two-dimensional completeness between the second background pixel and the fourth pixel distance, and use the second two-dimensional complete distance as the two-dimensional complete distance transformation value of the fourth pixel in the two-dimensional binary picture where it is located.

优选地,计算每一二维二值图片的二维完全距离变换具体包括:Preferably, calculating the two-dimensional complete distance transformation of each two-dimensional binary image specifically includes:

预处理步骤,所述预处理步骤为确定第一函数或者确定第二函数,所述第一函数用于确定二维二值图片第i行中距离第四像素最近的背景像素的位置,所述第二函数用于确定二维二值图片第j列中距离所述第四像素最近的背景像素的位置,其中,1≤i≤m,1≤j≤n,i与j均为整数;A preprocessing step, the preprocessing step is to determine the first function or determine the second function, the first function is used to determine the position of the background pixel closest to the fourth pixel in the i-th row of the two-dimensional binary image, the The second function is used to determine the position of the background pixel closest to the fourth pixel in the jth column of the two-dimensional binary image, wherein, 1≤i≤m, 1≤j≤n, i and j are both integers;

根据第三目标像素与所述第四像素的完全距离,及第三目标像素与离其最近背景像素的距离,确定第四像素的第二最近背景像素范围,并将第二最近背景像素范围按照预设规则划分为第一子最近背景像素范围集以及第二子最近背景像素范围集,第一子最近背景像素范围集包括至少一个第一子最近背景像素范围,所述至少一个子最近背景像素范围中的行数不大于列数,第二子最近背景像素范围集包括至少一个第二子最近背景像素范围,所述至少一个第二子最近背景像素范围中的行数大于列数;According to the complete distance between the third target pixel and the fourth pixel, and the distance between the third target pixel and its nearest background pixel, determine the second closest background pixel range of the fourth pixel, and divide the second closest background pixel range according to The preset rule is divided into a first sub-nearest background pixel range set and a second sub-nearest background pixel range set, the first sub-nearest background pixel range set includes at least one first sub-nearest background pixel range, and the at least one sub-nearest background pixel range The number of rows in the range is not greater than the number of columns, the second sub-nearest background pixel range set includes at least one second sub-nearest background pixel range, and the number of rows in the at least one second sub-nearest background pixel range is greater than the number of columns;

利用第一函数在第一子最近背景像素范围集的每行中搜索距离第四像素最近的背景像素,利用第二函数在第二子最近背景像素范围集的每列中搜索距离第四像素最近的背景像素;Use the first function to search for the background pixel closest to the fourth pixel in each row of the first sub-nearest background pixel range set, and use the second function to search for the closest background pixel to the fourth pixel in each column of the second sub-nearest background pixel range set background pixels;

从搜索出的距离第四像素最近的背景像素中确定出与第四像素距离最近的第二背景像素,计算第二背景像素与第四像素的第二完全距离,并将此第二完全距离作为第四像素的二维完全距离变换值。Determine the second background pixel closest to the fourth pixel from the searched background pixels closest to the fourth pixel, calculate the second complete distance between the second background pixel and the fourth pixel, and use this second complete distance as The 2D full distance transformed value of the fourth pixel.

优选地,所述确定所述第四像素的第二最近背景像素范围具体包括:Preferably, the determining the second nearest background pixel range of the fourth pixel specifically includes:

计算所述第三目标像素在二维二值图片中的二维完全距离r3Calculating the two-dimensional complete distance r 3 of the third target pixel in the two-dimensional binary image;

确定所述第四像素与所述第三目标像素的完全距离r4determining a complete distance r 4 of the fourth pixel from the third target pixel;

所述第二最近背景像素范围为以所述第四像素为圆心,以r3+r4为半径的圆O4的外切正方形所围成的区域;The second closest background pixel range is the area surrounded by the circumscribed square of the circle O 4 with the fourth pixel as the center and r 3 +r 4 as the radius;

或,所述第二最近背景像素范围为以所述第三目标像素为圆心,以r3为半径的圆O5的内接正方形与所述圆O4的外切正方形所围成的环形区域;Or, the second closest background pixel range is an annular area surrounded by the inscribed square of the circle O5 and the circumscribed square of the circle O4 with the third target pixel as the center and r3 as the radius ;

或,所述第二最近背景像素范围为以所述第四像素为球心,以|r3-r4|为半径的圆O6的内接正方形与所述圆O4的外切正方形所围成的环形区域。Or, the range of the second closest background pixel is defined by the inscribed square of the circle O 6 with the fourth pixel as the center and the radius |r 3 -r 4 | and the circumscribed square of the circle O 4 enclosed circular area.

优选地,所述第四像素位于二维二值图片的第x行,第y列,用(x,y)表示所述第四像素在所述二维二值图片中的位置,以(x,y)为分界点,将第x行分为左侧和右侧,将第y列分为上方和下方;Preferably, the fourth pixel is located in the xth row and the yth column of the two-dimensional binary picture, and (x, y) represents the position of the fourth pixel in the two-dimensional binary picture, and (x ,y) is the demarcation point, which divides row x into left and right, and divides column y into top and bottom;

所述确定第一函数具体包括:The determining the first function specifically includes:

确定用于计算所述二维二值图片第x行左侧距离所述第四像素(x,y)最近的背景像素所在列数的第一子函数,及用于计算所述二维二值图片第x行右侧距离所述第四像素(x,y)最近的背景像素所在列数的第二子函数,其中,1≤x≤m,1≤y≤n;Determining the first sub-function used to calculate the column number of the background pixel closest to the fourth pixel (x, y) on the left side of the xth row of the two-dimensional binary image, and used to calculate the two-dimensional binary image The second sub-function of the column number of the background pixel closest to the fourth pixel (x, y) on the right side of the xth row of the picture, wherein, 1≤x≤m, 1≤y≤n;

根据所述第一子函数及所述第二子函数,确定所述第一函数;determining the first function according to the first sub-function and the second sub-function;

所述确定第二函数具体包括:The determining the second function specifically includes:

确定用于计算所述二维二值图片第y列上方距离所述第四像素最近的背景像素所在行数的第三子函数,及用于计算所述二维二值图片第y列下方距离所述第四像素最近的背景像素所在行数的第四子函数;Determine the third sub-function used to calculate the row number of the background pixel closest to the fourth pixel above the yth column of the two-dimensional binary image, and to calculate the distance below the yth column of the two-dimensional binary image The fourth sub-function of the row number of the nearest background pixel of the fourth pixel;

根据所述第三子函数及所述第四子函数,确定所述第二函数。The second function is determined according to the third sub-function and the fourth sub-function.

优选地,所述第一子函数具体为L[x,y]:Preferably, the first sub-function is specifically L[x, y]:

LL [[ xx ,, ythe y ]] == ythe y II (( xx ,, ythe y )) == 00 LL [[ xx ,, ythe y -- 11 ]] II (( xx ,, ythe y )) == 11 ;;

若I(x,y)=1且y=1,那么L(x,y)=-Maxlable;If I(x, y)=1 and y=1, then L(x, y)=-Maxlable;

所述第二子函数具体为R[x,y]:The second sub-function is specifically R[x, y]:

RR [[ xx ,, ythe y ]] == ythe y II (( xx ,, ythe y )) == 00 RR [[ xx ,, ythe y ++ 11 ]] II (( xx ,, ythe y )) == 11 ;;

若I(x,y)=1且y=n,那么R[x,y]=Maxlable;If I(x, y)=1 and y=n, then R[x, y]=Maxlable;

则根据所述第一子函数及所述第二子函数确定的所述第一函数具体为SZ[x,y]:Then the first function determined according to the first sub-function and the second sub-function is specifically SZ[x, y]:

SZSZ [[ xx ,, ythe y ]] == LL [[ xx ,, ythe y ]] ythe y -- LL [[ xx ,, ythe y ]] << RR [[ xx ,, ythe y ]] -- ythe y RR [[ xx ,, ythe y ]] ythe y -- LL [[ xx ,, ythe y ]] &GreaterEqual;&Greater Equal; RR [[ xx ,, ythe y ]] -- ythe y ;;

所述第三子函数具体为T[x,y]:The third sub-function is specifically T[x, y]:

TT [[ xx ,, ythe y ]] == xx II (( xx ,, ythe y )) == 00 TT [[ xx -- 11 ,, ythe y ]] II (( xx ,, ythe y )) == 11 ;;

若I(x,y)=1且x=1,那么T[x,y]=-Maxlable;If I(x, y)=1 and x=1, then T[x, y]=-Maxlable;

所述第四子函数具体为D[x,y]:The fourth sub-function is specifically D[x, y]:

DD. [[ xx ,, ythe y ]] == xx II (( xx ,, ythe y )) == 00 DD. [[ xx ++ 11 ,, ythe y ]] II (( xx ,, ythe y )) == 11 ;;

若I(x,y)=1且x=m,那么D[x,y]=Maxlable;If I(x, y)=1 and x=m, then D[x, y]=Maxlable;

则根据所述第三子函数及所述第四子函数确定的所述第二函数具体为ZS[x,y]:Then the second function determined according to the third sub-function and the fourth sub-function is specifically ZS[x, y]:

ZSZS [[ xx ,, ythe y ]] == TT [[ xx ,, ythe y ]] xx -- DD. [[ xx ,, ythe y ]] << TT [[ xx ,, ythe y ]] -- xx DD. [[ xx ,, ythe y ]] xx -- DD. [[ xx ,, ythe y ]] &GreaterEqual;&Greater Equal; TT [[ xx ,, ythe y ]] -- xx ;;

其中,I(x,y)=1表示为目标像素,I(x,y)=0表示为背景像素,所述Maxlable为预设最大标记值。Wherein, I(x, y)=1 represents a target pixel, I(x, y)=0 represents a background pixel, and the Maxlable is a preset maximum label value.

其中,所述 Maxlable = ( 1 + 2 ) max ( m , n ) . Among them, the Maxlable = ( 1 + 2 ) max ( m , no ) .

经由上述的技术方案可知,采用本发明实施例提供的快速三维二值图像完全距离变换的方法,首先在已知第二目标像素的三维完全距离变换的情况下,可以根据第二目标相像素在三维二值图像中的三维完全距离变换值,确定第一像素的第一最近背景像素范围,再搜索距离第一像素的最近背景像素时,是在第一最近背景像素范围内进行搜索,而不是在整个二值图像中进行搜索,从而提高了搜索最近背景像素的速度;其次,在搜索出的距离第一像素最近的第一背景像素后,再计算第一背景像素与第一像素的第一完全距离,并不是搜索出一个背景像素后就计算该背景像素与第一像素的距离,从而减少了计算量,提高了计算速度,并且在整个搜索过程以及计算过程中都没有进行近似处理,所以计算得出的距离精确性高。It can be known from the above-mentioned technical solutions that, using the method for fast three-dimensional binary image complete distance transformation provided by the embodiment of the present invention, firstly, in the case of knowing the three-dimensional complete distance transformation of the second target pixel, it can be based on the second target phase pixel in The three-dimensional complete distance transformation value in the three-dimensional binary image determines the range of the first nearest background pixel of the first pixel, and then searches for the nearest background pixel from the first pixel, and searches within the range of the first nearest background pixel instead of Search in the entire binary image, thereby improving the speed of searching for the nearest background pixel; secondly, after searching out the first background pixel closest to the first pixel, then calculate the first background pixel and the first pixel. The complete distance does not calculate the distance between the background pixel and the first pixel after searching out a background pixel, thereby reducing the amount of calculation and improving the calculation speed, and no approximation is performed during the entire search process and calculation process, so The calculated distance has high accuracy.

附图说明 Description of drawings

为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据提供的附图获得其他的附图。In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings that need to be used in the description of the embodiments or the prior art. Obviously, the accompanying drawings in the following description are only It is an embodiment of the present invention, and those skilled in the art can also obtain other drawings according to the provided drawings without creative work.

图1为本发明实施例公开的第一种三维二值图像完全距离变换的方法的流程图;Fig. 1 is a flowchart of the first method for complete distance transformation of a three-dimensional binary image disclosed in an embodiment of the present invention;

图2为第一函数搜索二维二值图片中的第i行中距离O(x,y)最近的背景像素实际是搜索距离(i,y)最近的背景像素证的明过程图;Fig. 2 is the clear process diagram of the background pixel proof that the distance O (x, y) is actually the nearest background pixel of the search distance (i, y) in the i-th row in the first function search two-dimensional binary image;

图3为第一种第二最近背景像素范围示意图;Fig. 3 is a schematic diagram of the second closest background pixel range of the first type;

图4为第二种第二最近背景像素范围示意图;Fig. 4 is a schematic diagram of the range of the second closest background pixel of the second type;

图5为第三种第二最近背景像素范围示意图;Fig. 5 is a schematic diagram of the second closest background pixel range of the third type;

图6为在二维二值图片中距离第一像素最近的背景像素实际为距离第一像素在该二维二值图片中的投影像素最近的背景像素的证明图;Fig. 6 is a proof figure that the background pixel closest to the first pixel in the two-dimensional binary picture is actually the closest background pixel to the projection pixel of the first pixel in the two-dimensional binary picture;

图7为第一最近背景像素范围的示意图;Fig. 7 is a schematic diagram of the first nearest background pixel range;

图8为本发明实施例提供的一种分别计算分割的每一二维二值图片中各个像素的二维完全距离变换方法的流程示意图;Fig. 8 is a schematic flowchart of a two-dimensional complete distance transformation method for separately calculating each pixel in each segmented two-dimensional binary image provided by an embodiment of the present invention;

图9所示为第二最近背景像素的划分示意图;FIG. 9 is a schematic diagram of division of the second closest background pixel;

图10为本发明实施例提供的一种分别计算分割的每一二维二值图片中各个像素的二维完全距离变换方法的流程示意图;FIG. 10 is a schematic flowchart of a two-dimensional complete distance transformation method for separately calculating each pixel in each segmented two-dimensional binary image provided by an embodiment of the present invention;

图11为运用函数LR[x,y]与TD[x,y]搜索最近背景像素的示意图;Fig. 11 is a schematic diagram of searching for the nearest background pixel by using the functions LR[x, y] and TD[x, y];

图12为采用围线搜索方法搜索最近背景像素的示意图。FIG. 12 is a schematic diagram of searching for the nearest background pixel by using the contour search method.

具体实施方式 Detailed ways

下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only some, not all, embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by persons of ordinary skill in the art without making creative efforts belong to the protection scope of the present invention.

本发明所有实施例中的(x,y)和[x,y]中的x表示二维二值图片中的行,并不表示横坐标,(x,y)和[x,y]中的y表示二值图片中的列,并不表示纵坐标。例如像素(x0,y0)表示该像素在二值图片中的第x0行,第y0列。The x in (x, y) and [x, y] in all embodiments of the present invention represents the row in the two-dimensional binary picture, and does not represent the abscissa, and the x in (x, y) and [x, y] y represents the column in the binary image, not the ordinate. For example, the pixel (x 0 , y 0 ) represents the pixel's row x 0 and column y 0 in the binary image.

实施例一Embodiment one

请参阅附图1,为本发明实施例公开的第一种三维二值图像完全距离变换的方法的流程图,该方法可以包括:Please refer to accompanying drawing 1, it is the flow chart of the method for the first kind of three-dimensional binary image complete distance transformation that the embodiment of the present invention discloses, and this method can comprise:

步骤S101:将三维二值图像沿其中一轴分割成相应个数的二维二值图片;Step S101: dividing the three-dimensional binary image into a corresponding number of two-dimensional binary images along one of the axes;

具体的,沿着x轴,可将三维二值图像分割成m张二维二值图片,沿着y轴,可将三维二值图像分割成n张二维二值图片,沿着z轴,可将三维二值图像分割成s张二维二值图片。Specifically, along the x-axis, the three-dimensional binary image can be divided into m two-dimensional binary pictures; along the y-axis, the three-dimensional binary image can be divided into n two-dimensional binary pictures; along the z-axis, the three-dimensional binary The value image is divided into s two-dimensional binary images.

步骤S101为现有技术在此不作赘述。Step S101 is a prior art and will not be described in detail here.

步骤S102:分别计算分割的每一二维二值图片中各个像素的二维完全距离变换;Step S102: Calculate the two-dimensional complete distance transformation of each pixel in each segmented two-dimensional binary image;

可以利用现有技术中的完全距离变换方法计算每一二维二值图片中各个像素的完全距离变换。The complete distance transformation of each pixel in each two-dimensional binary image can be calculated by using the complete distance transformation method in the prior art.

优选的,计算一二维二值图片的距离变换(假设二维二值图片的尺寸为m×n,且m≥1,n≥1),首先计算第一行中(1,1)的完全距离变换,然后计算(1,2)的完全距离变换,按照从左到右的顺序依次计算至(1,n),再计算第二行中(2,1)的完全距离变换,从左向右依次计算至(2,n),也就是按照从左到右从上到下的顺序计算二值图片中每个像素的完全距离变换。Preferably, to calculate the distance transformation of a two-dimensional binary picture (assuming that the size of the two-dimensional binary picture is m×n, and m≥1, n≥1), first calculate the complete (1,1) in the first row Distance transformation, and then calculate the complete distance transformation of (1,2), calculate it in turn from left to right to (1,n), and then calculate the complete distance transformation of (2,1) in the second line, from left to right The right is calculated to (2,n) in turn, that is, the complete distance transformation of each pixel in the binary image is calculated in the order from left to right and top to bottom.

步骤S102可以包括:Step S102 may include:

S1021:确定第一函数或第二函数;S1021: Determine the first function or the second function;

步骤S1021是一个预处理步骤,不必每次都执行。Step S1021 is a preprocessing step and does not need to be executed every time.

第一函数用于确定二维二值图片第i行中距离第四像素最近的背景像素的位置,第二函数用于确定二维二值图片第j列中距离第四像素最近的背景像素的位置,其中,1≤i≤m,1≤j≤n,i与j均为整数。The first function is used to determine the position of the background pixel closest to the fourth pixel in row i of the two-dimensional binary image, and the second function is used to determine the position of the background pixel closest to the fourth pixel in column j of the two-dimensional binary image position, where, 1≤i≤m, 1≤j≤n, i and j are both integers.

假设第四像素位于二维二值图片的第x行,第y列,用(x,y)表示第四像素在二维二值图片的位置,以(x,y)为分界点,将第x行分为左侧和右侧,将第y列分为上方和下方。Assuming that the fourth pixel is located in the xth row and yth column of the two-dimensional binary image, use (x, y) to represent the position of the fourth pixel in the two-dimensional binary image, and use (x, y) as the dividing point, divide the first Row x is divided into left and right, and column y is divided into above and below.

确定第一函数的方法具体包括:The method for determining the first function specifically includes:

确定用于计算所述二维二值图片第x行左侧距离第四像素(x,y)最近的背景像素所在列数的第一子函数,及用于计算所述二维二值图片第x行右侧距离第四像素(x,y)最近的背景像素所在列数的第二子函数。其中,1≤x≤m,1≤y≤n。Determining the first sub-function used to calculate the column number of the background pixel closest to the fourth pixel (x, y) on the left side of the xth row of the two-dimensional binary picture, and used to calculate the first sub-function of the two-dimensional binary picture The second subfunction of the column number of the background pixel closest to the fourth pixel (x, y) on the right side of row x. Among them, 1≤x≤m, 1≤y≤n.

根据第一子函数及第二子函数,确定第一函数。The first function is determined according to the first sub-function and the second sub-function.

确定第二函数具体包括:确定用于计算所述二维二值图片第y列上方距离第四像素(x,y)最近的背景像素所在行数的第三子函数,及用于计算所述二维二值图片中第y列下方距离第四像素(x,y)最近的背景像素所在行数的第四子函数。Determining the second function specifically includes: determining a third sub-function for calculating the row number of the background pixel closest to the fourth pixel (x, y) above the yth column of the two-dimensional binary image, and for calculating the The fourth sub-function of the row number of the background pixel closest to the fourth pixel (x, y) below the y-th column in the two-dimensional binary image.

根据第三子函数及第四子函数,确定第二函数。The second function is determined according to the third sub-function and the fourth sub-function.

具体的,确定第一函数以及第二函数的第一种方法具体为:Specifically, the first method for determining the first function and the second function is specifically:

所述第一子函数具体为L[x,y]:The first sub-function is specifically L[x, y]:

LL [[ xx ,, ythe y ]] == ythe y II (( xx ,, ythe y )) == 00 LL [[ xx ,, ythe y -- 11 ]] II (( xx ,, ythe y )) == 11 ;;

若I(x,y)=1且y=1,那么L(x,y)=-Maxlable;If I(x, y)=1 and y=1, then L(x, y)=-Maxlable;

所述第二子函数具体为R[x,y]:The second sub-function is specifically R[x, y]:

RR [[ xx ,, ythe y ]] == ythe y II (( xx ,, ythe y )) == 00 RR [[ xx ,, ythe y ++ 11 ]] II (( xx ,, ythe y )) == 11 ;;

若I(x,y)=1且y=n,那么R[x,y]=Maxlable;If I(x, y)=1 and y=n, then R[x, y]=Maxlable;

则根据所述第一子函数及所述第二子函数确定的所述第一函数具体为SZ[x,y]:Then the first function determined according to the first sub-function and the second sub-function is specifically SZ[x, y]:

SZSZ [[ xx ,, ythe y ]] == LL [[ xx ,, ythe y ]] ythe y -- LL [[ xx ,, ythe y ]] << RR [[ xx ,, ythe y ]] -- ythe y RR [[ xx ,, ythe y ]] ythe y -- LL [[ xx ,, ythe y ]] &GreaterEqual;&Greater Equal; RR [[ xx ,, ythe y ]] -- ythe y ;;

所述第三子函数具体为T[x,y]:The third sub-function is specifically T[x, y]:

TT [[ xx ,, ythe y ]] == xx II (( xx ,, ythe y )) == 00 TT [[ xx -- 11 ,, ythe y ]] II (( xx ,, ythe y )) == 11 ;;

若I(x,y)=1且x=1,那么T[x,y]=-Maxlable;If I(x, y)=1 and x=1, then T[x, y]=-Maxlable;

所述第四子函数具体为D[x,y]:The fourth sub-function is specifically D[x, y]:

DD. [[ xx ,, ythe y ]] == xx II (( xx ,, ythe y )) == 00 DD. [[ xx ++ 11 ,, ythe y ]] II (( xx ,, ythe y )) == 11 ;;

若I(x,y)=1且x=m,那么D[x,y]=Maxlable;If I(x, y)=1 and x=m, then D[x, y]=Maxlable;

则根据所述第三子函数及所述第四子函数确定的所述第二函数具体为ZS[x,y]:Then the second function determined according to the third sub-function and the fourth sub-function is specifically ZS[x, y]:

ZSZS [[ xx ,, ythe y ]] == TT [[ xx ,, ythe y ]] xx -- DD. [[ xx ,, ythe y ]] << TT [[ xx ,, ythe y ]] -- xx DD. [[ xx ,, ythe y ]] xx -- DD. [[ xx ,, ythe y ]] &GreaterEqual;&Greater Equal; TT [[ xx ,, ythe y ]] -- xx ;;

确定第一函数以及第二函数的第二种方法具体为:The second method for determining the first function and the second function is specifically:

所述第一子函数具体为L[x,y]:The first sub-function is specifically L[x, y]:

LL [[ xx ,, ythe y ]] == ythe y II (( xx ,, ythe y )) == 00 LL [[ xx ,, ythe y -- 11 ]] II (( xx ,, ythe y )) == 11 ;;

若I(x,y)=1且y=1,那么L(x,y)=-Maxlable;If I(x, y)=1 and y=1, then L(x, y)=-Maxlable;

所述第二子函数具体为R[x,y]:The second sub-function is specifically R[x, y]:

RR [[ xx ,, ythe y ]] == ythe y II (( xx ,, ythe y )) == 00 RR [[ xx ,, ythe y ++ 11 ]] II (( xx ,, ythe y )) == 11 ;;

若I(x,y)=1且y=n,那么R[x,y]=Maxlable;If I(x, y)=1 and y=n, then R[x, y]=Maxlable;

则根据所述第一子函数及所述第二子函数确定的所述第一函数具体为LR[x,y]:Then the first function determined according to the first sub-function and the second sub-function is specifically LR[x, y]:

LRLR [[ xx ,, ythe y ]] == (( ythe y -- LL [[ xx ,, ythe y ]] )) 22 ythe y -- LL [[ xx ,, ythe y ]] << RR [[ xx ,, ythe y ]] -- ythe y (( RR [[ xx ,, ythe y ]] -- ythe y )) 22 ythe y -- LL [[ xx ,, ythe y ]] &GreaterEqual;&Greater Equal; RR [[ xx ,, ythe y ]] -- ythe y ;;

所述第三子函数具体为T[x,y]:The third sub-function is specifically T[x, y]:

TT [[ xx ,, ythe y ]] == xx II (( xx ,, ythe y )) == 00 TT [[ xx -- 11 ,, ythe y ]] II (( xx ,, ythe y )) == 11 ;;

若I(x,y)=1且x=1,那么T[x,y]=-Maxlable;If I(x, y)=1 and x=1, then T[x, y]=-Maxlable;

所述第四子函数具体为D[x,y]:The fourth sub-function is specifically D[x, y]:

DD. [[ xx ,, ythe y ]] == xx II (( xx ,, ythe y )) == 00 DD. [[ xx ++ 11 ,, ythe y ]] II (( xx ,, ythe y )) == 11 ;;

若I(x,y)=1且x=m,那么D[x,y]=Maxlable;If I(x, y)=1 and x=m, then D[x, y]=Maxlable;

则根据所述第三子函数及所述第四子函数确定的所述第二函数具体为TD[x,y]:Then the second function determined according to the third sub-function and the fourth sub-function is specifically TD[x,y]:

TDTD [[ xx ,, ythe y ]] == (( xx -- TT [[ xx ,, ythe y ]] )) 22 xx -- TT [[ xx ,, ythe y ]] << DD. [[ xx ,, ythe y ]] -- xx (( DD. [[ xx ,, ythe y ]] -- xx )) 22 xx -- TT [[ xx ,, ythe y ]] &GreaterEqual;&Greater Equal; DD. [[ xx ,, ythe y ]] -- xx ..

其中,I(x,y)=1表示为目标像素,I(x,y)=0表示为背景像素,Maxlable为预设最大标记值,其中, Maxlable = ( 1 + 2 ) max ( m , n ) . Among them, I(x, y)=1 represents the target pixel, I(x, y)=0 represents the background pixel, and Maxlable is the preset maximum mark value, where, Maxlable = ( 1 + 2 ) max ( m , no ) .

S1022:根据第三目标像素与第四像素的完全距离,及第三目标像素与离其最近背景像素的二维完全距离,确定第四像素的第二最近背景像素范围。S1022: Determine the second closest background pixel range of the fourth pixel according to the complete distance between the third target pixel and the fourth pixel, and the two-dimensional complete distance between the third target pixel and its nearest background pixel.

其中,第四像素与第三目标像素均位于同一二维二值图片中;Wherein, both the fourth pixel and the third target pixel are located in the same two-dimensional binary image;

为了提高计算速度,在确定第二背景像素范围之前,还可以包括:In order to improve the calculation speed, before determining the second background pixel range, it may also include:

计算LR[x,y];在LR[x,y]不大于1的情况下,所述第一完全距离为LR[x,y],在LR[x,y]大于1的情况下,执行确定第二最近背景像素范围步骤。Calculate LR[x,y]; when LR[x,y] is not greater than 1, the first complete distance is LR[x,y], and when LR[x,y] is greater than 1, execute Determine the second closest background pixel range step.

或者,计算TD[x,y];在TD[x,y]不大于1的情况下,第二完全距离为TD[x,y],在TD[x,y]大于1的情况下,执行确定第二最近背景像素范围步骤。Or, calculate TD[x,y]; when TD[x,y] is not greater than 1, the second complete distance is TD[x,y], and when TD[x,y] is greater than 1, execute Determine the second closest background pixel range step.

若LR(x,y)=0或者TD[x,y]=0则说明第四像素(x,y)是背景像素。若LR(x,y)=1则说明第四像素(x,y)的水平2邻域中存在背景像素,即第二完全距离为1,如果TD[x,y]=1则说明第四像素(x,y)的垂直2邻域中存在背景像素,即第二完全距离为1。If LR(x,y)=0 or TD[x,y]=0, it means that the fourth pixel (x,y) is a background pixel. If LR(x, y)=1, it means that there is a background pixel in the horizontal 2 neighborhood of the fourth pixel (x, y), that is, the second complete distance is 1; if TD[x, y]=1, it means that the fourth pixel (x, y) has a background pixel There are background pixels in the vertical 2-neighborhood of pixel (x,y), i.e. the second complete distance is 1.

在确定第二背景像素范围之前,还可以包括:Before determining the second background pixel range, it may also include:

计算(y-SZ[x,y])2;在(y-SZ[x,y])2不大于1的情况下,第二完全距离为(y-SZ[x,y])2,在(y-SZ[x,y])2大于1的情况下,执行确定第二最近背景像素范围步骤。Calculate (y-SZ[x,y]) 2 ; when (y-SZ[x,y]) 2 is not greater than 1, the second complete distance is (y-SZ[x,y]) 2 , in When (y-SZ[x,y]) 2 is greater than 1, perform the step of determining the second nearest background pixel range.

或,计算(x-ZS[x,y])2;在(x-ZS[x,y])2不大于1的情况下,第二完全距离为(x-ZS[x,y])2,在(x-ZS[x,y])2大于1的情况下,执行确定第二最近背景像素范围步骤。Or, calculate (x-ZS[x,y]) 2 ; if (x-ZS[x,y]) 2 is not greater than 1, the second complete distance is (x-ZS[x,y]) 2 , when (x-ZS[x,y]) 2 is greater than 1, execute the step of determining the second nearest background pixel range.

利用第一函数分别在第二最近背景像素范围的每行中搜索距离第四像素最近的背景像素,或利用第二函数分别在第二最近背景像素范围的每列中搜索距离第四像素最近的背景像素;Use the first function to search for the background pixel closest to the fourth pixel in each row of the second closest background pixel range, or use the second function to search for the closest background pixel to the fourth pixel in each column of the second closest background pixel range background pixels;

从搜索出的距离第四像素最近的背景像素中确定出与第四像素距离最近的第二背景像素,计算第二背景像素与第四像素的第二完全距离,并将第二完全距离作为第四像素在其所在的二维二值图片中的二维完全距离变换值。Determine the second background pixel closest to the fourth pixel from the searched background pixels closest to the fourth pixel, calculate the second complete distance between the second background pixel and the fourth pixel, and use the second complete distance as the first The 2D full distance transformed value of the quadpixel in its 2D binary image.

第四像素可以是位于二维二值图片中的任一像素,只是为了叙述方便才称任一像素为第四像素。The fourth pixel may be any pixel located in the two-dimensional binary image, and any pixel is called the fourth pixel only for the convenience of description.

当第四像素为背景像素时,距离第四像素最近的背景像素就是其本身。When the fourth pixel is a background pixel, the background pixel closest to the fourth pixel is itself.

假设上述第四像素在二维二值图片中的位置为(x,y),由于第一子函数是用于计算二维二值图片第x行左侧距离任一像素(x,y)最近的背景像素所在的列数,第二子函数用于计算二维二值图片第x行右侧距离任一像素(x,y)最近的背景像素所在的列数,所以根据第一子函数与第二子函数得到的SZ[x,y]也是用于确定第x行上距离任一像素(x,y)最近的背景像素所在的列数。Assuming that the position of the fourth pixel in the two-dimensional binary image is (x, y), since the first sub-function is used to calculate the distance from the left side of row x of the two-dimensional binary image to any pixel (x, y) closest The number of columns of the background pixels of the two-dimensional binary image, the second sub-function is used to calculate the number of columns of the background pixel that is closest to any pixel (x, y) on the right side of row x of the two-dimensional binary image, so according to the first sub-function and The SZ[x, y] obtained by the second sub-function is also used to determine the column number of the background pixel closest to any pixel (x, y) on the xth row.

用O(x,y)表示上述第四像素,利用第一函数搜索第i行(i≠x)中距离O(x,y)最近的背景像素,其实就是利用第一函数搜索第i行中距离(i,y)最近的背景像素,所以在执行步骤S102时,实际上是将第一函数SZ[x,y]中x替换成i的函数SZ[i,y]进行搜索,函数SZ[i,y]实际上是搜索在第i行中距离(i,y)最近的背景像素,由于在第i行中距离(i,y)最近的背景像素就是距离O(x,y)最近的背景像素,所以函数SZ[i,y]本质上还是用于搜索各行中距离O(x,y)最近的背景像素。Use O(x,y) to represent the above fourth pixel, use the first function to search for the background pixel closest to O(x,y) in the i-th row (i≠x), in fact, use the first function to search for the i-th row The background pixel closest to (i, y), so when step S102 is executed, the function SZ[i, y] that replaces x in the first function SZ[x, y] with i is actually searched, and the function SZ[ i, y] actually searches for the background pixel closest to (i, y) in line i, since the background pixel closest to (i, y) in line i is the closest to O(x, y) Background pixels, so the function SZ[i,y] is essentially used to search for the background pixel closest to O(x,y) in each row.

如图2所示,证明过程如下:假设L1,L2,R1,R2为第i行上的四个背景像素,它们与O(x,y)的距离分别为|OL1|,|OL2|,|OR1|,|OR2|,由几何知识可知距O(x,y)最近的背景像素显然就是距离(i,y)最近的背景像素,第i行中距离O(x,y)最近的背景像素的位置为(i,SZ[i,y])。As shown in Figure 2, the proof process is as follows: Suppose L 1 , L 2 , R 1 , R 2 are the four background pixels on the i-th row, and their distances from O(x, y) are |OL 1 |, |OL 2 |, |OR 1 |, |OR 2 |, it can be seen from geometric knowledge that the background pixel closest to O(x,y) is obviously the background pixel closest to (i,y), and the distance from O( x,y) The position of the nearest background pixel is (i,SZ[i,y]).

同理,利用第二函数搜索第j列(j≠y)中距O(x,y)最近的背景像素,其实就是利用第二函数搜索第j列中距离(x,j)最近的背景像素,所以在执行步骤S102时,实际上是将第二函数ZS[x,y]中y替换成j的函数ZS[x,j]进行搜索,第j列中距离O(x,y)最近的背景像素的位置为(ZS[x,j],j)。其中,1≤i≤m,1≤j≤n,i与j均为正整数。Similarly, using the second function to search for the background pixel closest to O(x, y) in the jth column (j≠y) is actually using the second function to search for the background pixel closest to (x, j) in the jth column , so when step S102 is executed, the function ZS[x,j] that replaces y in the second function ZS[x,y] with j is actually used for searching, and the closest distance to O(x,y) in the jth column The position of the background pixel is (ZS[x,j],j). Wherein, 1≤i≤m, 1≤j≤n, i and j are both positive integers.

确定第二最近背景像素范围具体包括:Determining the second nearest background pixel range specifically includes:

首先,计算第三目标像素O3与离其最近背景像素B0的二维完全距离r3First, calculate the two-dimensional complete distance r 3 between the third target pixel O 3 and the nearest background pixel B 0 ;

其次,确定第四像素O4与第三目标像素O3的完全距离r4Second, determine the complete distance r 4 between the fourth pixel O 4 and the third target pixel O 3 ;

计算完全距离r3可以通过现有技术中的方法计算。距离第三目标像素O3最近的背景像素可能有多个,根据实际情况只取其中一个背景像素B0即可。The calculated complete distance r 3 can be calculated by methods in the prior art. There may be multiple background pixels closest to the third target pixel O 3 , and only one of the background pixels B 0 can be selected according to the actual situation.

优选的,第四像素O4位于第三目标像素O3的四邻域内,这样第四像素O4与第三目标像素O3的完全距离r4=1。当然,第四像素O4的位置不限制于第三目标像素O3的四领域内,第四像素O4的具体位置并不影响本发明实施例的实现,所以不对第四像素O4的具体位置做具体限定。Preferably, the fourth pixel O 4 is located within the four-neighborhood of the third target pixel O 3 , so that the complete distance r 4 =1 between the fourth pixel O 4 and the third target pixel O 3 . Of course, the position of the fourth pixel O4 is not limited to the four areas of the third target pixel O3 , and the specific position of the fourth pixel O4 does not affect the implementation of the embodiment of the present invention, so the specific position of the fourth pixel O4 is not discussed. The location is specifically limited.

最后,根据完全距离r3以及完全距离r4确定第四像素O4的第二最近背景像素范围。Finally, the second nearest background pixel range of the fourth pixel O4 is determined according to the complete distance r3 and the complete distance r4 .

参见图3,为第一种第二最近背景像素范围示意图,图中的圆O4为以第四像素为圆心,以r3+r4为半径的圆O4,由于数字图像具有离散性,确定出精确的以圆弧为边界的圆形区域是十分耗时的,所以第二最近背景像素范围是圆O4的外切正方形所围成的区域。Referring to Fig. 3, it is a schematic diagram of the range of the second closest background pixel of the first type. The circle O 4 in the figure is a circle O 4 with the fourth pixel as the center and r 3 +r 4 as the radius. Due to the discrete nature of digital images, It is very time-consuming to determine the exact circular area bounded by the arc, so the second closest background pixel range is the area enclosed by the circumscribed square of the circle O 4 .

参见图4,为第二种第二最近背景像素范围示意图,第二最近背景像素范围为以所述第三目标像素O3为圆心,以r3为半径的圆O5的内接正方形与圆O4的外切正方形所围成的区域;Referring to FIG. 4 , it is a schematic diagram of the second closest background pixel range of the second type. The second closest background pixel range is the inscribed square and circle of the circle O5 with the third target pixel O3 as the center and r3 as the radius The area enclosed by the circumscribed square of O 4 ;

参见图5,为第三种第二最近背景像素范围示意图,第二最近背景像素范围为圆O6的外切正方形与圆O4的内接正方形所围成的环形区域。Referring to FIG. 5 , it is a schematic diagram of the second closest background pixel range of the third type. The second closest background pixel range is an annular area surrounded by the circumscribed square of circle O6 and the inscribed square of circle O4 .

圆O6是以所述第四像素为圆心,以|r3-r4|为半径的圆。Circle O 6 is a circle with the fourth pixel as the center and |r 3 -r 4 | as the radius.

如果第四像素位于二维二值图片的边缘位置,在确定第二最近背景像素范围时,初始确定的第二最近背景像素范围可能会有一部分超出二维二值图片,此时可以取确定的初始第二最近背景像素范围与二维二值图片的交集作为第二最近背景像素范围。If the fourth pixel is located at the edge position of the two-dimensional binary image, when determining the second nearest background pixel range, part of the initially determined second closest background pixel range may exceed the two-dimensional binary image, and at this time the determined The intersection of the initial second closest background pixel range and the two-dimensional binary image is used as the second closest background pixel range.

步骤S103:根据第二目标像素与第一像素的完全距离,及所述第二目标像素在三维二值图像中的三维完全距离变换值,确定第一像素的第一最近背景像素范围;Step S103: According to the complete distance between the second target pixel and the first pixel, and the three-dimensional complete distance transformation value of the second target pixel in the three-dimensional binary image, determine the first nearest background pixel range of the first pixel;

第二目标像素是三维二值图像中任一目标像素。The second target pixel is any target pixel in the three-dimensional binary image.

确定第一最近背景像素范围可以包括:Determining the first closest background pixel range may include:

确定第二目标像素在三维二值图像中的三维完全距离变换值为r1Determine the three-dimensional complete distance transformation value r 1 of the second target pixel in the three-dimensional binary image;

确定第一像素O1与第二目标像素O2的完全距离r2determining the complete distance r 2 between the first pixel O 1 and the second target pixel O 2 ;

第一最近背景像素范围为以第一像素O1为球心,以r1+r2为半径的球O1的外切正方体所围成的区域;The first closest background pixel range is the area surrounded by the circumscribed cube of the ball O 1 with the first pixel O 1 as the center and r 1 +r 2 as the radius;

或,第一最近背景像素范围为以第二目标像素O2为球心,以r1为半径的球O2的内接正方体与球O1的外切正方体所围成的区域;Or, the first closest background pixel range is the area surrounded by the inscribed cube of the ball O2 and the circumscribed cube of the ball O1 with the second target pixel O2 as the center of the sphere and r1 as the radius;

或,第一最近背景像素范围为以所述第一像素O1为球心,以|r1-r2|为半径的球O3的内接正方体与所述球O1的外切正方体所围成的区域。Or, the range of the first closest background pixel is defined by the inscribed cube of the ball O3 with the first pixel O1 as the center and the radius | r1 - r2 | and the circumscribed cube of the ball O1 enclosed area.

如果第一像素位于三维二值图像的边缘位置,在确定第一最近背景像素范围时,初始确定的第一最近背景像素范围可能会有一部分超出三维二值图像,此时可以取确定的初始第一最近背景像素范围与三维二值图像的交集作为第一最近背景像素范围。If the first pixel is located at the edge of the three-dimensional binary image, when determining the first nearest background pixel range, part of the initially determined first closest background pixel range may exceed the three-dimensional binary image. An intersection of the closest background pixel range and the three-dimensional binary image is used as the first closest background pixel range.

步骤S104:确定第一像素分别在第一最近背景像素范围中的各个二维二值图片中的投影像素的二维完全距离变换值;Step S104: Determine the two-dimensional complete distance transformation values of the projected pixels of the first pixel in each two-dimensional binary picture in the range of the first closest background pixel;

请参阅图6,假设像素O(x,y,z)为二维二值图片z上的一个目标像素,像素O0(x,y,z0)为O(x,y,z)在二维二值图片z0上的投影像素,设在二维二值图片z0上距像素O0(x,y,z0)最近的背景像素B0与像素O0(x,y,z0)的二维完全距离变换值的平方为|O0B0|2,那么二维二值图片z0上距像素O(x,y,z)最近的背景像素显然也为B0,且 | OB 0 | = | O 0 B 0 | 2 + | O O 0 | 2 . Please refer to Figure 6, assuming that pixel O(x,y,z) is a target pixel on the two-dimensional binary image z, pixel O 0 (x,y,z 0 ) is O(x,y,z) in two The projection pixel on the two-dimensional binary image z 0 is set to the background pixel B 0 closest to the pixel O 0 (x , y,z 0 ) and the pixel O 0 (x,y,z 0 ) on the two-dimensional binary image z 0 ) is |O 0 B 0 | 2 , then the background pixel closest to pixel O(x,y,z) on the two-dimensional binary image z 0 is obviously also B 0 , and | OB 0 | = | o 0 B 0 | 2 + | o o 0 | 2 .

假设三维二值图像沿z轴分割成s张二维二值图片,第一最近背景像素范围为以第一像素O1为球心,以r1+r2为半径的球O1的外切正方体所围成的区域,请参阅图7,为第一最近背景像素范围的示意图,图7中的r=r1+r2,B为球O1上的一个像素,图中用O表示O1,由图7可以看出第一最近背景像素范围可以看做是由2(r1+r2)+1张图片沿z轴叠加而成的,假设第一像素O1所在的二维二值图片为z0,优选的,首先确定二维二值图片z0中第一像素的二维完全距离变换值(此时第一像素在二维二值图片z0上的投影像素就是其本身),其次确定第一像素分别在二维二值图片z0±1中投影像素的二维完全距离变换值,再确定第一像素分别在二维二值图片z0±2中投影像素的二维完全距离变换值,直至二维二值图片z0±(r1+r2)。即以二维二值图片z0为对称中心沿z轴方向从里到外依次分别确定第一像素在各个二维二值图片中的投影像素的二维完全距离变换值,假设在二维二值图片z0+rx上确定出第一像素在二维二值图片z0+rx中的投影像素的二维完全距离变化值的平方为DRx 2,rx∈[-(r1+r2),r1+r2],由于在二维二值图片z0±(rx+1)中距离第一像素最近的背景像素与第一像素的距离平方的最小值为(rx+1)2,所以当DRx 2+rx 2≤(rx+1)2时,停止确定第一像素分别在二维二值图片z0±(rx+2)直至二维二值图片z0±(r1+r2)中的投影像素的二维完全距离变换值,如果DRx 2+rx 2>(rx+1)2,则继续确定第一像素分别在二值图片z0±(rx+2)中的投影像素的二维完全距离变换值,直至到二维二值图片z0±(r1+r2)。Assuming that the 3D binary image is divided into s two-dimensional binary images along the z-axis, the range of the first closest background pixel is defined by the circumscribed cube of the ball O 1 with the first pixel O 1 as the center and r 1 +r 2 as the radius For the enclosed area, please refer to Figure 7, which is a schematic diagram of the range of the first nearest background pixel, r=r 1 +r 2 in Figure 7, B is a pixel on the ball O 1 , O 1 is represented by O in the figure, It can be seen from Figure 7 that the range of the first closest background pixel can be regarded as being formed by superimposing 2(r 1 +r 2 )+1 pictures along the z-axis, assuming the two-dimensional binary picture where the first pixel O 1 is located is z 0 , preferably, first determine the two-dimensional complete distance transformation value of the first pixel in the two-dimensional binary image z 0 (at this time, the projected pixel of the first pixel on the two-dimensional binary image z 0 is itself), Secondly, determine the two-dimensional complete distance transformation value of the first pixel projected in the two-dimensional binary image z 0 ±1, and then determine the two-dimensional complete distance transformation value of the first pixel projected in the two-dimensional binary image z 0 ±2 The distance transformation value until the two-dimensional binary image z 0 ±(r 1 +r 2 ). That is, take the two-dimensional binary picture z 0 as the symmetric center and determine the two-dimensional complete distance transformation values of the projected pixels of the first pixel in each two-dimensional binary picture sequentially along the z-axis direction from the inside to the outside. The square of the two-dimensional complete distance change value of the projected pixel of the first pixel in the two-dimensional binary image z 0 +r x determined on the value picture z 0 +r x is DR x 2 , r x ∈ [-(r 1 +r 2 ),r 1 +r 2 ], since in the two-dimensional binary image z 0 ±(r x +1), the minimum value of the square of the distance between the background pixel closest to the first pixel and the first pixel is (r x +1) 2 , so when DR x 2 +r x 2 ≤(r x +1) 2 , stop determining the first pixel in the two-dimensional binary image z 0 ±(r x +2) until two-dimensional two value picture z 0 ±(r 1 +r 2 ) the two-dimensional complete distance transformation value of the projection pixel, if DR x 2 +r x 2 >(r x +1) 2 , continue to determine the first pixel in the two The two-dimensional complete distance transformed values of the projected pixels in the value image z 0 ±(r x +2) until the two-dimensional binary image z 0 ±(r 1 +r 2 ).

第一最近背景像素范围可以看做是由2(r1+r2)+1张图片沿z轴叠加而成的,而很有可能某张二维二值图片中距离第一像素的投影像素最近的背景像素不在第一最近背景像素范围内,但是这并不影响本发明实施例的实现,所以在此不作区分。The range of the first closest background pixel can be regarded as the superposition of 2(r 1 +r 2 )+1 pictures along the z-axis, and it is very likely that the projected pixel closest to the first pixel in a two-dimensional binary picture The background pixel is not within the range of the first closest background pixel, but this does not affect the implementation of the embodiment of the present invention, so no distinction is made here.

步骤S105:根据确定的第一像素分别在第一背景像素中各个二维二值图像的投影像素的二维完全距离变换值,确定出在三维二值图像中距离第一像素最近的第一背景像素,计算第一背景像素与第一像素的第一完全距离,并将此第一完全距离作为第一像素的三维完全距离变换值。Step S105: Determine the first background closest to the first pixel in the three-dimensional binary image according to the determined two-dimensional complete distance transformation values of the first pixels in the first background pixels of the projected pixels of each two-dimensional binary image pixels, calculating a first complete distance between the first background pixel and the first pixel, and using the first complete distance as a three-dimensional complete distance transformation value of the first pixel.

假设第一像素在三维二值图像中的位置为(x,y,z),由于每一二维二值图片中的各个像素的二维完全距离都已经计算出,假设DRx表示从二维二值图像zx中距离第一像素在二维二值图像zx中投影像素最近的背景像素的平方值,其中角标x表示第一像素的投影像素在二维二值图像zx上,那么步骤S105具体包括:Suppose the position of the first pixel in the three-dimensional binary image is (x, y, z), since the two-dimensional complete distance of each pixel in each two-dimensional binary image has been calculated, assuming that DR x represents the distance from the two-dimensional The square value of the background pixel closest to the first pixel in the two-dimensional binary image z x in the binary image z x , where the superscript x indicates that the projected pixel of the first pixel is on the two-dimensional binary image z x , Then step S105 specifically includes:

利用公式min{DRx 2+|zx-z|2},其中zx∈第一最近背景像素范围中z轴的取值范围,确定出与第一像素距离最近的第一背景像素,再利用公式得到第一完全距离。Using the formula min{DR x 2 +|z x -z| 2 }, where z x ∈ the value range of the z-axis in the range of the first nearest background pixel, determine the first background pixel closest to the first pixel, and then use the formula Get the first complete distance.

优选的,计算每一二维二值图片中各个像素的三维完全距离变换时,假设三维二值图像沿z轴分割成s张二维二值图片,这s张二维二值图片在z轴中的范围是[1,s],则首先从二维二值图片z=1计算各个二维二值图片中各个像素的三维完全距离变换,其次,计算二维二值图片z=2中各个像素的三维完全距离变换,再计算二维二值图片z=3中各个像素的三维完全距离变换,依次类推直至计算完二维二值图片z=s中各个像素的三维完全距离变换,即由二维二值图片中z的最小值计算至z的最大值。Preferably, when calculating the three-dimensional complete distance transformation of each pixel in each two-dimensional binary image, it is assumed that the three-dimensional binary image is divided into s two-dimensional binary images along the z-axis, and the range of these s two-dimensional binary images in the z-axis is [1, s], then first calculate the three-dimensional complete distance transform of each pixel in each two-dimensional binary picture z=1 from the two-dimensional binary picture z=1, secondly, calculate the three-dimensional complete distance transformation of each pixel in the two-dimensional binary picture z=2 Distance transformation, and then calculate the three-dimensional complete distance transformation of each pixel in the two-dimensional binary image z=3, and so on until the three-dimensional complete distance transformation of each pixel in the two-dimensional binary image z=s is calculated, that is, the two-dimensional binary image z=s The minimum value of z in the picture is calculated to the maximum value of z.

采用本发明实施例提供的快速三维二值图像完全距离变换的方法,首先在已知第二目标像素的三维完全距离变换的情况下,可以根据第二目标相像素在三维二值图像中的三维完全距离变换值,确定第一像素的第一最近背景像素范围,再搜索距离第一像素的最近背景像素时,是在第一最近背景像素范围内进行搜索,而不是在整个二值图像中进行搜索,从而提高了搜索最近背景像素的速度;其次,在搜索出的距离第一像素最近的第一背景像素后,再计算第一背景像素与第一像素的第一完全距离,并不是搜索出一个背景像素后就计算该背景像素与第一像素的距离,从而减少了计算量,提高了计算速度,并且在整个搜索过程以及计算过程中都没有进行近似处理,所以计算得出的距离精确性高。Using the method for fast three-dimensional binary image complete distance transformation provided by the embodiment of the present invention, firstly, under the condition that the three-dimensional complete distance transformation of the second target pixel is known, the three-dimensional distance transformation of the second target phase pixel in the three-dimensional binary image can be Complete distance transformation value, determine the first closest background pixel range of the first pixel, and then search for the closest background pixel to the first pixel, it is searched within the first closest background pixel range, not in the entire binary image Search, thereby improving the speed of searching for the nearest background pixel; secondly, after searching out the first background pixel closest to the first pixel, then calculating the first complete distance between the first background pixel and the first pixel is not to search for the first background pixel After one background pixel, the distance between the background pixel and the first pixel is calculated, thereby reducing the amount of calculation and improving the calculation speed, and no approximation is performed during the entire search process and calculation process, so the calculated distance is accurate high.

实施例二Embodiment two

请参阅图8,为本发明实施例提供的一种分别计算分割的每一二维二值图片中各个像素的二维完全距离变换方法的流程示意图,即实施例一中步骤S102的实现方法,该方法可以包括:Please refer to FIG. 8 , which is a schematic flowchart of a two-dimensional complete distance transformation method for separately calculating each pixel in each segmented two-dimensional binary image provided by the embodiment of the present invention, that is, the implementation method of step S102 in the first embodiment, The method can include:

步骤S801:根据第三目标像素与第四像素的完全距离,及第三目标像素与离其最近背景像素的距离,确定第四像素的第二最近背景像素范围,并将第二最近背景像素范围按照预设规则划分为第一子最近背景像素范围集以及第二子最近背景像素范围集,第一子最近背景像素范围集包括至少一个第一子最近背景像素范围,所述至少一个子最近背景像素范围中的行数不大于列数,第二子最近背景像素范围集包括至少一个第二子最近背景像素范围,所述至少一个第二子最近背景像素范围中的行数大于列数;Step S801: According to the complete distance between the third target pixel and the fourth pixel, and the distance between the third target pixel and its nearest background pixel, determine the second closest background pixel range of the fourth pixel, and set the second closest background pixel range According to preset rules, it is divided into a first sub-nearest background pixel range set and a second sub-nearest background pixel range set, the first sub-nearest background pixel range set includes at least one first sub-nearest background pixel range, and the at least one sub-nearest background pixel range The number of rows in the pixel range is not greater than the number of columns, the second sub-nearest background pixel range set includes at least one second sub-nearest background pixel range, and the number of rows in the at least one second sub-nearest background pixel range is greater than the number of columns;

在步骤S801之前还包括:计算LR[x,y]以及TD[x,y];在LR[x,y]或者TD[x,y]Before step S801, it also includes: calculating LR[x, y] and TD[x, y]; in LR[x, y] or TD[x, y]

不大于1的情况下,所述第二完全距离为min{LR[x,y],TD[x,y]},在LR[x,y]When not greater than 1, the second complete distance is min{LR[x,y],TD[x,y]}, in LR[x,y]

以及TD[x,y]均大于1的情况下,进入步骤S802。And when both TD[x, y] are greater than 1, go to step S802.

若LR(x,y)=0或者TD[x,y]=0则说明第四像素(x,y)是背景像素。若LR(x,y)=1则说明第四像素(x,y)的水平2邻域中存在背景像素,即第二完全距离为1,如果TD[x,y]=1则说明第四像素(x,y)的垂直2邻域中存在背景像素,即第二完全距离为1。If LR(x,y)=0 or TD[x,y]=0, it means that the fourth pixel (x,y) is a background pixel. If LR(x,y)=1, it means that there is a background pixel in the horizontal 2 neighborhood of the fourth pixel (x,y), that is, the second complete distance is 1, and if TD[x,y]=1, it means that the fourth There are background pixels in the vertical 2-neighborhood of pixel (x,y), i.e. the second complete distance is 1.

第二最近背景像素范围如图4或者图5所示的第二最近背景像素范围,将内接正方形的一对边的线段延长至与外切正方形的边界相交,这里以第二种第二最近背景像素范围为例进行划分,如图9所示,为第二最近背景像素的划分示意图,点划线是圆O3内接正方形一对边的延长线,该对边将第二最近背景像素范围分成上下左右四个子最近背景像素范围,称之为上方区域、下方区域、左方区域以及右方区域,显然在上方区域与下方区域中行数小于列数,在左方区域和右方区域中列数小于行数。当然,也可以用圆O3内接正方形另一对边的延长线,将最近背景像素范围分成上下左右四个区域。The second nearest background pixel range as shown in Figure 4 or Figure 5, extends the line segment of a pair of sides inscribed in the square to intersect with the boundary of the circumscribed square, here the second nearest The background pixel range is divided as an example, as shown in Figure 9, which is a schematic diagram of the division of the second nearest background pixel, the dotted line is the extension of a pair of sides of a square inscribed in the circle O3 , and the pair of sides divides the second nearest background pixel The range is divided into four sub-closest background pixel ranges, namely upper, lower, left, and right areas. Obviously, the number of rows in the upper and lower areas is less than the number of columns, and in the left and right areas The number of columns is less than the number of rows. Of course, the extension line of the other opposite side of the square may also be inscribed by the circle O 3 to divide the range of the nearest background pixel into four areas: upper, lower, left, and right.

预设规则是指将圆O3内接正方形的一对边的线段延长至与外切正方形的边界相交,该对边将第二最近背景像素范围分成上下左右四个子最近背景像素范围。The default rule is to extend the line segment of a pair of sides of the inscribed square of the circle O3 to intersect with the boundary of the circumscribed square. The pair of sides divides the second closest background pixel range into four sub-closest background pixel ranges: upper, lower, left, and right.

第一子最近背景像素范围集包括:上方区域以及下方区域;第二子最近背景像素范围集包括:左方区域以及右方区域。The first sub-nearest background pixel range set includes: an upper area and a lower area; the second sub-nearest background pixel range set includes: a left area and a right area.

步骤S802:利用第一函数在第一子最近背景像素范围集的每行中搜索距离第四像素最近的背景像素,利用第二函数在第二子最近背景像素范围集的每列中搜索距离第四像素最近的背景像素;Step S802: Use the first function to search for the background pixel closest to the fourth pixel in each row of the first sub-nearest background pixel range set, and use the second function to search for the background pixel closest to the fourth pixel in each column of the second sub-nearest background pixel range set. the four-pixel nearest background pixel;

在第一子最近背景像素范围集的行数不大于列数时,利用第一函数进行搜索,所用的搜索时间少,在第二子最近背景像素范围集的行数大于列数时,利用第二函数进行搜索,所用的搜索时间少。When the number of rows in the first sub-nearest background pixel range set is not greater than the number of columns, use the first function to search, and the search time is less; when the number of rows in the second sub-nearest background pixel range set is greater than the number of columns, use the second function The second function is used to search, and the search time used is less.

步骤S803:从搜索出的距离第四像素最近的背景像素中确定出与第四像素距离最近的第二背景像素,计算第二背景像素与第四像素的第二完全距离,并将此第二完全距离作为第四像素的二维完全距离变换值。Step S803: Determine the second background pixel closest to the fourth pixel from the searched background pixels closest to the fourth pixel, calculate the second complete distance between the second background pixel and the fourth pixel, and calculate the second full distance as the 2D full distance transformed value of the fourth pixel.

采用本发明实施例,由于对第二最近背景像素范围按照预定规则进行了划分,由于第一子最近背景像素范围集的行数不大于列数,利用第一函数在第一子最近背景像素范围集的每行中搜索距离第四像素最近的背景像素,由于第二子最近背景像素范围集的行数大于列数,利用第二函数在第二子最近背景像素范围集的每列中搜索距离第四像素最近的背景像素,更加快了搜索速度,从而提高了计算速度。According to the embodiment of the present invention, since the second nearest background pixel range is divided according to predetermined rules, since the number of rows of the first sub-nearest background pixel range set is not greater than the number of columns, the first function is used in the first sub-nearest background pixel range Search for the background pixel closest to the fourth pixel in each row of the set, because the number of rows in the second sub-nearest background pixel range set is greater than the number of columns, use the second function to search for the distance in each column of the second sub-nearest background pixel range set The nearest background pixel of the fourth pixel accelerates the search speed, thereby improving the calculation speed.

实施例三Embodiment Three

请参阅图10,为本发明实施例提供的一种分别计算分割的每一二维二值图片中各个像素的二维完全距离变换方法的流程示意图,即实施例一中步骤S102实现方法,该方法可以包括:Please refer to FIG. 10 , which is a schematic flowchart of a two-dimensional complete distance transformation method for separately calculating each pixel in each segmented two-dimensional binary image provided by the embodiment of the present invention, that is, the implementation method of step S102 in the first embodiment. Methods can include:

步骤S1001:根据第三目标像素与第四像素的完全距离,及第三目标像素与离其最近背景像素的二维完全距离,确定第四像素的第二最近背景像素范围;Step S1001: According to the complete distance between the third target pixel and the fourth pixel, and the two-dimensional complete distance between the third target pixel and its nearest background pixel, determine the second closest background pixel range of the fourth pixel;

步骤S1002:利用第一函数以及第二函数分别在第二最近背景像素范围的每层中搜索距离第四像素最近的背景像素;Step S1002: using the first function and the second function to search for the background pixel closest to the fourth pixel in each layer of the second closest background pixel range;

第二最近背景像素范围的每层是指以所述第四像素或者所述第三目标像素为中心的正方形的边界。Each layer of the second closest background pixel range refers to a boundary of a square centered on the fourth pixel or the third target pixel.

具体的,利用第一函数以及第二函数从第rx层开始搜索直至在第rx+k层搜索到距离第四像素最近的背景像素,第rx层是最近背景像素范围内距离第四像素最近的一层,k=0,1,2…q-1,第二最近背景像素范围内一共有q层;Specifically, use the first function and the second function to start searching from the rxth layer until the rx +kth layer searches for the background pixel closest to the fourth pixel, and the rxth layer is the fourth pixel within the range of the nearest background pixel. The nearest layer of pixels, k=0,1,2...q-1, there are a total of q layers within the range of the second closest background pixel;

从在第rx+k层搜索出的距离第四像素最近的背景像素中,确定出第rx+k层中距离第四像素最近的一背景像素,并记录第rx+k层中所述距离第四像素最近的一背景像素与第四像素的完全距离平方值 From the background pixels closest to the fourth pixel searched in the rx +kth layer, determine a background pixel in the rx +kth layer closest to the fourth pixel, and record all the background pixels in the rx +kth layer The complete distance square value between a background pixel closest to the fourth pixel and the fourth pixel

比较与(rx+k+1)2+(rx+k)2,当时,停止搜索,当时,继续搜索下一层,直至搜索完毕第rx+q-1层结束。Compare with (r x +k+1) 2 +(r x +k) 2 , when , stop searching when When , continue to search the next layer until the r x + q-1th layer is finished.

以如图5所示的第二最近背景像素范围为例,对步骤S1002进行说明,第二最近背景像素的每一层都是以O4为中心的正方形的边界,该正方形边长的一半就是该层的层数,采用围线搜索的思想在最近背景像素范围内进行搜索的方法为从层(圆内接正方形边长的一半)开始,逐层扫描直到r1+r2层(圆外切正方形边长的一半)结束,假设扫描第rx层,其中参见图11,为运用函数LR[x,y]与TD[x,y]搜索最近背景像素的示意图,对于rx层上的像素分别沿x、y方向将其划分为R1(在图中用虚线包围的区域)、R2(在图中用点划线包围的区域)、R3(在图中左侧实现包围的区域)以及R4(在图中右侧实现包围的区域)四组,易知该四组中的元素分别为(x-rx)行,(x+rx)行,(y-rx)列,(y+rx)列上像素的一部分。在(x-rx)行中距离目标像素O最近的背景像素(记为Bx1)的坐标为则表明Bx1∈R1,即R1中存在背景像素,同理若LR[x+rx,y]<rx 2,TD[x,y-rx]<rx 2TD[xx,y+r]<rx 2,则分别表明R2、R3、R4中存在背景像素,设tD=min{LR[x-rx,y],LR[x+rx,y],TD[x,y-rx],TD[xx,y+r]},记rx层上距离第四像素最近的背景像素与第四像素的距离的平方为DTx 2=tD+rx 2,由于在第rx+1层中tD的最小值为(rx+1)2,所以当tD≤(rx+1)2时,停止搜索,或者判断时停止搜索。Taking the second closest background pixel range as shown in Figure 5 as an example, step S1002 is described, each layer of the second closest background pixel is the boundary of a square centered on O 4 , and half of the square side length is For the number of layers of this layer, the method of searching within the nearest background pixel range by using the idea of perimeter search is as follows: Layer (half the side length of the square inscribed in the circle) starts, and scans layer by layer until r 1 + r 2 layers (half the side length of the square circumscribed by the circle) end, assuming that the r xth layer is scanned, where Referring to Fig. 11, it is a schematic diagram of using the functions LR[x, y] and TD[x, y] to search for the nearest background pixel. For the pixels on the r x layer, they are divided into R 1 along the x and y directions respectively (in the figure The area surrounded by dotted lines), R 2 (the area enclosed by dotted lines in the figure), R 3 (the area surrounded by the left side of the figure) and R 4 (the area surrounded by the right side of the figure) It is easy to know that the elements in the four groups are (xr x ) row, (x+r x ) row, (yr x ) column, and part of the pixel on (y+r x ) column. The coordinates of the background pixel (denoted as B x1 ) closest to the target pixel O in the (xr x ) row are or like It indicates that B x1 ∈ R 1 , that is, there are background pixels in R 1. Similarly, if LR[x+r x ,y]<r x 2 ,TD[x,yr x ]<r x 2 TD[x x ,y +r]<r x 2 , it indicates that there are background pixels in R 2 , R 3 , and R 4 respectively. Let tD=min{LR[xr x ,y],LR[x+r x ,y],TD[x ,yr x ],TD[x x ,y+r]}, record the square of the distance between the background pixel closest to the fourth pixel on layer r x and the fourth pixel as DT x 2 =tD+r x 2 , because in The minimum value of tD in the r x +1th layer is (r x +1) 2 , so when tD≤(r x +1) 2 , stop searching, or judge when to stop searching.

参见图12,为采用围线搜索方法搜索最近背景像素的示意图,假设需要计算距离变换的第四像素为目标像素A,图中数字1代表第一层、数字2代表第2层、数字3代表第3层以及数字4代表第4层,图中只画出四层,但是在实际应用中并不一定是四层,假设在rx=2时,搜索到一个背景像素B4,显然背景像素B4与目标像素A的距离为但是的平方值18大于(3+1)2,所以需要继续搜索第3层,在rx=3时,搜索到两个背景像素B1与B3,由于背景像素B1与目标像素A的距离为显然13小于(4+1)2,所以停止对下一层的搜索,此时利用第一函数以及第二函数在最近背景像素范围中搜索到的距离第一像素最近的背景像素有B1、B3和B4Referring to Figure 12, it is a schematic diagram of searching for the nearest background pixel by using the contour search method, assuming that the fourth pixel that needs to calculate the distance transformation is the target pixel A, the number 1 in the figure represents the first layer, the number 2 represents the second layer, and the number 3 represents The third layer and the number 4 represent the fourth layer. Only four layers are drawn in the figure, but it is not necessarily four layers in practical applications. Assume that when r x =2, a background pixel B 4 is found, obviously the background pixel The distance between B 4 and target pixel A is but The square value of 18 is greater than (3+1) 2 , so it is necessary to continue searching the third layer. When r x =3, two background pixels B 1 and B 3 are found. Due to the distance between the background pixel B 1 and the target pixel A for Obviously, 13 is less than (4+1) 2 , so the search for the next layer is stopped. At this time, the background pixels closest to the first pixel searched by the first function and the second function in the range of the nearest background pixels are B 1 , B3 and B4 .

上述是以图4所示的最近背景像素范围为例,对步骤S1002进行的解释,如果第二最近背景像素是以图2所示,第二最近背景像素范围的每层是指以O4为中心的正方形的边界,那么采用围线搜索的思想在最近背景像素范围内进行搜索的方法为:从第1层开始(即从圆心的8领域开始),逐层扫描直到r1+r2层(圆外切正方形边长的一半)结束;如果第二最近背景像素是以图3所示,第二最近背景像素范围的每层是指以O3为中心的正方形组成的,那么采用围线搜索的思想在最近背景像素范围内进行搜索的方法为:从第1层(即从圆心的8领域开始)开始,当扫描至第r1层时(第r1层为圆O3的外切正方形边长的一半),第二最近背景像素范围的左侧已经搜索完毕,此第二最近背景像素范围的每层是由以O3为中心的如图3所示的点划线框的边界,从第r1+1层进行搜索直到第r1+r2层。The above is an example of the nearest background pixel range shown in Fig. 4, to explain step S1002, if the second closest background pixel is as shown in Fig. The boundary of the square in the center, then the method of searching within the nearest background pixel range using the idea of perimeter search is as follows: start from the first layer (that is, start from the 8th area of the center of the circle), and scan layer by layer until r 1 + r 2 layers (half the side length of the square circumscribed by the circle); if the second closest background pixel is as shown in Figure 3, and each layer of the second closest background pixel range refers to a square with O 3 as the center, then use the perimeter The idea of searching The method of searching within the nearest background pixel range is as follows: starting from the first layer (that is, starting from the 8 field of the center of the circle), when scanning to the r1th layer (the r1th layer is the circumscribed circle O3 half of the side length of the square), the left side of the second closest background pixel range has been searched, and each layer of the second closest background pixel range is bounded by a dotted line box centered on O 3 as shown in Figure 3 , search from layer r 1 +1 until layer r 1 +r 2 .

步骤S1003:从搜索出的距离第四像素最近的背景像素中确定出与第四像素距离最近的第二背景像素,计算第二背景像素与第四像素的第二完全距离,并将此第二完全距离作为第四像素的二维完全距离变换值。Step S1003: Determine the second background pixel closest to the fourth pixel from the searched background pixels closest to the fourth pixel, calculate the second complete distance between the second background pixel and the fourth pixel, and calculate the second full distance as the 2D full distance transformed value of the fourth pixel.

完全距离是指该第二背景像素与第四像素的最短距离,即直线距离,距离变换值是指与目标像素距离最近的背景像素与该目标像素的距离值。The complete distance refers to the shortest distance between the second background pixel and the fourth pixel, that is, the straight-line distance, and the distance transformation value refers to the distance value between the background pixel closest to the target pixel and the target pixel.

具体的,步骤S1003包括:根据记录的距离所述第四像素最近的背景像素与所述第四像素的完全距离平方值,确定出与第四像素距离最近的第二背景像素与第四像素的第二完全距离平方值;对所述第二完全距离平方值开方得到所述第二完全距离。Specifically, step S1003 includes: according to the recorded complete distance square value between the background pixel closest to the fourth pixel and the fourth pixel, determine the distance between the second background pixel closest to the fourth pixel and the fourth pixel The square value of the second complete distance; the square root of the square value of the second complete distance is used to obtain the second complete distance.

记rx+k层上距离第四像素最近的背景像素与第四像素的距离的平方为假设只在第三层、第四层以及第五层找到了距离第四像素最近的背景像素,则步骤S1003具体包括:The square of the distance between the background pixel closest to the fourth pixel and the fourth pixel on the r x +k layer is Assuming that only the background pixel closest to the fourth pixel is found on the third layer, the fourth layer and the fifth layer, step S1003 specifically includes:

利用公式确定出与第四像素距离最近的第二背景像素,再利用公式:计算出第二完全距离。use the formula Determine the second background pixel closest to the fourth pixel, and then use the formula: Calculate the second complete distance.

本发明实施例提供的方法,不仅仅具有实施例一的有益效果,而且由于是利用第一函数以及第二函数在最近背景像素的每层中进行搜索,所以更加快了搜索速度。The method provided by the embodiment of the present invention not only has the beneficial effect of the first embodiment, but also uses the first function and the second function to search in each layer of the nearest background pixel, so the search speed is faster.

为了本领域技术人员进一步了解本发明实施例的优点,发明人使用上述方法计算三维二值图像中各个像素的完全距离变换,以及使用现有技术对同一副三维二值图像进行完全距离变换,并对二者的运行结果进行比较。In order for those skilled in the art to further understand the advantages of the embodiments of the present invention, the inventor uses the above method to calculate the complete distance transformation of each pixel in the 3D binary image, and uses the existing technology to perform complete distance transformation on the same 3D binary image, and Compare the results of the two operations.

现有技术是指Euclidean distance transform of digital images in arbitrarydimensions.PCM 2006,LNCS,2006,4261:72-79中记载的方法。The prior art refers to the method described in Euclidean distance transform of digital images in arbitrary dimensions. PCM 2006, LNCS, 2006, 4261:72-79.

如表1所示,为现有技术计算三维完全距离变换的运行时间(单位:秒)与利用本方法计算三维完全距离变换的时间对比表格。As shown in Table 1, it is a comparison table of the running time (unit: second) for calculating the three-dimensional complete distance transformation in the prior art and the time for calculating the three-dimensional complete distance transformation using this method.

表1Table 1

从表1中可以看出,对不同尺寸的图像进行距离变换,现有技术进行三维完全距离变换的时间都比本发明实施例提供的方法运行的时间长,为了更直观的表达本发明实施例提供的进行三维完全距离变换的方法效率高这一理念,表1中还给出了“现有技术/本发明实施例提供的方法”运行的时间之比。It can be seen from Table 1 that for distance transformation of images of different sizes, the time required for the existing technology to perform three-dimensional complete distance transformation is longer than that of the method provided by the embodiment of the present invention. In order to express the embodiment of the present invention more intuitively Based on the idea that the provided method for performing three-dimensional complete distance transformation has high efficiency, Table 1 also shows the running time ratio of "the prior art/the method provided by the embodiment of the present invention".

本说明书中各个实施例采用递进的方式描述,每个实施例重点说明的都是与其他实施例的不同之处,各个实施例之间相同相似部分互相参见即可。对于实施例公开的装置而言,由于其与实施例公开的方法相对应,所以描述的比较简单,相关之处参见方法部分说明即可。Each embodiment in this specification is described in a progressive manner, each embodiment focuses on the difference from other embodiments, and the same and similar parts of each embodiment can be referred to each other. As for the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and for the related information, please refer to the description of the method part.

结合本文中所公开的实施例描述的方法或算法的步骤可以直接用硬件、处理器执行的软件模块,或者二者的结合来实施。软件模块可以置于随机存储器(RAM)、内存、只读存储器(ROM)、电可编程ROM、电可擦除可编程ROM、寄存器、硬盘、可移动磁盘、CD-ROM、或技术领域内所公知的任意其它形式的存储介质中。The steps of the methods or algorithms described in connection with the embodiments disclosed herein may be directly implemented by hardware, software modules executed by a processor, or a combination of both. Software modules can be placed in random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other Any other known storage medium.

对所公开的实施例的上述说明,使本领域专业技术人员能够实现或使用本发明。对这些实施例的多种修改对本领域的专业技术人员来说将是显而易见的,本文中所定义的一般原理可以在不脱离本发明的精神或范围的情况下,在其它实施例中实现。因此,本发明将不会被限制于本文所示的这些实施例,而是要符合与本文所公开的原理和新颖特点相一致的最宽的范围。The above description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the present invention will not be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims (8)

1.一种三维二值图像完全距离变换的方法,所述三维二值图像的尺寸为m×n×s,其特征在于,包括:1. A method for complete distance transformation of a three-dimensional binary image, the size of the three-dimensional binary image is m × n × s, characterized in that, comprising: 将所述三维二值图像沿z轴分割成s张二维二值图片;dividing the three-dimensional binary image into s two-dimensional binary images along the z axis; 分别计算分割的每一二维二值图片中各个像素的二维完全距离变换;Calculating the two-dimensional complete distance transform of each pixel in each segmented two-dimensional binary image; 根据第二目标像素与需要计算三维完全距离变换的第一像素的完全距离,及所述第二目标像素在所述三维二值图像中的三维完全距离变换值,确定所述第一像素的第一最近背景像素范围;According to the complete distance between the second target pixel and the first pixel for which three-dimensional complete distance transformation needs to be calculated, and the three-dimensional complete distance transformation value of the second target pixel in the three-dimensional binary image, determine the first pixel of the first pixel. a nearest background pixel range; 确定所述第一像素在所述第一最近背景像素范围中的各个二维二值图片中的投影像素的二维完全距离变换值;determining the two-dimensional complete distance transform value of the projected pixel of the first pixel in each two-dimensional binary image within the range of the first nearest background pixel; 根据所述确定的第一像素在所述第一最近背景像素范围中各个二维二值图片的投影像素的二维完全距离变换值,确定出所述三维二值图像中距离所述第一像素最近的第一背景像素,计算所述第一背景像素与所述第一像素的第一完全距离,并将所述第一完全距离作为所述第一像素的三维完全距离变换值;According to the determined two-dimensional complete distance transformation value of the projected pixel of each two-dimensional binary picture in the first closest background pixel range of the first pixel, determine the distance from the first pixel in the three-dimensional binary image The nearest first background pixel, calculating the first complete distance between the first background pixel and the first pixel, and using the first complete distance as the three-dimensional complete distance transformation value of the first pixel; 所述第二目标像素在所述三维二值图像中的三维完全距离变换值为r1,所述根据第二目标像素与第一像素的完全距离,及所述第二目标像素在所述三维二值图像中的三维完全距离变换值,确定所述第一像素的第一最近背景像素范围具体包括:The 3D complete distance transformation value of the second target pixel in the 3D binary image is r 1 , according to the complete distance between the second target pixel and the first pixel, and the 3D distance of the second target pixel in the 3D The three-dimensional complete distance transformation value in the binary image, determining the first nearest background pixel range of the first pixel specifically includes: 确定所述第一像素与所述第二目标像素的完全距离r2determining a full distance r 2 of the first pixel to the second target pixel; 所述第一最近背景像素范围为以所述第一像素为球心,以r1+r2为半径的球O1的外切正方体所围成的区域;或,所述第一最近背景像素范围为以所述第二目标像素为球心,以r1为半径的球O2的内接正方体与所述球O1的外切正方体所围成的区域;或,所述第一最近背景像素范围为以所述第一像素为球心,以|r1-r2|为半径的球O3的内接正方体与所述球O1的外切正方体所围成的区域;The first closest background pixel range is the area surrounded by a circumscribed cube of a ball O 1 with the first pixel as the center and r 1 +r 2 as the radius; or, the first closest background pixel The range is the area enclosed by the inscribed cube of the ball O2 and the circumscribed cube of the ball O1 with the second target pixel as the center and r1 as the radius; or, the first closest background The pixel range is the area surrounded by the inscribed cube of the ball O 3 and the circumscribed cube of the ball O 1 with the first pixel as the center and |r 1 -r 2 | as the radius; 当所述第一最近背景像素范围是以所述第一像素为球心,以r1+r2为半径的球O1的外切正方体所围成的区域时,所述第一像素所在的二维二值图片为z0,所述确定所述第一像素在所述第一最近背景像素范围中的各个二维二值图片中的投影像素的二维完全距离变换值具体包括:When the first closest background pixel range is the area surrounded by a circumscribed cube of a ball O 1 with the first pixel as the center and r 1 +r 2 as the radius, the first pixel is located The two-dimensional binary picture is z 0 , and the determination of the two-dimensional complete distance transformation value of the first pixel in each two-dimensional binary picture in the range of the first nearest background pixel specifically includes: 以所述二维二值图片z0为对称中心沿z轴方向从里到外依次确定所述第一像素在二维二值图片z0+rx中的投影像素的二维完全距离变换值的平方DRx 2,并记录确定的二维完全距离变换值的平方,rx=0,±1,±2,…,±(r1+r2);Taking the two-dimensional binary picture z0 as the center of symmetry and sequentially determining the two-dimensional complete distance transformation value of the projected pixel of the first pixel in the two-dimensional binary picture z0 + rx from the inside to the outside along the z-axis direction The square of DR x 2 , and record the square of the determined two-dimensional complete distance transformation value, r x =0,±1,±2,...,±(r 1 +r 2 ); 判断DRx 2是否满足DRx 2+rx 2≤(rx+1)2,如果是,则停止确定第一像素分别在二维二值图片z0±(rx+1)直至二维二值图片z0±(r1+r2)中投影像素的二维完全距离变换值,如果否,则继续确定第一像素分别在二维二值图片z0±(rx+1)中投影像素的二维完全距离变换值,直至确定出所述第一像素在二维二值图片z0±(r1+r2)中的投影像素的二维完全距离变换值为止。Judging whether DR x 2 satisfies DR x 2 +r x 2 ≤(r x +1) 2 , if yes, stop determining the first pixel in the two-dimensional binary image z 0 ±(r x +1) to two-dimensional The two-dimensional complete distance transformation value of the projected pixel in the binary image z 0 ±(r 1 +r 2 ), if not, continue to determine that the first pixel is respectively in the two-dimensional binary image z 0 ±(r x +1) Projecting the two-dimensional complete distance transformation value of the pixel until the two-dimensional complete distance transformation value of the projected pixel of the first pixel in the two-dimensional binary image z 0 ±(r 1 +r 2 ) is determined. 2.根据权利要求1所述方法,其特征在于,所述根据所述第一像素在所述第一最近背景像素范围中各个二维二值图片的投影像素的二维完全距离变换值,确定出所述三维二值图像中距离所述第一像素最近的第一背景像素具体包括:2. The method according to claim 1, wherein, according to the two-dimensional complete distance transformation values of the projected pixels of each two-dimensional binary picture in the first closest background pixel range of the first pixel, determine Finding the first background pixel closest to the first pixel in the three-dimensional binary image specifically includes: 利用公式其中zx∈第一最近背景像素范围中z的取值范围,确定出与第一像素距离最近的第一背景像素;use the formula Wherein z x ∈ the value range of z in the first nearest background pixel range, determine the first background pixel closest to the first pixel distance; 利用公式计算出第一完全距离。use the formula Calculate the first complete distance. 3.根据权利要求1所述方法,其特征在于,计算每一二维二值图片的二维完全距离变换具体包括:3. The method according to claim 1, wherein calculating the two-dimensional complete distance transformation of each two-dimensional binary picture specifically comprises: 预处理步骤,所述预处理步骤为确定第一函数或者确定第二函数,所述第一函数用于确定二维二值图片第i行中距离第四像素最近的背景像素的位置,所述第二函数用于确定二维二值图片第j列中距离所述第四像素最近的背景像素的位置,其中,1≤i≤m,1≤j≤n,i与j均为整数;A preprocessing step, the preprocessing step is to determine the first function or determine the second function, the first function is used to determine the position of the background pixel closest to the fourth pixel in the i-th row of the two-dimensional binary image, the The second function is used to determine the position of the background pixel closest to the fourth pixel in the jth column of the two-dimensional binary image, wherein, 1≤i≤m, 1≤j≤n, i and j are both integers; 根据第三目标像素与需要计算二维完全距离的所述第四像素的完全距离,及所述第三目标像素在二维二值图片中的二维完全距离,确定所述第四像素的第二最近背景像素范围,所述第四像素与所述第三目标像素均位于同一二维二值图片中;According to the complete distance between the third target pixel and the fourth pixel for which the two-dimensional complete distance needs to be calculated, and the two-dimensional complete distance of the third target pixel in the two-dimensional binary image, determine the first position of the fourth pixel 2. The closest background pixel range, the fourth pixel and the third target pixel are located in the same two-dimensional binary image; 利用所述第一函数分别在所述第二最近背景像素范围的每行中搜索距离所述第四像素最近的背景像素,或利用所述第二函数分别在所述第二最近背景像素范围的每列中搜索距离所述第四像素最近的背景像素;Use the first function to search for the background pixel closest to the fourth pixel in each row of the second closest background pixel range, or use the second function to search for the background pixel in the second closest background pixel range Search for the nearest background pixel to the fourth pixel in each column; 从搜索出的距离所述第四像素最近的背景像素中确定出与所述第四像素距离最近的第二背景像素,计算所述第二背景像素与所述第四像素的第二二维完全距离,并将所述第二二维完全距离作为所述第四像素在其所在的二维二值图片中的二维完全距离变换值。Determine the second background pixel closest to the fourth pixel from the searched background pixels closest to the fourth pixel, and calculate the second two-dimensional completeness between the second background pixel and the fourth pixel distance, and use the second two-dimensional complete distance as the two-dimensional complete distance transformation value of the fourth pixel in the two-dimensional binary picture where it is located. 4.根据权利要求1所述方法,其特征在于,计算每一二维二值图片的二维完全距离变换具体包括:4. The method according to claim 1, wherein calculating the two-dimensional complete distance transformation of each two-dimensional binary picture specifically comprises: 预处理步骤,所述预处理步骤为确定第一函数或者确定第二函数,所述第一函数用于确定二维二值图片第i行中距离第四像素最近的背景像素的位置,所述第二函数用于确定二维二值图片第j列中距离所述第四像素最近的背景像素的位置,其中,1≤i≤m,1≤j≤n,i与j均为整数;A preprocessing step, the preprocessing step is to determine the first function or determine the second function, the first function is used to determine the position of the background pixel closest to the fourth pixel in the i-th row of the two-dimensional binary image, the The second function is used to determine the position of the background pixel closest to the fourth pixel in the jth column of the two-dimensional binary image, wherein, 1≤i≤m, 1≤j≤n, i and j are both integers; 根据第三目标像素与所述第四像素的完全距离,及第三目标像素与离其最近背景像素的距离,确定第四像素的第二最近背景像素范围,并将第二最近背景像素范围按照预设规则划分为第一子最近背景像素范围集以及第二子最近背景像素范围集,第一子最近背景像素范围集包括至少一个第一子最近背景像素范围,所述至少一个第一子最近背景像素范围中的行数不大于列数,第二子最近背景像素范围集包括至少一个第二子最近背景像素范围,所述至少一个第二子最近背景像素范围中的行数大于列数;According to the complete distance between the third target pixel and the fourth pixel, and the distance between the third target pixel and its nearest background pixel, determine the second closest background pixel range of the fourth pixel, and divide the second closest background pixel range according to The preset rule is divided into a first sub-nearest background pixel range set and a second sub-nearest background pixel range set, the first sub-nearest background pixel range set includes at least one first sub-nearest background pixel range, and the at least one first sub-nearest background pixel range The number of rows in the background pixel range is not greater than the number of columns, the second sub-nearest background pixel range set includes at least one second sub-nearest background pixel range, and the number of rows in the at least one second sub-nearest background pixel range is greater than the number of columns; 利用第一函数在第一子最近背景像素范围集的每行中搜索距离第四像素最近的背景像素,利用第二函数在第二子最近背景像素范围集的每列中搜索距离第四像素最近的背景像素;Use the first function to search for the background pixel closest to the fourth pixel in each row of the first sub-nearest background pixel range set, and use the second function to search for the closest background pixel to the fourth pixel in each column of the second sub-nearest background pixel range set background pixels; 从搜索出的距离第四像素最近的背景像素中确定出与第四像素距离最近的第二背景像素,计算第二背景像素与第四像素的第二完全距离,并将此第二完全距离作为第四像素的二维完全距离变换值。Determine the second background pixel closest to the fourth pixel from the searched background pixels closest to the fourth pixel, calculate the second complete distance between the second background pixel and the fourth pixel, and use this second complete distance as The 2D full distance transformed value of the fourth pixel. 5.根据权利要求3或4任一所述方法,其特征在于,所述确定所述第四像素的第二最近背景像素范围具体包括:5. The method according to any one of claims 3 or 4, wherein said determining the second nearest background pixel range of said fourth pixel specifically comprises: 计算所述第三目标像素在二维二值图片中的二维完全距离r3Calculating the two-dimensional complete distance r 3 of the third target pixel in the two-dimensional binary image; 确定所述第四像素与所述第三目标像素的完全距离r4determining a complete distance r 4 of the fourth pixel from the third target pixel; 所述第二最近背景像素范围为以所述第四像素为圆心,以r3+r4为半径的圆O4的外切正方形所围成的区域;The second closest background pixel range is the area surrounded by the circumscribed square of the circle O 4 with the fourth pixel as the center and r 3 +r 4 as the radius; 或,所述第二最近背景像素范围为以所述第三目标像素为圆心,以r3为半径的圆O5的内接正方形与所述圆O4的外切正方形所围成的环形区域;Or, the second closest background pixel range is an annular area surrounded by the inscribed square of the circle O5 and the circumscribed square of the circle O4 with the third target pixel as the center and r3 as the radius ; 或,所述第二最近背景像素范围为以所述第四像素为球心,以|r3-r4|为半径的圆O6的内接正方形与所述圆O4的外切正方形所围成的环形区域。Or, the range of the second closest background pixel is defined by the inscribed square of the circle O 6 with the fourth pixel as the center and the radius |r 3 -r 4 | and the circumscribed square of the circle O 4 enclosed circular area. 6.根据权利要求3或4任一所述方法,其特征在于,所述第四像素位于二维二值图片的第x行,第y列,用(x,y)表示所述第四像素在所述二维二值图片中的位置,以(x,y)为分界点,将第x行分为左侧和右侧,将第y列分为上方和下方;6. according to any described method of claim 3 or 4, it is characterized in that, described 4th pixel is positioned at the xth line of two-dimensional binary picture, yth column, represents described 4th pixel with (x, y) In the position in the two-dimensional binary picture, with (x, y) as the dividing point, the xth row is divided into left and right sides, and the yth column is divided into top and bottom; 所述确定第一函数具体包括:The determining the first function specifically includes: 确定用于计算所述二维二值图片第x行左侧距离所述第四像素(x,y)最近的背景像素所在列数的第一子函数,及用于计算所述二维二值图片第x行右侧距离所述第四像素(x,y)最近的背景像素所在列数的第二子函数,其中,1≤x≤m,1≤y≤n;Determining the first sub-function used to calculate the column number of the background pixel closest to the fourth pixel (x, y) on the left side of the xth row of the two-dimensional binary image, and used to calculate the two-dimensional binary image The second sub-function of the column number of the background pixel closest to the fourth pixel (x, y) on the right side of the xth row of the picture, wherein, 1≤x≤m, 1≤y≤n; 根据所述第一子函数及所述第二子函数,确定所述第一函数;determining the first function according to the first sub-function and the second sub-function; 所述确定第二函数具体包括:The determining the second function specifically includes: 确定用于计算所述二维二值图片第y列上方距离所述第四像素最近的背景像素所在行数的第三子函数,及用于计算所述二维二值图片第y列下方距离所述第四像素最近的背景像素所在行数的第四子函数;Determine the third sub-function used to calculate the row number of the background pixel closest to the fourth pixel above the yth column of the two-dimensional binary image, and to calculate the distance below the yth column of the two-dimensional binary image The fourth sub-function of the row number of the nearest background pixel of the fourth pixel; 根据所述第三子函数及所述第四子函数,确定所述第二函数。The second function is determined according to the third sub-function and the fourth sub-function. 7.根据权利要求6所述方法,其特征在于,所述第一子函数具体为L[x,y]:7. The method according to claim 6, wherein the first sub-function is specifically L[x, y]: LL [[ xx ,, ythe y ]] == ythe y II (( xx ,, ythe y )) == 00 LL [[ xx ,, ythe y -- 11 ]] II (( xx ,, ythe y )) == 11 ;; 若I(x,y)=1且y=1,那么L[x,y]=-Maxlable;If I(x, y)=1 and y=1, then L[x, y]=-Maxlable; 所述第二子函数具体为R[x,y]:The second sub-function is specifically R[x, y]: RR [[ xx ,, ythe y ]] == ythe y II (( xx ,, ythe y )) == 00 RR [[ xx ,, ythe y ++ 11 ]] II (( xx ,, ythe y )) == 11 ;; 若I(x,y)=1且y=n,那么R[x,y]=Maxlable;If I(x, y)=1 and y=n, then R[x, y]=Maxlable; 则根据所述第一子函数及所述第二子函数确定的所述第一函数具体为SZ[x,y]:Then the first function determined according to the first sub-function and the second sub-function is specifically SZ[x, y]: SZSZ [[ xx ,, ythe y ]] == LL [[ xx ,, ythe y ]] ythe y -- LL [[ xx ,, ythe y ]] << RR [[ xx ,, ythe y ]] -- ythe y RR [[ xx ,, ythe y ]] ythe y -- LL [[ xx ,, ythe y ]] &GreaterEqual;&Greater Equal; RR [[ xx ,, ythe y ]] -- ythe y ;; 所述第三子函数具体为T[x,y]:The third sub-function is specifically T[x, y]: TT [[ xx ,, ythe y ]] == xx II (( xx ,, ythe y )) == 00 TT [[ xx -- 11 ,, ythe y ]] II (( xx ,, ythe y )) == 11 ;; 若I(x,y)=1且x=1,那么T[x,y]=-Maxlable;If I(x, y)=1 and x=1, then T[x, y]=-Maxlable; 所述第四子函数具体为D[x,y]:The fourth sub-function is specifically D[x, y]: DD. [[ xx ,, ythe y ]] == xx II (( xx ,, ythe y )) == 00 DD. [[ xx ++ 11 ,, ythe y ]] II (( xx ,, ythe y )) == 11 ;; 若I(x,y)=1且x=m,那么D[x,y]=Maxlable;If I(x, y)=1 and x=m, then D[x, y]=Maxlable; 则根据所述第三子函数及所述第四子函数确定的所述第二函数具体为ZS[x,y]:Then the second function determined according to the third sub-function and the fourth sub-function is specifically ZS[x, y]: ZSZS [[ xx ,, ythe y ]] == TT [[ xx ,, ythe y ]] ythe y -- DD. [[ xx ,, ythe y ]] << TT [[ xx ,, ythe y ]] -- xx DD. [[ xx ,, ythe y ]] ythe y -- DD. [[ xx ,, ythe y ]] &GreaterEqual;&Greater Equal; TT [[ xx ,, ythe y ]] -- xx ;; 其中,I(x,y)=1表示为目标像素,I(x,y)=0表示为背景像素,所述Maxlable为预设最大标记值。Wherein, I(x, y)=1 represents a target pixel, I(x, y)=0 represents a background pixel, and the Maxlable is a preset maximum label value. 8.根据权利要求7所述方法,其特征在于,所述 8. The method according to claim 7, wherein the
CN201210205736.3A 2012-06-20 2012-06-20 Method for transforming full distance of three-dimensional binary image Expired - Fee Related CN102737361B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201210205736.3A CN102737361B (en) 2012-06-20 2012-06-20 Method for transforming full distance of three-dimensional binary image

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201210205736.3A CN102737361B (en) 2012-06-20 2012-06-20 Method for transforming full distance of three-dimensional binary image

Publications (2)

Publication Number Publication Date
CN102737361A CN102737361A (en) 2012-10-17
CN102737361B true CN102737361B (en) 2014-11-05

Family

ID=46992797

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201210205736.3A Expired - Fee Related CN102737361B (en) 2012-06-20 2012-06-20 Method for transforming full distance of three-dimensional binary image

Country Status (1)

Country Link
CN (1) CN102737361B (en)

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1403057A (en) * 2001-09-13 2003-03-19 田捷 3D Euclidean distance transformation process for soft tissue display in CT image

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7809165B2 (en) * 2007-01-25 2010-10-05 Mitsubishi Electric Research Laboratories, Inc. Method for generating distance maps using scan lines

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1403057A (en) * 2001-09-13 2003-03-19 田捷 3D Euclidean distance transformation process for soft tissue display in CT image

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
基于链码技术的距离变换改进算法;徐达丽等;《计算机工程与应用》;20090901;第45卷(第25期);第176-178页 *
徐达丽等.基于链码技术的距离变换改进算法.《计算机工程与应用》.2009,第45卷(第25期),第176-178页. *

Also Published As

Publication number Publication date
CN102737361A (en) 2012-10-17

Similar Documents

Publication Publication Date Title
CN103679702B (en) A kind of matching process based on image border vector
CN108733780B (en) Picture searching method and device
CN110489778B (en) Graph segmentation method and laser etching control system for laser etching processing
CN103247041B (en) A kind of dividing method of the cloud data of the many geometric properties based on local sampling
TW201824186A (en) Tiled map generating method and apparatus in virtual map, and tiled map updating method and apparatus in virtual map
CN104517109B (en) A kind of bearing calibration of QR codes image and system
US10643372B2 (en) Method for reconstructing three-dimensional information of object and apparatus for the same
TW201531871A (en) System and method for sticking an image on a point cloud model
CN103578133A (en) Method and device for reconstructing two-dimensional image information in three-dimensional mode
CN103942754A (en) Panoramic image completion method and device
CN115880685B (en) A three-dimensional target detection method and system based on votenet model
WO2024060999A1 (en) Polygon processing method and apparatus, and device, computer-readable storage medium and computer program product
CN108074250A (en) Matching power flow computational methods and device
CN108564604B (en) Binocular vision stereo matching method and device based on plane constraint and triangulation
TWI489859B (en) Image deformation method and computer program product
CN110728623B (en) Cloud point splicing method, terminal equipment and computer storage medium
CN103871022B (en) Image cropping method and device
CN111340889A (en) Automatic acquisition of matching image blocks and point cloud spheres based on vehicle laser scanning
CN102737359B (en) Method for quickly performing complete distance transformation on three-dimensional binary image
CN102737361B (en) Method for transforming full distance of three-dimensional binary image
CN104036096B (en) Method for mapping bump features on inclined face to manufacturing feature bodies
CN110427506A (en) Spatial data boundary processing method, device, computer equipment and storage medium
CN102737360B (en) Method for fast transforming full distance of binary image
CN112036398A (en) Text correction method and system
CN116246038B (en) Method, system, electronic equipment and medium for reconstructing three-dimensional line segment of multi-view image

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
CF01 Termination of patent right due to non-payment of annual fee
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20141105

Termination date: 20180620