TWI670682B - Image distance transformation apparatus and method using bi-directional scan - Google Patents

Image distance transformation apparatus and method using bi-directional scan Download PDF

Info

Publication number
TWI670682B
TWI670682B TW107116112A TW107116112A TWI670682B TW I670682 B TWI670682 B TW I670682B TW 107116112 A TW107116112 A TW 107116112A TW 107116112 A TW107116112 A TW 107116112A TW I670682 B TWI670682 B TW I670682B
Authority
TW
Taiwan
Prior art keywords
pixel
current
image
scan
mask
Prior art date
Application number
TW107116112A
Other languages
Chinese (zh)
Other versions
TW201947525A (en
Inventor
詩湧 陳
Original Assignee
台達電子工業股份有限公司
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 台達電子工業股份有限公司 filed Critical 台達電子工業股份有限公司
Priority to TW107116112A priority Critical patent/TWI670682B/en
Application granted granted Critical
Publication of TWI670682B publication Critical patent/TWI670682B/en
Publication of TW201947525A publication Critical patent/TW201947525A/en

Links

Landscapes

  • Image Processing (AREA)

Abstract

本發明係提供一種利用雙向掃瞄之影像距離轉換方法,包括:對一輸入影像之各像素依一第一順序套用一第一遮罩以進行一第一掃瞄以產生一中間影像,其中該第一掃瞄包括一第一比較處理及一第一更新處理;以及對該中間影像之各像素依一第二順序套用一第二遮罩以進行一第二掃瞄以取得該輸入影像中之各像素之一距離資訊,其中該第二掃瞄包括一第二比較處理及一第二更新處理;其中,對該輸入影像之所進行之該第一比較處理係使用一第一目前像素,而不與在該輸入影像中在該第一順序上位於該第一目前像素之前且位於相同之一第一目前區段的像素比較;其中,對該中間影像所進行之該第二比較處理係使用一第二目前像素,而不與在該中間影像中在該第二順序上位於該第二目前像素之前且位於相同之一第二目前區段的像素比較。 The present invention provides an image distance conversion method using a two-way scan, comprising: applying a first mask to a pixel of an input image in a first order to perform a first scan to generate an intermediate image, wherein the image is generated. The first scan includes a first comparison process and a first update process; and each pixel of the intermediate image is applied with a second mask in a second order to perform a second scan to obtain the input image. One of the pixels is distance information, wherein the second scan includes a second comparison process and a second update process; wherein the first comparison process performed on the input image uses a first current pixel, and Not comparing with pixels in the first sequence that are located in the first order before the first current pixel and in the same first current segment; wherein the second comparison processing performed on the intermediate image is used A second current pixel is not compared to a pixel in the intermediate image that precedes the second current pixel and is located in the same one of the second current segment.

Description

利用雙向掃瞄之影像距離轉換裝置及其方法 Image distance conversion device using two-way scanning and method thereof

本發明係有關於影像處理,特別是有關於一種利用雙向掃瞄影像距離轉換裝置及其方法。 The present invention relates to image processing, and more particularly to a method and apparatus for utilizing a two-way scan image distance conversion device.

對於一幀二元影像來說,影像中之像素可分為背景像素(例如像素值為0)和目標像素(例如像素值為1)兩類。距離轉換(Distance Transformation)係指將二元影像中之每一個像素的像素值0或1轉換成由其到最近的目標像素之間的距離,且目標像素之距離轉換值為0。經過距離轉換後之影像更能顯示出影像之邊緣、幾何形狀之資訊,亦可用於物件比對、細線化、及路線規劃等應用。 For a frame of binary image, the pixels in the image can be divided into two types: the background pixel (for example, the pixel value is 0) and the target pixel (for example, the pixel value is 1). Distance Transformation refers to converting the pixel value 0 or 1 of each pixel in the binary image to the distance from the nearest target pixel, and the distance conversion value of the target pixel is 0. After the distance conversion, the image can display the information of the edge and geometry of the image, and can also be used for object comparison, thinning, and route planning.

現今距離轉換之演算法主要可分為近似距離變換(Euclidean Distance Transform)以及完全歐幾里德距離變換。近似歐幾里德距離變換之一般可用兩個遮罩(mask)實現,例如可使用3x3、5x5、7x7遮罩等等,各遮罩係分別進行前進掃瞄(forward scan)及後退掃瞄(backward scan)。在遮罩中之參數值均為整數以簡化計算,也就是以近似的方式計算前景物件至背 景像素之間的歐幾里德距離(歐氏距離)。此類方法會具有誤差,例如城市方塊距離(city-block distance)或曼哈頓距離(Manhattan Distance),但此類方法之實現方式簡單且速度較快,例如可用於不要求高精確度的影像處理,例如監視器影像、醫學影像等等。 The current distance conversion algorithm can be mainly divided into Euclidean Distance Transform and complete Euclidean distance transform. The approximate Euclidean distance transform can generally be implemented by two masks, for example, 3x3, 5x5, 7x7 masks, etc., each of which performs forward scan and backward scan ( Backward scan). The values of the parameters in the mask are integers to simplify the calculation, that is, the foreground object is calculated to the back in an approximate manner. The Euclidean distance between the pixels of the scene (Euclidean distance). Such methods can have errors, such as city-block distance or Manhattan Distance, but such methods are simple and fast to implement, such as for image processing that does not require high precision. For example, monitor images, medical images, and the like.

完全歐幾里德距離變換因為需要計算精確的歐幾里德距離,其計算的複雜度較高,且計算時間長,故通常不會使用於一般應用上。 The full Euclidean distance transform is computationally complex and has a long calculation time because it needs to calculate the exact Euclidean distance, so it is usually not used in general applications.

對於近似歐幾里德距離變換之計算而言,其使用的遮罩設計通常需要目前像素之前一個像素之計算結果,這也造成了資料相依性的問題。當程式碼在編譯器處理後所產生之指令亦會具有資料相依性,所以會讓處理器在執行時產生停止以等待運算結果之情況,進而造成運算效能不佳。 For the calculation of the approximate Euclidean distance transform, the mask design used usually requires the calculation of one pixel before the current pixel, which also causes the problem of data dependence. When the code is processed by the compiler, the instructions will also have data dependencies, so the processor will stop when it is executed to wait for the result of the operation, which will result in poor computing performance.

因此,需要一種利用雙向掃瞄影像距離轉換裝置及其方法以解決上述問題。 Therefore, there is a need for a two-way scanning image distance conversion device and method thereof to solve the above problems.

本發明係提供一種利用雙向掃瞄之影像距離轉換方法,包括:對一輸入影像之各像素依一第一順序套用一第一遮罩以進行一第一掃瞄以產生一中間影像,其中該第一掃瞄包括一第一比較處理及一第一更新處理;以及對該中間影像之各像素依一第二順序套用一第二遮罩以進行一第二掃瞄以取得該輸入影像中之各像素之一距離資訊,其中該第二掃瞄包括一第二比較處理及一第二更新處理;其中,該第一比較處理係使 用該輸入影像中之一第一目前像素而不與該輸入影像中在該第一順序上位於該第一目前像素之前且位於相同之一第一目前區段的像素比較;其中,該第二比較處理係使用該中間影像中之一第二目前像素而不與該中間影像中在第二順序上位於該第二目前像素之前且位於相同之一第二目前區段的像素比較。 The present invention provides an image distance conversion method using a two-way scan, comprising: applying a first mask to a pixel of an input image in a first order to perform a first scan to generate an intermediate image, wherein the image is generated. The first scan includes a first comparison process and a first update process; and each pixel of the intermediate image is applied with a second mask in a second order to perform a second scan to obtain the input image. One of the pixels is distance information, wherein the second scan includes a second comparison process and a second update process; wherein the first comparison process is Using one of the first current pixels of the input image without comparing with pixels of the input image that are located in the first order before the first current pixel and located in the same first current segment; wherein, the second The comparison process uses one of the second current pixels of the intermediate image without comparison with pixels of the intermediate image that are located in front of the second current pixel in the second order and are located in the same one of the second current segments.

本發明更提供一種影像距離轉換裝置,包括:一記憶體單元,用以儲存一影像距離轉換程式;以及一處理單元,用以由該記憶體單元讀取並執行該影像距離轉換程式以進行下列步驟:對一輸入影像之各像素依一第一順序套用一第一遮罩以進行一第一掃瞄以產生一中間影像,其中該第一掃瞄包括一第一比較處理及一第一更新處理;以及對該中間影像之各像素依一第二順序套用一第二遮罩以進行一第二掃瞄以取得該輸入影像中之各像素之一距離資訊,其中該第二掃瞄包括一第二比較處理及一第二更新處理;其中,該第一比較處理係使用該輸入影像中之一第一目前像素而不與該輸入影像中在該第一順序上位於該第一目前像素之前且位於相同之一第一目前區段的像素比較;其中,該第二比較處理係使用該中間影像中之一第二目前像素而不與該中間影像中在第二順序上位於該第二目前像素之前且位於相同之一第二目前區段的像素比較。 The present invention further provides an image distance conversion device, comprising: a memory unit for storing an image distance conversion program; and a processing unit for reading and executing the image distance conversion program by the memory unit to perform the following Step: applying a first mask to a pixel of an input image in a first order to perform a first scan to generate an intermediate image, wherein the first scan includes a first comparison process and a first update Processing; and applying a second mask to the pixels of the intermediate image in a second order to perform a second scan to obtain distance information of each pixel in the input image, wherein the second scan includes a second scan a second comparison process and a second update process; wherein the first comparison process uses one of the first current pixels of the input image without being in front of the first current pixel in the first sequence in the input image And comparing pixels of the same one of the first current segments; wherein the second comparison process uses one of the second images of the intermediate image without being in the intermediate image And the comparison pixel in the second section of the same one currently located before the second sequence of two current pixel.

100‧‧‧影像距離轉換裝置 100‧‧‧Image distance conversion device

110‧‧‧處理單元 110‧‧‧Processing unit

111‧‧‧緩衝器 111‧‧‧buffer

120‧‧‧記憶體單元 120‧‧‧ memory unit

121‧‧‧揮發性記憶體 121‧‧‧ volatile memory

122‧‧‧非揮發性記憶體 122‧‧‧Non-volatile memory

123‧‧‧影像距離轉換程式 123‧‧‧Image Distance Conversion Program

A-E、A’-E’‧‧‧像素 A-E, A’-E’‧‧ ‧ pixels

P‧‧‧像素 P‧‧ ‧ pixels

q0-q7‧‧‧像素 Q0-q7‧‧‧ pixels

a、b、c、d‧‧‧暫存器 a, b, c, d‧‧‧ register

d0、d1‧‧‧距離 D0, d1‧‧‧ distance

S610-S620‧‧‧步驟 S610-S620‧‧‧Steps

700‧‧‧輸入影像 700‧‧‧ Input image

701-708‧‧‧箭頭 701-708‧‧‧ arrow

7001、7002‧‧‧前進掃瞄遮罩 7001, 7002‧‧‧ forward scanning mask

7101、7102‧‧‧後退掃瞄遮罩 7101, 7102‧‧‧ Back scanning mask

710‧‧‧中間影像 710‧‧‧ intermediate image

711-718‧‧‧箭頭 711-718‧‧‧ arrow

P(0,0)-P(9,9)、P’(0,0)-P’(9,9)‧‧‧像素 P(0,0)-P(9,9), P'(0,0)-P'(9,9)‧‧‧ pixels

第1圖係顯示依據本發明一實施例中之影像距離轉換裝置之功能方塊圖。 1 is a functional block diagram showing an image distance conversion device in accordance with an embodiment of the present invention.

第2A圖係顯示依據本發明一實施例中以3x3區域進行雙向掃瞄之示意圖。 2A is a schematic diagram showing bidirectional scanning in a 3x3 region in accordance with an embodiment of the present invention.

第2B圖係顯示依據本發明一實施例中之前進掃瞄遮罩的示意圖。 2B is a schematic diagram showing a pre-scanning mask in accordance with an embodiment of the present invention.

第2C圖係顯示依據本發明一實施例中之後退掃瞄遮罩的示意圖。 2C is a schematic diagram showing a back-sweeping mask in accordance with an embodiment of the present invention.

第2D圖係顯示依據本發明一實施例中之部份輸入影像的示意圖。 2D is a schematic diagram showing a portion of an input image in accordance with an embodiment of the present invention.

第3A圖係顯示依據本發明一實施例中之掃瞄遮罩的示意圖。 Figure 3A is a schematic illustration of a scanning mask in accordance with an embodiment of the present invention.

第3B圖係顯示依據本發明第3A圖之實施例中之前進掃瞄遮罩的示意圖。 Figure 3B is a schematic illustration of a prior scanning mask in accordance with an embodiment of Figure 3A of the present invention.

第3C圖係顯示依據本發明第3A圖之實施例中之後退掃瞄遮罩的示意圖。 Figure 3C is a schematic view showing the back-sweeping mask in the embodiment of Figure 3A of the present invention.

第3D圖係顯示依據本發明一實施例中之前進掃瞄遮罩中之像素的示意圖。 3D is a schematic diagram showing pixels in a pre-scan mask in accordance with an embodiment of the present invention.

第3E圖係顯示依據本發明一實施例中之後退掃瞄遮罩中之像素的示意圖。 Figure 3E is a schematic diagram showing the pixels in the back-sweep mask in accordance with an embodiment of the present invention.

第4A~4C圖係顯示本發明一實施例中之前進掃瞄中之第一比較處理的示意圖。 4A to 4C are views showing a first comparison process in the previous scanning in an embodiment of the present invention.

第4D~4F圖係顯示本發明一實施例中之前進掃瞄中之第一更新處理的示意圖。 4D to 4F are diagrams showing the first update processing in the previous scanning in an embodiment of the present invention.

第4G~4I圖係顯示本發明一實施例中之後退掃瞄中之第二比較處理的示意圖。 The 4G~4I diagram shows a schematic diagram of a second comparison process in the backward scan in an embodiment of the present invention.

第4J~4L圖係顯示本發明一實施例中之後退掃瞄中之第二更新處理的示意圖。 The 4th through 4th drawings show a schematic diagram of a second update process in the backward scan in an embodiment of the present invention.

第5圖係顯示依據本發明一實施例中之不同掃瞄遮罩的示意圖。 Figure 5 is a schematic diagram showing different scanning masks in accordance with an embodiment of the present invention.

第6圖係顯示依據本發明一實施例中之影像距離轉換方法的流程圖。 Figure 6 is a flow chart showing a method of image distance conversion in accordance with an embodiment of the present invention.

第7A及7B圖係顯示依據本發明之一實施例中以不同順序進行影像距離轉換的示意圖。 7A and 7B are diagrams showing image distance conversion in different orders in accordance with an embodiment of the present invention.

為使本發明之上述目的、特徵和優點能更明顯易懂,下文特舉一較佳實施例,並配合所附圖式,作詳細說明如下。 The above described objects, features and advantages of the present invention will become more apparent from the description of the appended claims.

第1圖係顯示依據本發明一實施例中之影像距離轉換裝置之功能方塊圖。如第1圖所示,影像距離轉換裝置100包括一處理單元110及一記憶體單元120。處理單元110例如可為一般用途處理器(general-purpose processor)、數位信號處理器(digital signal processor)、或是影像信號處理器(image signal processor),但本發明並不限於此。處理單元110係包括一緩衝器111,用以儲存在執行影像距離轉換方法之中間資料。 1 is a functional block diagram showing an image distance conversion device in accordance with an embodiment of the present invention. As shown in FIG. 1 , the image distance conversion device 100 includes a processing unit 110 and a memory unit 120 . The processing unit 110 may be, for example, a general-purpose processor, a digital signal processor, or an image signal processor, but the present invention is not limited thereto. The processing unit 110 includes a buffer 111 for storing intermediate data in the image distance conversion method.

記憶體單元120係包括一揮發性記憶體121及一非揮發性記憶體122。揮發性記憶體121可為一隨機存取記憶體, 例如是一靜態隨機存取記憶體(SRAM)或一動態隨機存取記憶體(DRAM),但本發明並不限於此。非揮發性記憶體122例如可為一硬碟機、一固態硬碟機、一快閃記憶體、或一唯讀記憶體,但本發明並不限於此。 The memory unit 120 includes a volatile memory 121 and a non-volatile memory 122. The volatile memory 121 can be a random access memory. For example, a static random access memory (SRAM) or a dynamic random access memory (DRAM), but the invention is not limited thereto. The non-volatile memory 122 can be, for example, a hard disk drive, a solid state drive, a flash memory, or a read-only memory, but the invention is not limited thereto.

非揮發性記憶體122係儲存一影像距離轉換程式123,處理單元110係將影像距離轉換程式123由非揮發性記憶體122讀取至揮發性記憶體121並執行,其中影像距離轉換程式123係包括一影像距離轉換方法之程式碼。 The non-volatile memory 122 stores an image distance conversion program 123. The processing unit 110 reads the image distance conversion program 123 from the non-volatile memory 122 to the volatile memory 121 and executes the image distance conversion program 123. A code including an image distance conversion method is included.

第2A圖係顯示依據本發明一實施例中以3x3區域進行雙向掃瞄之示意圖。如第2A圖所示,在3x3區域中,待測像素p係具有8個相鄰像素q0~q7,其可分為第一集合N1={q0,q1,q2,q3}以及第二集合N2={q4,q5,q6,q7}。以下先對本案使用雙向掃瞄之距離轉換演算法之符號進行說明。 2A is a schematic diagram showing bidirectional scanning in a 3x3 region in accordance with an embodiment of the present invention. As shown in FIG. 2A, in the 3x3 region, the pixel to be tested p has 8 adjacent pixels q0 to q7, which can be divided into a first set N1={q0, q1, q2, q3} and a second set N2. ={q4,q5,q6,q7}. The following is a description of the symbol of the distance conversion algorithm using the two-way scanning in this case.

f係表示用以記錄歐幾里德轉換之距離的二維圖。F係表示前景(或物件)像素之集合。F’則表示背景像素之集合。 f is a two-dimensional map representing the distance of the Euclidean transformation. The F system represents a collection of foreground (or object) pixels. F' represents a collection of background pixels.

像素p之相對座標向量R(p)=(Rx,Ry),其係記錄了像素p與最近的背景像素之間的水平及垂直像素距離,其初始值為(0,0)。需注意的是,Rx(p)及Ry(p)係分別為水平像素距離及垂直像素距離。 The relative coordinate vector R(p)=(Rx, Ry) of the pixel p records the horizontal and vertical pixel distance between the pixel p and the nearest background pixel, and its initial value is (0, 0). It should be noted that R x (p) and R y (p) are the horizontal pixel distance and the vertical pixel distance, respectively.

h(p,q)係表示在像素p及q之開根號歐氏距離(squared Euclidean distance)的差值,其中像素q係包括於N1及N2之聯集,即q {q0,q1,q2,q3,q4,q5,q6,q7}。 h(p,q) is the difference between the squared Euclidean distances of the pixels p and q, where the pixel q is included in the union of N1 and N2, ie q {q0,q1,q2,q3,q4,q5,q6,q7}.

G(p,q)係表示像素p及q之相對座標的差值,其中像素q係包括於N1及N2之聯集,即q {q0,q1,q2,q3,q4,q5,q6, q7}。 G(p,q) represents the difference between the relative coordinates of the pixels p and q, where the pixel q is included in the union of N1 and N2, ie q {q0,q1,q2,q3,q4,q5,q6, q7}.

h(p,q)及G(p,q)係可用下列公式進行計算: h(p,q) and G(p,q) can be calculated by the following formula:

在進行雙向掃瞄之距離轉換時,都會先對輸入二元影像執行前進掃瞄以產生一中間影像,再用對中間影像執行後退掃瞄以得到輸出距離影像。 In the two-way scan distance conversion, a forward scan is performed on the input binary image to generate an intermediate image, and a backward scan is performed on the intermediate image to obtain an output distance image.

詳細而言,前進掃瞄係對二元影像套用前進掃瞄遮罩並依照循序掃瞄(raster scan)的方式由左而右、由上而下進行處理並產生中間影像。後退掃瞄係對中間影像套用後退掃瞄遮罩並依照反循序掃瞄(reverse raster scan)的方式由右而左、由下而上進行處理並產生輸出距離影像。 In detail, the forward scan applies a forward scan mask to the binary image and processes it from left to right, top to bottom, and produces an intermediate image in a raster scan manner. The back scan applies a back scan mask to the intermediate image and processes it from right to left, bottom to top, and produces an output distance image in a reverse raster scan.

在一實施例中,雙向掃瞄距離轉換之流程的虛擬程式碼(pseudo code)係如下所示:前進掃瞄: In one embodiment, the pseudo code of the bidirectional scan distance conversion process is as follows: forward scan:

後退掃瞄: Back scan:

然而,上述雙向掃瞄之流程中之最小值的運算會有資料相依性的問題。第2B圖及第2C圖分別表示前進掃瞄遮罩及後退掃瞄遮罩。詳細而言,如第2B圖所示,在前進掃瞄遮罩中之目前像素P的水平或垂直方向之相鄰像素(例如q0及q2)之距離為d0,與像素q1及q3之距離為d1。類似地,在後退掃瞄遮罩中之目前像素P的水平或垂直方向之相鄰像素(例如q4及q6)之距離為d0,與像素q5及q7之距離為d1。在一實施例中,d0=1且d1=2。 However, the operation of the minimum value in the above two-way scanning process has a problem of data dependency. Figures 2B and 2C show the forward scan mask and the backward scan mask, respectively. In detail, as shown in FIG. 2B, the distance between adjacent pixels (for example, q0 and q2) of the horizontal or vertical direction of the current pixel P in the forward scanning mask is d0, and the distance from the pixels q1 and q3 is D1. Similarly, the distance between adjacent pixels (for example, q4 and q6) of the horizontal or vertical direction of the current pixel P in the backward scanning mask is d0, and the distance from the pixels q5 and q7 is d1. In an embodiment, d0=1 and d1=2.

在套用前進掃瞄遮罩對第2D圖中之輸入影像的第i列及第i+1列進行處理時,可看出在計算像素B’之距離時,其運算會用到A’像素之距離;在計算像素C’之距離時,其運算會用到B’像素之距離;在計算像素D’之距離時,其運算會用到C’像素之距離。故上述計算方式係具有資料相依性。 When applying the forward scan mask to process the ith column and the i+1th column of the input image in the 2D image, it can be seen that when calculating the distance of the pixel B', the operation uses the A' pixel. Distance; when calculating the distance of pixel C', its operation will use the distance of B' pixel; when calculating the distance of pixel D', its operation will use the distance of C' pixel. Therefore, the above calculation method has data dependence.

本發明中之距離轉換方向係將上述前進掃瞄(例如為第一掃瞄)之流程分為第一比較處理及第一更新處理,並將上述後退掃瞄(例如為第二掃瞄)之流程分為第二比較處理及第二更新處理,藉以消除資料相依性之問題。 In the distance conversion direction of the present invention, the flow of the forward scan (for example, the first scan) is divided into a first comparison process and a first update process, and the backward scan (for example, the second scan) is performed. The process is divided into a second comparison process and a second update process to eliminate the problem of data dependency.

舉例來說,在前進掃瞄之第一比較處理一開始,若目標像素為一前景像素,則將f(p)設定為無限大(INF)。在實作上,INF值可為一非常大的數值,例如可為無號整數(unsigned integer)之上限值。 For example, at the beginning of the first comparison processing of the forward scan, if the target pixel is a foreground pixel, f(p) is set to infinity (INF). In practice, the INF value can be a very large value, such as an unsigned integer upper limit.

接著,處理單元110係執行第一程式碼:步驟(1)對q={q1,q2,q3}進行遞迴運算(iteration)以計算最小值min(f(q),f(p)+h(p,q)),並且將結果指派至f(p)。需注意的是,在上述運算中並未考慮q=q0的情況。 Next, the processing unit 110 executes the first code: step (1) performs an iteration on q={q1, q2, q3} to calculate a minimum value min(f(q), f(p)+h (p, q)) and assign the result to f(p). It should be noted that the case of q=q0 is not considered in the above calculation.

步驟(2)若存在q包括了min(f(q),f(p)+h(p,q))且(f(p)+h(p,q)<f(p),則將R(p)更新為R(q)+G(p,q),並將緩衝器中關於目標像素之索引x之數值更新為f(p)。 Step (2) If q includes min(f(q), f(p)+h(p,q)) and (f(p)+h(p,q)<f(p), then R (p) is updated to R(q)+G(p, q), and the value of the index x of the target pixel in the buffer is updated to f(p).

在前進掃瞄之第一更新處理,處理器係執行第二程式碼: In the first update processing of the forward scan, the processor executes the second code:

步驟(1):若在緩衝器中關於目標像素之索引x的數值並不是INF,則將緩衝器中之數值與f(q0)+f(p,q0)相比較。 Step (1): If the value of the index x with respect to the target pixel in the buffer is not INF, the value in the buffer is compared with f(q0)+f(p, q0).

步驟(2):若緩衝器中之數值小於f(q0)+f(p,q0),則將目標像素設定為緩衝器中之數值。若緩衝器中之數值大於或等於f(q0)+f(p,q0),則將目標像素設定為f(q0)+f(p,q0)並更新R(p)為R(q0)+G(p,q0)。 Step (2): If the value in the buffer is less than f(q0)+f(p, q0), the target pixel is set to the value in the buffer. If the value in the buffer is greater than or equal to f(q0)+f(p,q0), set the target pixel to f(q0)+f(p,q0) and update R(p) to R(q0)+ G(p, q0).

需注意的是,在第一程式碼中已經去除了運算時的資料相依性,但在第二程式碼中仍然有資料相依性,但因為在第二程式碼中之運算較簡單,且是針對每一列的像素分別依序進行處理,因此迴圈相依性很小,其相關運算只佔了整體運算的一小部份。 It should be noted that the data dependency of the operation has been removed in the first code, but there is still data dependency in the second code, but because the operation in the second code is simpler and is aimed at The pixels of each column are processed sequentially, so the loop dependence is small, and the correlation operation only accounts for a small part of the overall operation.

第3A圖係顯示依據本發明一實施例中之掃瞄遮罩的示意圖。第3B圖係顯示依據本發明第3A圖之實施例中之前進掃瞄遮罩的示意圖。第3C圖係顯示依據本發明第3A圖之實施例中之後退掃瞄遮罩的示意圖。 Figure 3A is a schematic illustration of a scanning mask in accordance with an embodiment of the present invention. Figure 3B is a schematic illustration of a prior scanning mask in accordance with an embodiment of Figure 3A of the present invention. Figure 3C is a schematic view showing the back-sweeping mask in the embodiment of Figure 3A of the present invention.

在一實施例中,本發明係採用3x3斜面遮罩(chamfer mask)以計算影像中之物件的距離,如第3A圖所示。當使用雙向掃瞄以計算影像中之物件的距離時,係分別使用前進掃瞄遮罩及後退掃瞄遮罩,如第3B圖及第3C圖所示。需注意的是,影像背景之像素數值可設為無限大,在實作上可為一非常大的數值。例如前景影像之像素的距離可設定為0,且背景部分之像素的距離可設定為無號整數之上限值。 In one embodiment, the present invention employs a 3x3 chamfer mask to calculate the distance of an object in an image, as shown in Figure 3A. When using a two-way scan to calculate the distance of an object in an image, the forward scan mask and the back scan mask are used, respectively, as shown in Figures 3B and 3C. It should be noted that the pixel value of the image background can be set to infinity, which can be a very large value in practice. For example, the distance of the pixels of the foreground image can be set to 0, and the distance of the pixels of the background portion can be set to the upper limit of the unsigned integer.

第3D圖係顯示依據本發明一實施例中之前進掃瞄遮罩中之像素的示意圖。第3E圖係顯示依據本發明一實施例中之後退掃瞄遮罩中之像素的示意圖。若使用第3B圖中之前進掃瞄遮罩,像素P為待計算的像素,且像素V0~V3係為在前進掃瞄遮罩中像素P的鄰近像素。依照傳統的前進掃瞄計算方式則會計算像素P之數值為:P=min(P+0,V0+3,V1+4,V2+3,V3+4),如第3D圖所示,此計算方式會使用到像素P之左方像素,故會有資料相依性的問題存在。 3D is a schematic diagram showing pixels in a pre-scan mask in accordance with an embodiment of the present invention. Figure 3E is a schematic diagram showing the pixels in the back-sweep mask in accordance with an embodiment of the present invention. If the pre-scan mask is used in FIG. 3B, the pixel P is the pixel to be calculated, and the pixels V0-V3 are adjacent pixels of the pixel P in the forward scan mask. According to the traditional forward scan calculation method, the value of the pixel P is calculated as: P=min(P+0, V0+3, V1+4, V2+3, V3+4), as shown in the 3D figure, The calculation method uses the pixel to the left of the pixel P, so there is a problem of data dependency.

類似地,若使用第3C圖中之後退掃瞄遮罩,像素P為待計算的像素,且像素V0~V3係為在後退掃瞄遮罩中像素P的鄰近像素。依照傳統的後退掃瞄計算方式則會計算像素P之數值為:P=min(P+0,V0+4,V1+3,V2+4,V3+3),如第3E圖所示,此計算方式會使用到像素P之右方像素,故同樣會有資料 相依性的問題存在。 Similarly, if the back-sweep mask in FIG. 3C is used, the pixel P is the pixel to be calculated, and the pixels V0-V3 are adjacent pixels of the pixel P in the back-scan mask. According to the traditional back scan calculation method, the value of the pixel P is calculated as: P=min (P+0, V0+4, V1+3, V2+4, V3+3), as shown in Fig. 3E, The calculation method will use the pixel to the right of the pixel P, so there will be data as well. The problem of dependency exists.

在一實施例中,本發明中之距離轉換方向係將上述前進掃瞄之流程分為第一比較處理及第一更新處理,並將上述後退掃瞄之流程分為第二比較處理及第二更新處理,藉以消除資料相依性之問題。 In an embodiment, the distance conversion direction in the present invention divides the flow of the forward scan into a first comparison process and a first update process, and divides the flow of the backward scan into a second comparison process and a second process. Update processing to eliminate the problem of data dependencies.

第4A~4C圖係顯示本發明一實施例中之前進掃瞄中之第一比較處理的示意圖。在第4A圖中,若輸入影像中之當前列(例如第i+1列)之目前像素為B’(即第一目前像素),則前進掃瞄的第一比較處理會將目前像素B’更新為min((B’+0),(A+4),(B+3),(C+4)),即使用如第3B圖之前進掃瞄遮罩中之上一列(例如第i列)的像素(即左上方像素A、上方像素B、及右上方像素C)及目前像素B’進行運算。 4A to 4C are views showing a first comparison process in the previous scanning in an embodiment of the present invention. In FIG. 4A, if the current pixel of the current column (for example, the (i+1)th column) in the input image is B' (ie, the first current pixel), the first comparison processing of the forward scan will be the current pixel B'. Updated to min((B'+0), (A+4), (B+3), (C+4)), ie using the previous column in the scan mask as before Figure 3B (eg i The pixels of the column (ie, the upper left pixel A, the upper pixel B, and the upper right pixel C) and the current pixel B' are operated.

在第4B圖中,若輸入影像中之當前列(例如第i+1列)之目前像素為C’,則前進掃瞄的第一比較處理會將目前像素C’更新為min((C’+0),(B+4),(C+3),(D+4)),即使用如第3B圖之前進掃瞄遮罩中之上一列(例如第i列)的像素(即左上方像素B、上方像素C、及右上方像素D)及目前像素C’進行運算。 In FIG. 4B, if the current pixel of the current column (eg, the (i+1)th column) in the input image is C', the first comparison process of the forward scan updates the current pixel C' to min ((C'). +0), (B+4), (C+3), (D+4)), that is, using pixels in the upper column (for example, the i-th column) in the scanning mask before the 3B image (ie, upper left) The square pixel B, the upper pixel C, and the upper right pixel D) and the current pixel C' are operated.

在第4C圖中,若輸入影像之當前列(例如第i+1列)之目前像素為D’,則前進掃瞄的第一比較處理會將目前像素D’更新為min((D’+0),(C+4),(D+3),(E+4)),即使用如第3B圖之前進掃瞄遮罩中之上一列(例如第i列)的像素(即左上方像素C、上方像素D、及右上方像素E)及目前像素D’進行運算。 In FIG. 4C, if the current pixel of the current column of the input image (eg, the (i+1)th column) is D', the first comparison process of the forward scan updates the current pixel D' to min ((D'+ 0), (C+4), (D+3), (E+4)), that is, using pixels in the upper column (for example, the i-th column) in the scanning mask before the 3B image (ie, upper left) The pixel C, the upper pixel D, and the upper right pixel E) and the current pixel D' are operated.

在前進掃瞄之第一比較處理中,即以類似於第4A~4C圖之流程以更新目前像素。當對輸入影像中之當前列(例 如第i+1列)進行前進掃瞄的第一比較處理後,會產生一前進掃瞄中間列影像(例如第一中間列影像)。需注意的是,在第一比較處理中,並未使用到目前像素之左方像素。例如在進行目前像素B’之第一比較處理時,並未使用到目前像素B’之左方像素A’,所以並不會產生資料相依性的問題。 In the first comparison process of the forward scan, the flow is similar to the process of FIGS. 4A-4C to update the current pixel. When the current column in the input image (example) After the first comparison processing of the forward scan as in the (i+1)th column, a forward scan intermediate column image (for example, the first intermediate column image) is generated. It should be noted that in the first comparison process, the left pixel of the current pixel is not used. For example, when the first comparison processing of the current pixel B' is performed, the left pixel A' of the current pixel B' is not used, so that there is no problem of data dependency.

第4D~4F圖係顯示本發明一實施例中之前進掃瞄中之第一更新處理的示意圖。當對輸入影像中之當前列(例如第i+1列)的所有像素進行前進掃瞄的第一比較處理後,會產生一前進掃瞄中間列影像(例如第一中間區段影像)。接著,對前進掃瞄中間列影像進行前進掃瞄的第一更新處理。如第4D圖所示,若前進掃瞄中間列影像中之目前像素為B’,則對像素B’進行第一更新處理時會比較像素B’以及其左方像素A’加上距離值,並取最小值以更新像素B’,例如可用下式表示:B’=min(B’,A’+3)。 4D to 4F are diagrams showing the first update processing in the previous scanning in an embodiment of the present invention. When the first comparison process of the forward scan of all the pixels in the current column (for example, the (i+1)th column) in the input image is generated, a forward scan intermediate column image (for example, the first intermediate segment image) is generated. Next, a first update process of the forward scan of the forward scan intermediate column image is performed. As shown in FIG. 4D, if the current pixel in the forward scan middle column image is B', the pixel B' is compared with the pixel B' and the left pixel A' plus the distance value when the pixel B' is subjected to the first update process. And taking the minimum value to update the pixel B', for example, can be expressed by the following formula: B' = min (B', A' + 3).

如第4E圖所示,若前進掃瞄中間列影像中之目前像素為C’,則對像素C’進行第一更新處理時會比較像素C’以及其左方像素B’加上距離值,並取最小值以更新像素C’,例如可用下式表示:C’=min(C’,B’+3)。 As shown in FIG. 4E, if the current pixel in the forward scan middle column image is C', the pixel C' is compared with the pixel C' and the left pixel B' is added to the distance value when the first update process is performed on the pixel C'. And taking the minimum value to update the pixel C', for example, can be expressed by the following formula: C' = min (C', B' + 3).

如第4F圖所示,若前進掃瞄中間列影像中之目前像素為D’,則對像素D’進行第一更新處理時會比較像素D’以及其左方像素C’加上距離值,並取最小值以更新像素D’,例如可用下式表示:D’=min(D’,C’+3)。當對目前列的前進掃瞄中間列影像進行前進掃瞄的第一更新處理後,即表示已完成目前列的前進掃瞄並產生一中間列影像以更新輸入影像中之目前列 的像素數值。依此類推,對輸入影像中之每一列的像素分別依序進行第一比較處理及第一更新處理以產生一中間影像。 As shown in FIG. 4F, if the current pixel in the forward scan middle column image is D', the pixel D' and the left pixel C' plus the distance value are compared when the pixel D' is subjected to the first update process. And taking the minimum value to update the pixel D', for example, can be expressed by the following formula: D' = min (D', C' + 3). After performing the first update processing of the forward scan of the current scan image of the middle column, it indicates that the forward scan of the current column has been completed and a middle column image is generated to update the current column in the input image. The pixel value. And so on, the first comparison process and the first update process are sequentially performed on the pixels of each column in the input image to generate an intermediate image.

第4G~4I圖係顯示本發明一實施例中之後退掃瞄中之第二比較處理的示意圖。當完成第4A~4F圖所示之輸入影像中之每一列像素之前進掃瞄的第一比較處理及第一更新處理後,會產生一中間影像。在一實施例中,後退掃瞄係分為第二比較處理及第二更新處理,且依序對中間影像中之每一列的像素進行第二比較處理及第二更新處理。後退掃瞄(包括第二比較處理及第二更新處理)之掃瞄順序係以由下而上、由右而左的順序進行反循序掃瞄(inverse raster scan)。 The 4G~4I diagram shows a schematic diagram of a second comparison process in the backward scan in an embodiment of the present invention. An intermediate image is generated after the first comparison process and the first update process of the scan before each column of the input image shown in FIGS. 4A-4F is completed. In an embodiment, the back scan system is divided into a second comparison process and a second update process, and the second comparison process and the second update process are sequentially performed on the pixels of each column in the intermediate image. The scan sequence of the backward scan (including the second comparison processing and the second update processing) performs an inverse raster scan in a bottom-up, right-to-left order.

接著,對前進掃瞄所產生的中間影像之目前列(例如第i-1列)進行後退掃瞄之第二比較處理。如第4G圖所示,若中間影像之目前列之目前像素為D’,則後退掃瞄的第二比較處理會將目前列的目前像素D’更新為min((D’+0),(C+4),(D+3),(E+4)),即使用如第3C圖之後退掃瞄遮罩中之下一列(例如第i列)的像素(即左下方像素C、下方像素D、及右下方像素E)及目前像素D’進行運算。 Next, a second comparison process of the backward scan is performed on the current column (for example, the i-1th column) of the intermediate image generated by the forward scan. As shown in FIG. 4G, if the current pixel of the intermediate image is D', the second comparison processing of the backward scan updates the current pixel D' of the current column to min((D'+0), ( C+4), (D+3), (E+4)), that is, use the pixel in the lower column (for example, the i-th column) in the scan mask as shown in FIG. 3C (ie, the lower left pixel C, below) The pixel D and the lower right pixel E) and the current pixel D' are operated.

如第4H圖所示,若中間影像之目前列(例如第i-1列)之目前像素為C’,則後退掃瞄的第二比較處理會將目前列之目前像素C’更新為min((C’+0),(B+4),(C+3),(D+4)),即使用如第3C圖之後退掃瞄遮罩中之下一列(例如第i列)的像素(即左下方像素B、下方像素C、及右下方像素D)及目前像素C’進行運算。 As shown in FIG. 4H, if the current pixel of the current column (for example, the i-1th column) of the intermediate image is C', the second comparison processing of the backward scan updates the current pixel C' of the current column to min ( (C'+0), (B+4), (C+3), (D+4)), that is, using the pixel in the lower column (for example, the i-th column) in the back-sweep mask as in FIG. 3C (ie, the lower left pixel B, the lower pixel C, and the lower right pixel D) and the current pixel C' are calculated.

如第4I圖所示,若中間影像之目前列之目前像素為 B’,則後退掃瞄的第二比較處理會將目前像素B’更新為min((B’+0),(A+4),(B+3),(C+4)),即使用如第3C圖之後退掃瞄遮罩中之下一列(例如第i列)的像素(即左下方像素A、下方像素B、及右下方像素C)及目前像素B’進行運算。 As shown in Figure 4I, if the current pixel of the intermediate image is currently B', the second comparison processing of the back scan will update the current pixel B' to min((B'+0), (A+4), (B+3), (C+4)), ie use As shown in FIG. 3C, the pixels in the lower column (for example, the i-th column) of the scan mask (ie, the lower left pixel A, the lower pixel B, and the lower right pixel C) and the current pixel B' are operated.

在後退掃瞄之目前列之第二比較處理中,即以類似於第4G~4I圖之流程以更新中間影像之目前列之目前像素。當對中間影像之目前列進行後退掃瞄的第二比較處理後,會產生一後退掃瞄中間列影像(例如第二中間區段影像)以更新中間影像中之目前列的像素數值。需注意的是,在第二比較處理中,並未使用到目前列之目前像素之右方像素。例如在進行目前像素D’之第二比較處理時,並未使用到目前像素D’之左方像素E’,所以並不會產生資料相依性的問題。 In the second comparison process of the current backward scan, the process is similar to the process of 4G~4I to update the current pixel of the current image of the intermediate image. After the second comparison processing of the backward scan of the current image of the intermediate image, a backward scan intermediate column image (for example, the second intermediate segment image) is generated to update the pixel value of the current column in the intermediate image. It should be noted that in the second comparison process, the right pixel of the current pixel currently listed is not used. For example, when the second comparison processing of the current pixel D' is performed, the left pixel E' of the current pixel D' is not used, so that there is no problem of data dependency.

第4J~4L圖係顯示本發明一實施例中之後退掃瞄中之第二更新處理的示意圖。當對中間影像之目前列進行後退掃瞄的第二比較處理後,會產生後退掃瞄中間列影像。接著,對後退掃瞄中間列影像進行後退掃瞄的第二更新處理。如第4J圖所示,若後退掃瞄中間列影像中之目前像素為D’,則對像素D’進行第二更新處理時會比較像素D’以及其右方像素E’加上距離值,並取最小值以更新像素B’,例如可用下式表示:D’=min(D’,E’+3)。 The 4th through 4th drawings show a schematic diagram of a second update process in the backward scan in an embodiment of the present invention. When the second comparison process of the backward scan of the current column of the intermediate image is performed, a reverse scan intermediate column image is generated. Next, a second update process of the backward scan of the backward scan intermediate column image is performed. As shown in FIG. 4J, if the current pixel in the backward scan middle column image is D′, the second update process on the pixel D′ compares the pixel D′ and the right pixel E′ with the distance value. And taking the minimum value to update the pixel B', for example, can be expressed by the following formula: D' = min (D', E' + 3).

如第4K圖所示,若後退掃瞄中間列影像中之目前像素為C’,則對像素C’進行第二更新處理時會比較像素C’以及其右方像素D’加上距離值,並取最小值以更新像素C’,例如可用下式表示:C’=min(C’,D’+3)。 As shown in FIG. 4K, if the current pixel in the backward scan middle column image is C', the second update process is performed on the pixel C′, and the pixel C′ and the right pixel D′ are compared with the distance value. And taking the minimum value to update the pixel C', for example, can be expressed by the following formula: C' = min (C', D' + 3).

如第4L圖所示,若後退掃瞄中間列影像中之目前像素為B’,則對像素B’進行第二更新處理時會比較像素B’以及其右方像素C’加上距離值,並取最小值以更新像素B’,例如可用下式表示:B’=min(B’,C’+3)。當完成如第4J~4L圖中對後退掃瞄中間列影像之目前列的後退掃瞄的第二更新處理後,即表示已完成目前列的後退掃瞄。依此類推,對中間影像中之每一列的像素分別依序(例如以反循序掃瞄之順序)進行第二比較處理及第二更新處理後可產生一輸出影像,其中輸出影像中之各像素之數值即表示在輸入影像中之相應的各像素的距離資訊。 As shown in FIG. 4L, if the current pixel in the backward scan middle column image is B', the second update processing on the pixel B' compares the pixel B' and the right pixel C' with the distance value. And taking the minimum value to update the pixel B', for example, can be expressed by the following formula: B' = min (B', C' + 3). When the second update processing of the backward scan of the current column of the backward scan middle column image in the 4th to 4th drawings is completed, it means that the backward scan of the current column has been completed. And so on, the pixels of each column in the intermediate image are sequentially (for example, in the order of anti-sequential scanning), and the second comparison processing and the second updating processing are performed to generate an output image, wherein each pixel in the output image is generated. The value indicates the distance information of each pixel in the input image.

需注意的是,為了便於說明,在第2A-2D圖、第3A-3E圖、以及第4A-4L圖之實施例均是先以循序掃瞄之順序(例如為第一順序)進行前進掃瞄,再以反循序掃瞄之順序(例如為第二順序)進行後退掃瞄。本發明並不限定於上述順序的掃瞄方式。 It should be noted that, for convenience of description, the embodiments in the 2A-2D, 3A-3E, and 4A-4L modes are first scanned in the order of sequential scanning (for example, in the first order). Aiming, and then performing backward scanning in the order of anti-sequential scanning (for example, in the second order). The present invention is not limited to the scanning method of the above sequence.

在一些實施例中,本發明係可先以反循序掃瞄之順序進行後退掃瞄,再以循序掃瞄之順序進行前進掃瞄。意即,反循序掃瞄為第一順序,且循序掃瞄為第二順序。舉例來說,若反循序掃瞄為第一順序,則會先以後退掃瞄遮罩(此時為第一遮罩)對輸入影像進行第一掃瞄(即後退掃瞄),其中第一掃瞄包括第一比較處理及第一更新處理。然而,在此處是對輸入影像先進行後退掃瞄,且對輸入影像之每一列的像素進行第一比較處理後會產生一後退掃瞄列影像(例如為第一中間區段影像)。第一更新處理則是對第一中間區段影像之像素進行更新。當完成輸入影像之每一列像素的第一掃瞄後,會產生一中 間影像。上述操作方式係類似於前述實施例中關於後退掃瞄的部分,故其細節於此不再贅述。 In some embodiments, the present invention may perform a backward scan in the order of anti-sequential scanning, and then perform a forward scan in the order of sequential scanning. That is, the anti-sequential scan is in the first order, and the sequential scan is in the second order. For example, if the anti-sequential scan is in the first order, the scan mask (in this case, the first mask) is first retracted to perform a first scan (ie, back scan) on the input image, where the first The scan includes a first comparison process and a first update process. However, here, the input image is first back-scanned, and a first comparison process is performed on the pixels of each column of the input image to generate a back scan column image (for example, a first intermediate segment image). The first update process updates the pixels of the first intermediate segment image. When the first scan of each column of pixels of the input image is completed, a middle Image. The above operation mode is similar to the portion of the foregoing embodiment regarding the back scan, and thus the details thereof will not be described herein.

接著,再以循序掃瞄(例如為第二順序),以對應於上述後退掃瞄遮罩的前進掃瞄遮罩(例如為第二遮罩),對中間影像進行第二掃瞄(例如為前進掃瞄),其中第二掃瞄包括第二比較處理及第二更新處理。然而,在此處是對中間影像進行前進掃瞄,且對中間影像之每一列的像素進行第二比較處理後會產生一前進掃瞄列影像(例如為第二中間區段影像)。第二更新處理則是對第二中間區段影像之像素進行更新。對中間影像中之每一列的像素分別以第二順序進行第二比較處理及第二更新處理後可產生一輸出影像,其中輸出影像中之各像素之數值即表示在輸入影像中之相應的各像素的距離資訊。上述操作方式係類似於前述實施例中關於前進掃瞄的部分,故其細節於此不再贅述。 Then, in a sequential scan (for example, in a second order), a second scan is performed on the intermediate image by a forward scan mask (for example, a second mask) corresponding to the backward scan mask (for example, Forward scan), wherein the second scan includes a second comparison process and a second update process. However, here, the intermediate image is scanned forward, and a second comparison process is performed on the pixels of each column of the intermediate image to generate a forward scan column image (for example, a second intermediate segment image). The second update process updates the pixels of the second intermediate segment image. A second comparison process and a second update process are performed on the pixels of each column in the intermediate image to generate an output image, wherein the values of the pixels in the output image represent corresponding ones in the input image. The distance information of the pixel. The above operation mode is similar to the portion of the foregoing embodiment regarding forward scanning, and thus the details thereof will not be described herein.

第5圖係顯示依據本發明一實施例中之不同掃瞄遮罩的示意圖。在一實施例中,除了3x3斜面遮罩之外,本發明亦可使用其他類型的掃瞄遮罩,例如城市方塊(city block)遮罩、棋盤(chessboard)遮罩、5x5斜面遮罩、或7x7斜面遮罩等等,如第5圖所示。在第5圖中之各遮罩類型係包括前進掃瞄遮罩及後退掃瞄遮罩。前進掃瞄遮罩在方框內之部分遮罩係用於進行前進掃瞄之第一比較處理,例如在3x3斜面遮罩中之前進掃瞄遮罩裡為0之數值,其為進行第一比較處理時之目前像素的遮罩像素。前進掃瞄遮罩裡標示為「-」之像素則表示不進行處理。 Figure 5 is a schematic diagram showing different scanning masks in accordance with an embodiment of the present invention. In an embodiment, in addition to a 3x3 beveled mask, other types of scanning masks may be used in the present invention, such as a city block mask, a chessboard mask, a 5x5 beveled mask, or 7x7 beveled masks, etc., as shown in Figure 5. Each mask type in Figure 5 includes a forward scan mask and a back scan mask. The partial mask of the forward scan mask in the box is used for the first comparison processing of the forward scan, for example, the value of 0 in the front scan mask in the 3x3 bevel mask, which is the first Compare the mask pixels of the current pixel at the time of processing. Pixels marked "-" in the forward scan mask indicate no processing.

需注意的是,3x3斜面遮罩之前進掃瞄遮罩中以圓圈標示3之數值則沒有用於第一比較處理,此即第一比較處理並未使用目前像素之左方像素。類似地,在3x3斜面遮罩中之後退掃瞄遮罩裡為0之數值,其為進行第二比較處理時之目前像素的遮罩像素。需注意的是,3x3斜面遮罩之後退掃瞄遮罩中以圓圈標示3之數值則沒有用於第二比較處理,此即第二比較處理並未使用目前像素之右方像素。後退掃瞄遮罩裡標示為「-」之像素則表示不進行處理。在第5圖中之其他遮罩類型亦是採用類似的方式進行處理。 It should be noted that the value of the 3x3 bevel mask in the front scan mask marked with a circle is not used for the first comparison process, and the first comparison process does not use the left pixel of the current pixel. Similarly, in the 3x3 bevel mask, there is a value of 0 in the back scan mask, which is the mask pixel of the current pixel when the second comparison process is performed. It should be noted that the value of the 3x3 bevel mask in the back-sweep mask marked with a circle is not used for the second comparison process, and the second comparison process does not use the right pixel of the current pixel. Pixels marked "-" in the back scan mask indicate no processing. The other mask types in Figure 5 are also processed in a similar manner.

第6圖係顯示依據本發明一實施例中之影像距離轉換方法的流程圖。 Figure 6 is a flow chart showing a method of image distance conversion in accordance with an embodiment of the present invention.

在步驟S610,對一輸入影像之各像素依第一順序套用一第一遮罩以進行一第一掃瞄以產生一中間影像,其中第一掃瞄包括一第一比較處理及一第一更新處理。舉例來說,若第一順序為循序掃瞄,則第一遮罩為前進掃瞄遮罩。此時,對輸入影像之目前列所進行之第一比較處理係使用第一目前像素及其上方的相鄰像素、或第一目前像素及其上方、左上方、及右上方之相鄰像素,而不與在輸入影像中在第一順序上位於第一目前像素之前且位於相同之一第一目前區段的像素比較。(在此例子中,第一目前區段為在輸入影像中之第一目前像素之第一目前列,且第一比較處理不與與第一目前像素位於相同的第一目前列之左方像素比較)。 In step S610, a first mask is applied to each pixel of an input image in a first order to perform a first scan to generate an intermediate image, wherein the first scan includes a first comparison process and a first update. deal with. For example, if the first sequence is sequential scanning, the first mask is a forward scanning mask. At this time, the first comparison processing performed on the current column of the input image uses the first current pixel and the adjacent pixel above it, or the first current pixel and the adjacent pixels above, above, and above the upper right pixel, Rather than being compared to pixels located in the first order preceding the first current pixel and in the same first current segment in the input image. (In this example, the first current segment is the first current column of the first current pixel in the input image, and the first comparison process is not the same as the left pixel of the first current column that is located at the same time as the first current pixel. Compare).

若第一順序為反循序掃瞄,則第一遮罩為後退掃瞄遮罩,對輸入影像之目前列所進行之第一比較處理係使用在 輸入影像中之第一目前像素及其下方的相鄰像素(例如使用第5圖中之城市方塊遮罩的前進掃瞄遮罩)、或第一目前像素及其下方、左下方、及右下方之相鄰像素(例如使用第5圖中之3x3、5x5、7x7斜面遮罩或棋盤遮罩的前進掃瞄遮罩),而不與在輸入影像中在第一順序上位於第一目前像素之前且位於相同之一第一目前區段的像素比較。在此例子中,第一目前區段為在輸入影像中之第一目前像素之第一目前列,且第一比較處理不與與第一目前像素位於相同的第一目前列之右方像素)比較。意即,無論第一順序為循序掃瞄或反循序掃瞄(即無論第一遮罩為前進掃瞄遮罩或後退掃瞄遮罩),第一比較處理係使用第一目前像素,而不與在輸入影像中在第一順序上位於第一目前像素之前且位於相同之一第一目前區段的像素比較。 If the first sequence is anti-sequential scan, the first mask is a back scan mask, and the first comparison processing performed on the current column of the input image is used. Inputting the first current pixel in the image and the adjacent pixel below it (for example, using the forward scan mask of the city square mask in FIG. 5), or the first current pixel and its lower, lower left, and lower right Adjacent pixels (eg, using the 3x3, 5x5, 7x7 bevel mask, or the forward scan mask of the checkerboard mask in Figure 5), rather than before the first current pixel in the first order in the input image And a comparison of pixels located in the same first current segment. In this example, the first current segment is the first current column of the first current pixel in the input image, and the first comparison process is not in the right pixel of the first current column that is the same as the first current pixel. Comparison. That is, regardless of whether the first order is a sequential scan or a reverse scan (ie, whether the first mask is a forward scan mask or a backward scan mask), the first comparison processing uses the first current pixel instead of A comparison is made to pixels in the input image that precede the first current pixel in the first order and are located in the same one of the first current segments.

詳細而言,因為要消除在第一順序上位於第一目前像素之前且位於相同第一目前區段之像素(可為左方、右方、上方、或下方的像素)之間運算的資料相依性,本發明係在第一比較處理中使用第一目前像素及其上方區段或下方區段的相鄰像素(視所使用的掃瞄順序及掃瞄遮罩而定),但不包括在第一順序上位於第一目前像素之前且位於相同第一目前區段之像素。第一更新處理係針對輸入影像中每一列之像素進行完第一比較處理後所產生之第一中間區段影像,再依序更新在第一中間區段影像所計算出之距離的最小值。 In detail, because the data dependency between the pixels located in the first order before the first current pixel and located in the pixels of the same first current segment (which may be left, right, above, or below) is to be eliminated. The present invention uses the first current pixel and its adjacent upper or lower adjacent pixels in the first comparison process (depending on the scanning order used and the scanning mask), but not included in Pixels that precede the first current pixel and are located in the same first current segment in the first order. The first update processing is to perform the first intermediate segment image generated after the first comparison processing on the pixels of each column in the input image, and sequentially update the minimum value of the distance calculated in the first intermediate segment image.

在步驟S620,對中間影像之各像素依一第二順序套用一第二遮罩以進行一第二掃瞄以取得輸入影像中之各像素之一距離資訊,其中第二掃瞄包括一第二比較處理及一第二 更新處理。舉例來說,若第一順序為循序掃瞄,則第二順序則為反循序掃瞄,且第二遮罩為相應於前進掃瞄遮罩(第一遮罩)之一後退掃瞄遮罩(第二遮罩)。此時,對中間影像之目前列所進行之第二比較處理係使用在中間影像中之第二目前像素及其下方的相鄰像素(例如使用第5圖中之城市方塊遮罩的後退掃瞄遮罩)、或第二目前像素及其下方、左下方、及右下方之相鄰像素(例如使用第5圖中之3x3、5x5、7x7斜面遮罩或棋盤遮罩的後退掃瞄遮罩),而不與在中間影像中在第二順序上位於第二目前像素之前且位於相同之第二目前區段的像素比較。在此例子中,第二目前區段為在中間影像中之第二目前像素之第二目前列,且第二比較處理不與與第二目前像素位於相同的第二目前列之右方像素比較。 In step S620, a second mask is applied to each pixel of the intermediate image in a second order to perform a second scan to obtain distance information of each pixel in the input image, wherein the second scan includes a second Comparative processing and a second Update processing. For example, if the first sequence is sequential scanning, the second sequence is anti-sequential scanning, and the second mask is one of the backward scanning masks corresponding to the forward scanning mask (first mask). (second mask). At this time, the second comparison processing performed on the current column of the intermediate image uses the second current pixel in the intermediate image and the adjacent pixel below it (for example, using the backward scan of the city square mask in FIG. 5) a mask, or a second current pixel and its adjacent pixels below, to the lower left, and to the lower right (eg, a back scan mask using a 3x3, 5x5, 7x7 bevel mask or a checkerboard mask in Figure 5) Instead of being compared to pixels in the second image that are in the second order before the second current pixel and in the same second current segment. In this example, the second current segment is the second current column of the second current pixel in the intermediate image, and the second comparison process is not compared with the right pixel of the second current column that is the same as the second current pixel. .

若第一順序為反循序掃瞄,則第二順序則為循序掃瞄,且第二遮罩為相應於後退掃瞄遮罩(第一遮罩)之一前進掃瞄遮罩(第二遮罩)。此時,對中間影像之目前列所進行之第二比較處理係使用第二目前像素及其上方的相鄰像素、或第二目前像素及其上方、左上方、及右上方之相鄰像素,而不與在中間影像中在第二順序上位於第二目前像素之前且位於相同之第二目前區段的像素比較。意即,無論第二順序為循序掃瞄或反循序掃瞄(即無論第二遮罩為前進掃瞄遮罩或後退掃瞄遮罩),第二比較處理係使用第二目前像素,而不與在中間影像中在第二順序上之第二目前像素之相鄰像素比較。在此例子中,第二目前區段為在中間影像中之第二目前像素之第二目前列,且第二比較處理不與與第二目前像素位於相同的第二目前 列之左方像素比較。 If the first sequence is a reverse sequential scan, the second sequence is a sequential scan, and the second mask is a forward scan mask corresponding to one of the backward scan masks (first mask) (second cover) cover). At this time, the second comparison processing performed on the current column of the intermediate image uses the second current pixel and the adjacent pixel above it, or the second current pixel and the adjacent pixels above, above, and above the upper right pixel, Rather than comparing pixels in the second image that are in the second order before the second current pixel and in the same second current segment. That is, regardless of whether the second sequence is a sequential scan or a reverse scan (ie, whether the second mask is a forward scan mask or a backward scan mask), the second comparison processing uses the second current pixel instead of Compare with adjacent pixels of the second current pixel in the second sequence in the intermediate image. In this example, the second current segment is the second current column of the second current pixel in the intermediate image, and the second comparison process is not the same as the second current pixel with the second current pixel. The pixel comparison on the left of the column.

詳細而言,因為要消除在第二順序上位於第二目前像素之前且位於相同第二目前區段之像素(可為左方、右方、上方、或下方的相鄰像素)之間運算的資料相依性,本發明係在第二比較處理中係使用在中間影像中之第二目前像素及其上方區段或下方區段的相鄰像素(視所使用的掃瞄順序及掃瞄遮罩而定),但不包括在中間影像中在第二順序上位於第二目前像素之前且位於相同的第二目前區段之像素。第二更新處理係針對中間影像之每一列之像素進行完第二比較處理後所產生之第二中間區段影像,再依序更新在第二中間區段影像中所計算出之輸出結果。需注意的是,在第二更新處理結束之後,處理單元110係再將所計算出各像素之輸出結果開根號以得到在輸入影像中之各像素所相應的距離資訊。在一些實施例中,可直接利用第二掃瞄所產生的結果以做為輸入影像中之各像素所相應的距離資訊。 In detail, because the operation between the pixels located in the second order before the second current pixel and located in the same second current segment (which may be left, right, above, or below adjacent pixels) is to be eliminated. In the second comparison processing, the second current pixel in the intermediate image and the adjacent pixels of the upper or lower segment thereof are used in the second comparison process (depending on the scanning order and the scanning mask used). And does not include pixels in the intermediate image that are located before the second current pixel in the second order and are located in the same second current segment. The second update process is to perform the second intermediate segment image generated after the second comparison process on the pixels of each column of the intermediate image, and sequentially update the output result calculated in the second intermediate segment image. It should be noted that after the second update process ends, the processing unit 110 further calculates the output result of each pixel to obtain the distance information corresponding to each pixel in the input image. In some embodiments, the results produced by the second scan can be directly utilized as the distance information corresponding to each pixel in the input image.

本發明中第6圖之流程係可應用於第3A~3E圖、第4A~4L圖、及第5圖之實施例,意即將前進掃瞄及後退掃瞄均劃分為比較處理及更新處理,且可應用於不同遮罩類型,使得在計算更新像素時的資料相依性得以大幅降低,使得程式編譯器所產生的程式碼的計算效率可大幅提高。此外,第6圖之流程除了適用於先進行前後掃瞄再進行後退掃瞄之操作外,亦適用於先進行後退掃瞄再進行前進掃瞄之操作。 The flow of the sixth embodiment of the present invention can be applied to the embodiments of FIGS. 3A-3E, 4A-4L, and 5, meaning that both the forward scan and the backward scan are divided into comparison processing and update processing. It can be applied to different mask types, so that the data dependency when calculating the updated pixels is greatly reduced, so that the calculation efficiency of the code generated by the program compiler can be greatly improved. In addition, the flow of FIG. 6 is applicable to the operation of performing the backward scanning and the forward scanning in addition to the operations of performing the back-and-forth scanning and the backward scanning.

第7A及7B圖係顯示依據本發明之一實施例中以不同順序進行影像距離轉換的示意圖。在第6圖之實施例中,第 一順序及第二順序均是以循序掃瞄及反循序掃瞄為例說明,然而本發明並不限定於上述順序。例如第二順序只要係相對於第一順序,皆可執行本發明中之影像距離轉換方法。在一實施例中,輸入影像700包括10x10個像素,例如包括像素P(0,0)~P(9,9),如第7A圖所示。中間影像710包括10x10個像素,例如包括像素P’(0,0)~P’(9,9),如第7B圖所示。 7A and 7B are diagrams showing image distance conversion in different orders in accordance with an embodiment of the present invention. In the embodiment of Figure 6, the first Both the sequential and the second sequence are illustrated by sequential scanning and reverse scanning, but the present invention is not limited to the above sequence. For example, the second sequence may perform the image distance conversion method of the present invention as long as it is relative to the first order. In one embodiment, the input image 700 includes 10 x 10 pixels, for example, including pixels P(0, 0)~P(9, 9), as shown in FIG. 7A. The intermediate image 710 includes 10 x 10 pixels, for example, including pixels P'(0, 0) - P' (9, 9) as shown in Fig. 7B.

以第一順序為例,若第一順序為循序掃瞄,則會從輸入像素700之像素P(0,0)開始,依據箭頭701之方向由上而下、由左而右依序對輸入影像700中之各像素進行掃瞄。若使用3x3斜面遮罩,當第一掃瞄中的目前像素為P(1,4)時,前進掃瞄遮罩7001例如包含像素P(1,4)、P(0,3)、P(0,4)、及P(0,5),此時第一目前區段為P(1,0)至P(1,9),第一比較處理不對P(1,3)進行比較。相對地,第二順序則會由中間影像710之像素P’(9,9)開始,依據箭頭712之方向,由下而上、由右而左依序對中間影像710之各像素進行掃瞄。當第二掃瞄中之目前像素為P’(8,4)時,後退掃瞄遮罩7101例如包含像素P’(8,4)、P’(9,3)、P’(9,4)、及P’(9,5)。當第一掃瞄中的第一比較處理對第一目前區段的比較完成後,第一更新處理對第一目前區段所產生的第一中間區段影像中之像素依序更新其數值,接著對下一個第一目前區段進行第一掃瞄。 Taking the first sequence as an example, if the first sequence is sequential scanning, it will start from the pixel P (0, 0) of the input pixel 700, and the input is from top to bottom and left to right according to the direction of the arrow 701. Each pixel in image 700 is scanned. If a 3x3 bevel mask is used, when the current pixel in the first scan is P(1, 4), the forward scan mask 7001 includes, for example, pixels P(1, 4), P(0, 3), P ( 0, 4), and P (0, 5), at this time, the first current segment is P (1, 0) to P (1, 9), and the first comparison process does not compare P (1, 3). In contrast, the second sequence starts from the pixel P' (9, 9) of the intermediate image 710, and scans the pixels of the intermediate image 710 from bottom to top and from right to left in sequence according to the direction of the arrow 712. . When the current pixel in the second scan is P' (8, 4), the back scan mask 7101 includes, for example, pixels P'(8, 4), P'(9, 3), P' (9, 4). ), and P' (9, 5). After the comparison of the first comparison process in the first scan is completed, the first update process sequentially updates the pixels in the first intermediate segment image generated by the first current segment. A first scan is then performed on the next first current segment.

若第一順序為反循序掃瞄,則會從像素P(9,9)開始,依據箭頭702之方向由下而上、由右而左依序對輸入影像700中之各像素進行掃瞄。 If the first sequence is anti-sequential scanning, each pixel in the input image 700 is scanned sequentially from the bottom to the top and from the right to the left according to the direction of the arrow 702 from the pixel P (9, 9).

在一些實施例中,第一順序例如可由輸入影像700 中之像素P(9,0)開始,依據箭頭704之方向,由左而右、由下而上依序對輸入影像700中之各像素進行掃瞄。舉例來說,從像素P(9,0)開始,依據箭頭704之方向,第一目前區段包括像素P(9,0)至P(0,0)(例如為第一目前像素之第一目前行),下一個第一目前區段則包括像素P(9,1)至P(0,1),之後,再下一個第一目前區段則包括像素P(9,2)至P(0,2),依此類推。若使用3x3斜面遮罩,當第一掃瞄中之目前像素為P(4,1)時,前進掃瞄遮罩7002例如包含像素P(4,1)、P(3,0)、P(4,0)、及P(5,0)。此時,第二順序例如可由中間影像710中之像素P’(0,9)開始,依據箭頭715之方向,由右而左、由上而下依序對中間影像710中之各像素進行掃瞄。舉例來說,從像素P’(0,9)開始,依據箭頭715之方向,第二目前區段包括像素P’(0,9)至P’(9,9)(例如為第二目前像素之第二目前行),下一個第二目前區段則包括像素P’(0,8)至P’(9,8),之後,再下一個第二目前區段則包括像素P’(0,7)至P’(9,7),依此類推。當第二掃瞄中之第二更新處理的目前像素為P’(4,8)時,後退掃瞄遮罩7102例如包含像素P’(4,8)、P’(3,9)、P’(4,9)、及P’(5,9)。上述第一順序及第二順序之掃瞄方式例如可視為分別將循序掃瞄及反循序掃瞄以逆時針方向旋轉90度,且前進掃瞄遮罩及後退掃瞄遮罩亦以逆時針方向旋轉90度之方式使用。 In some embodiments, the first sequence may be, for example, an input image 700 The pixel P(9, 0) starts scanning the pixels in the input image 700 from left to right and from bottom to top in accordance with the direction of the arrow 704. For example, starting from pixel P(9,0), according to the direction of arrow 704, the first current segment includes pixels P(9,0) to P(0,0) (for example, the first of the first current pixels) Currently, the next first current segment includes pixels P(9,1) to P(0,1), and then the next first current segment includes pixels P(9,2) to P( 0, 2), and so on. If a 3x3 bevel mask is used, when the current pixel in the first scan is P(4, 1), the forward scan mask 7002 includes, for example, pixels P(4,1), P(3,0), P( 4,0), and P(5,0). At this time, the second sequence can be started, for example, by the pixels P'(0, 9) in the intermediate image 710, and the pixels in the intermediate image 710 are sequentially scanned from right to left and from top to bottom according to the direction of the arrow 715. aim. For example, starting from pixel P'(0,9), according to the direction of arrow 715, the second current segment includes pixels P'(0,9) to P'(9,9) (for example, the second current pixel) The second current row), the next second current segment includes pixels P'(0,8) to P'(9,8), and then the next second current segment includes pixels P'(0). , 7) to P' (9, 7), and so on. When the current pixel of the second update processing in the second scan is P' (4, 8), the back scan mask 7102 includes, for example, pixels P'(4, 8), P'(3, 9), P. '(4,9), and P'(5,9). The scanning method of the first sequence and the second sequence may be, for example, rotating the sequential scanning and the reverse scanning respectively by 90 degrees in a counterclockwise direction, and the forward scanning mask and the backward scanning mask are also counterclockwise. Use 90 degrees to rotate.

詳細而言,在輸入影像中之第一目前像素的第一目前區段可為第一目前像素之一第一目前列或一第一目前行,視掃瞄順序而定。在中間影像中之第二目前像素的第二目前區段可為第二目前像素之一第二目前列或一第二目前行,視 掃瞄順序而定。此外,若第一目前區段為第一目前像素在輸入影像中之一第一目前列,第二目前區段為第二目前像素在中間影像中之一第二目前列。若第一目前區段為第一目前像素在輸入影像中之一第一目前行,第二目前區段為第二目前像素在中間影像中之一第二目前行。 In detail, the first current segment of the first current pixel in the input image may be the first current column or the first current row of the first current pixel, depending on the scanning order. The second current segment of the second current pixel in the intermediate image may be one of the second current pixel, the second current column, or a second current row, Depending on the scanning order. In addition, if the first current segment is the first current column of the first current pixel in the input image, the second current segment is the second current column of the second current pixel in the intermediate image. If the first current segment is the first current row of the first current pixel in the input image, the second current segment is the second current row of the second current pixel in the intermediate image.

在另一些實施例中,本發明中之第一順序及第二順序並不限定於上述實施例中的順序。例如循序掃瞄及反循序掃瞄例如可用對稱翻轉(flipped)、互相對調(interchanged)、旋轉(rotation)、或其組合的方式以分別套用於第一順序及第二順序。例如當第一順序係由輸入影像700之像素P(0,9)開始,依據箭頭707之方向由上而下、而右而左進行掃瞄。此時,第二順序則由中間影像710之像素P’(9,0)開始,依據箭頭718之方向由下而上、而左而右進行掃瞄。需了解的是,在第7A圖中所標示的箭頭701~708所指的像素及箭頭方向均可以做為第一順序之起點像素及掃瞄方向。若以第7A圖中之箭頭701~708做為第一順序之依據,則第二順序係分別相應於第7B圖中之箭頭712、711、716、715、714、713、718、及717。 In other embodiments, the first order and the second order in the present invention are not limited to the order in the above embodiments. For example, sequential scanning and anti-sequential scanning may be applied to the first sequence and the second sequence, respectively, by means of symmetrical flipping, interchanging, rotation, or a combination thereof. For example, when the first sequence starts from the pixel P (0, 9) of the input image 700, the scanning is performed from top to bottom and right to left according to the direction of the arrow 707. At this time, the second sequence starts from the pixel P' (9, 0) of the intermediate image 710, and scans from bottom to top and left to right according to the direction of the arrow 718. It should be understood that the pixels and the direction of the arrow indicated by the arrows 701 to 708 indicated in FIG. 7A can be used as the starting point pixel and the scanning direction of the first sequence. If the arrows 701 to 708 in Fig. 7A are used as the basis for the first order, the second sequence corresponds to the arrows 712, 711, 716, 715, 714, 713, 718, and 717 in Fig. 7B, respectively.

需注意的是,依此方式進行雙向掃瞄,在第一掃瞄中的第一目前像素之相鄰像素需選擇在輸入影像700中在第一順序上位於第一目前像素之前且位於相同之第一目前區段的像素,且在第二掃瞄中的第二目前像素之相鄰像素需選擇在中間影像710中在第二順序上位於第二目前像素之前且位於相同之第二目前區段的像素。意即在第一更新處理及第二更新處理中的相鄰像素之選擇需視掃瞄順序而定,例如選擇在相應順 序上且位於相應的目前區段之先前相鄰像素。此外,前進掃瞄遮罩及後退掃瞄遮罩亦依據所選擇的掃瞄順序對應地進行調整。 It should be noted that, in this manner, the two-way scanning is performed, and the adjacent pixels of the first current pixel in the first scan are selected to be in the input image 700 before the first current pixel in the first order and are located in the same The pixels of the first current segment, and the adjacent pixels of the second current pixel in the second scan are selected to be located in the intermediate image 710 in the second order before the second current pixel and located in the same second current region. The pixels of the segment. That is, the selection of adjacent pixels in the first update process and the second update process depends on the scan order, for example, the selection is in the corresponding order. The previous neighboring pixels on the sequence and located in the corresponding current segment. In addition, the forward scan mask and the backward scan mask are also adjusted correspondingly according to the selected scan order.

本發明之方法,或特定型態或其部份,可以以程式碼的型態包含於實體媒體,如軟碟、光碟片、硬碟、或是任何其他機器可讀取(如電腦可讀取)儲存媒體,其中,當程式碼被機器,如電腦載入且執行時,此機器變成用以參與本發明之裝置或系統。本發明之方法、系統與裝置也可以以程式碼型態透過一些傳送媒體,如電線或電纜、光纖、或是任何傳輸型態進行傳送,其中,當程式碼被機器,如電腦接收、載入且執行時,此機器變成用以參與本發明之裝置或系統。當在一般用途處理器實作時,程式碼結合處理器提供一操作類似於應用特定邏輯電路之獨特裝置。 The method of the present invention, or a specific type or part thereof, may be included in a physical medium such as a floppy disk, a compact disc, a hard disk, or any other machine (for example, a computer readable computer). A storage medium in which, when the code is loaded and executed by a machine, such as a computer, the machine becomes a device or system for participating in the present invention. The method, system and apparatus of the present invention may also be transmitted in a coded form via some transmission medium, such as a wire or cable, optical fiber, or any transmission type, wherein the code is received and loaded by a machine, such as a computer. And when executed, the machine becomes a device or system for participating in the present invention. When implemented in a general purpose processor, the code in conjunction with the processor provides a unique means of operation similar to application specific logic.

本發明雖以較佳實施例揭露如上,然其並非用以限定本發明的範圍,任何所屬技術領域中具有通常知識者,在不脫離本發明之精神和範圍內,當可做些許的更動與潤飾,因此本發明之保護範圍當視後附之申請專利範圍所界定者為準。 The present invention has been disclosed in the above preferred embodiments, and is not intended to limit the scope of the present invention. Any one of ordinary skill in the art can make a few changes without departing from the spirit and scope of the invention. The scope of protection of the present invention is therefore defined by the scope of the appended claims.

Claims (10)

一種利用雙向掃瞄之影像距離轉換方法,包括:對一輸入影像之各像素依一第一順序套用一第一遮罩以進行一第一掃瞄以產生一中間影像,其中該第一掃瞄包括一第一比較處理及一第一更新處理;以及對該中間影像之各像素依一第二順序套用一第二遮罩以進行一第二掃瞄以取得該輸入影像中之各像素之一距離資訊,其中該第二掃瞄包括一第二比較處理及一第二更新處理;其中,該第一比較處理係使用該輸入影像中之一第一目前像素而不與該輸入影像中在該第一順序上位於該第一目前像素之前且位於相同之一第一目前區段的像素比較;其中,該第二比較處理係使用該中間影像中之一第二目前像素而不與該中間影像中在第二順序上位於該第二目前像素之前且位於相同之一第二目前區段的像素比較。 An image distance conversion method using a two-way scan includes: applying a first mask to a pixel of an input image in a first order to perform a first scan to generate an intermediate image, wherein the first scan Include a first comparison process and a first update process; and applying a second mask to the pixels of the intermediate image in a second order to perform a second scan to obtain one of the pixels in the input image Distance information, wherein the second scan includes a second comparison process and a second update process; wherein the first comparison process uses one of the first current pixels of the input image without being in the input image Comparing pixels in the first order before the first current pixel and in the same one of the first current segments; wherein the second comparison process uses one of the second images in the intermediate image without the intermediate image Pixels in the second order that precede the second current pixel and are located in the same one of the second current segment. 如申請專利範圍第1項所述之方法,其中該第一順序為循序掃瞄,且該第二順序為反循序掃瞄,其中該第一遮罩為一前進掃瞄遮罩,且該第二遮罩為相應於該前進掃瞄遮罩之一後退掃瞄遮罩。 The method of claim 1, wherein the first sequence is a sequential scan, and the second sequence is a reverse scan, wherein the first mask is a forward scan mask, and the first The second mask is a back scan mask corresponding to one of the forward scanning masks. 如申請專利範圍第2項所述之方法,其中該第一比較處理係使用該第一目前像素及其上方之相鄰像素、或該第一目前像素及其上方、左上方、及右上方之相鄰像素, 且該第二比較處理係使用該第二目前像素及其下方之相鄰像素、或該第二目前像素及其下方、左下方、及右下方之相鄰像素。 The method of claim 2, wherein the first comparison processing uses the first current pixel and an adjacent pixel above it, or the first current pixel and its upper, upper left, and upper right Adjacent pixels, And the second comparison processing uses the second current pixel and the adjacent pixel below it, or the second current pixel and the adjacent pixels below, below, and below the right pixel. 如申請專利範圍第1項所述之方法,其中該第一更新處理係對該輸入影像之該第一目前區段的該第一比較處理所產生之一第一中間區段影像中之像素依序更新其距離結果,且該第二更新處理係對該中間影像之該第二目前區段的該第二比較處理所產生一第二中間區段影像中之像素依序更新其距離輸出結果。 The method of claim 1, wherein the first update processing is based on a pixel in the first intermediate segment image generated by the first comparison processing of the first current segment of the input image. And updating the distance result, and the second update processing sequentially updates the distance output result of the pixels in the second intermediate segment image generated by the second comparison process of the second current segment of the intermediate image. 如申請專利範圍第1項所述之方法,其中:若該第一目前區段為該第一目前像素在該輸入影像中之一第一目前列,該第二目前區段為該第二目前像素在該中間影像中之一第二目前列;以及若該第一目前區段為該第一目前像素在該輸入影像中之一第一目前行,該第二目前區段為該第二目前像素在該中間影像中之一第二目前行。 The method of claim 1, wherein: if the first current segment is the first current column of the first current pixel in the input image, the second current segment is the second current segment a second current column of the pixel in the intermediate image; and if the first current segment is the first current row of the first current pixel in the input image, the second current segment is the second current current The pixel is in the second current line of one of the intermediate images. 一種影像距離轉換裝置,包括:一記憶體單元,用以儲存一影像距離轉換程式;以及一處理單元,用以由該記憶體單元讀取並執行該影像距離轉換程式以進行下列步驟:對一輸入影像之各像素依一第一順序套用一第一遮罩以進行一第一掃瞄以產生一中間影像,其中該第一掃瞄包括一第一比較處理及一第一更新處理;以及 對該中間影像之各像素依一第二順序套用一第二遮罩以進行一第二掃瞄以取得該輸入影像中之各像素之一距離資訊,其中該第二掃瞄包括一第二比較處理及一第二更新處理;其中,該第一比較處理係使用該輸入影像之一第一目前像素而不與該輸入影像中在該第一順序上位於該第一目前像素之前且位於相同之一第一目前區段的像素比較;其中,該第二比較處理係使用該中間影像之一第二目前像素而不與該中間影像中在該第二順序上位於該第二目前像素之前且位於相同之一第二目前區段的像素比較。 An image distance conversion device includes: a memory unit for storing an image distance conversion program; and a processing unit for reading and executing the image distance conversion program by the memory unit to perform the following steps: Each pixel of the input image applies a first mask in a first order to perform a first scan to generate an intermediate image, wherein the first scan includes a first comparison process and a first update process; Applying a second mask to the pixels of the intermediate image in a second order to perform a second scan to obtain distance information of each pixel in the input image, wherein the second scan includes a second comparison. Processing and a second update process; wherein the first comparison process uses one of the first current pixels of the input image and is not in the same order as the first current pixel in the first sequence a pixel comparison of a first current segment; wherein the second comparison process uses a second current pixel of the intermediate image without being located before the second current pixel in the second sequence in the intermediate image Pixel comparison of one of the second current segments of the same. 如申請專利範圍第6項所述之影像距離轉換裝置,其中該第一順序為循序掃瞄,且該第二順序為反循序掃瞄,其中該第一遮罩為一前進掃瞄遮罩,且該第二遮罩為相應於該前進掃瞄遮罩之一後退掃瞄遮罩。 The image distance conversion device of claim 6, wherein the first sequence is a sequential scan, and the second sequence is an anti-sequential scan, wherein the first mask is a forward scan mask. And the second mask is a back scan mask corresponding to one of the forward scanning masks. 如申請專利範圍第7項所述之影像距離轉換裝置,其中該第一比較處理係使用該第一目前像素及其上方之相鄰像素、或該第一目前像素及其上方、左上方、及右上方之相鄰像素,且該第二比較處理係使用該第二目前像素及其下方之相鄰像素、或該第二目前像素及其下方、左下方、右下方之相鄰像素。 The image distance conversion device of claim 7, wherein the first comparison processing uses the first current pixel and an adjacent pixel above the first current pixel, and the first current pixel and above, upper left, and The adjacent pixel in the upper right side, and the second comparison processing uses the second current pixel and the adjacent pixel below it, or the second current pixel and the adjacent pixels below, the lower left, and the lower right. 如申請專利範圍第6項所述之影像距離轉換裝置,其中該第一更新處理係對該輸入影像之該第一目前區段的 該第一比較處理所產生之一第一中間區段影像中之各像素依序更新其距離結果,且該第二更新處理係對該中間影像中之該第二目前區段的該第二比較處理所產生之一第二中間區段影像中之各像素依序更新其距離輸出結果。 The image distance conversion device of claim 6, wherein the first update processing is performed on the first current segment of the input image. Each pixel in the first intermediate segment image generated by the first comparison process sequentially updates the distance result thereof, and the second update process is the second comparison of the second current segment in the intermediate image. Each pixel in the second intermediate segment image generated by the processing sequentially updates its distance output result. 如申請專利範圍第6項所述之影像距離轉換裝置,其中:若該第一目前區段為該第一目前像素在該輸入影像中之一第一目前列,該第二目前區段為該第二目前像素在該中間影像中之一第二目前列;以及若該第一目前區段為該第一目前像素在該輸入影像中之一第一目前行,該第二目前區段為該第二目前像素在該中間影像中之一第二目前行。 The image distance conversion device of claim 6, wherein: if the first current segment is the first current column of the first current pixel in the input image, the second current segment is the a second current column of the second current column in the intermediate image; and if the first current segment is the first current row of the first current pixel in the input image, the second current segment is the The second current pixel is in a second current line of the intermediate image.
TW107116112A 2018-05-11 2018-05-11 Image distance transformation apparatus and method using bi-directional scan TWI670682B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
TW107116112A TWI670682B (en) 2018-05-11 2018-05-11 Image distance transformation apparatus and method using bi-directional scan

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
TW107116112A TWI670682B (en) 2018-05-11 2018-05-11 Image distance transformation apparatus and method using bi-directional scan

Publications (2)

Publication Number Publication Date
TWI670682B true TWI670682B (en) 2019-09-01
TW201947525A TW201947525A (en) 2019-12-16

Family

ID=68618819

Family Applications (1)

Application Number Title Priority Date Filing Date
TW107116112A TWI670682B (en) 2018-05-11 2018-05-11 Image distance transformation apparatus and method using bi-directional scan

Country Status (1)

Country Link
TW (1) TWI670682B (en)

Citations (3)

* 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
CN102737359A (en) * 2012-06-20 2012-10-17 四川师范大学 Method for quickly performing complete distance transformation on three-dimensional binary image
TW201244698A (en) * 2011-03-30 2012-11-16 Mitsubishi Electric Corp Method for tracking tumors

Patent Citations (3)

* 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
TW201244698A (en) * 2011-03-30 2012-11-16 Mitsubishi Electric Corp Method for tracking tumors
CN102737359A (en) * 2012-06-20 2012-10-17 四川师范大学 Method for quickly performing complete distance transformation on three-dimensional binary image

Also Published As

Publication number Publication date
TW201947525A (en) 2019-12-16

Similar Documents

Publication Publication Date Title
TWI423659B (en) Image corretion method and related image corretion system thereof
US7324706B2 (en) System and method for representing a general two dimensional spatial transformation
JP4657367B2 (en) Image processing apparatus, imaging apparatus, and image distortion correction method
US20170078631A1 (en) Projection system, semiconductor integrated circuit, and image correction method
JP5238220B2 (en) Resolution conversion apparatus, method and program
Fedorov et al. Variational framework for non-local inpainting
JP2008512767A (en) General two-dimensional spatial transformation expression system and method
CN110473139B (en) Image distance conversion device and method using bidirectional scanning
JP2010034696A (en) Resolution converting device, method, and program
JP5541679B2 (en) Image processing apparatus and method, and program
US20080019612A1 (en) Image scaling device
US20200334890A1 (en) Systems and Methods for Fast Texture Mapping of 3D Models
JP5316385B2 (en) Image processing apparatus and image processing program
TWI670682B (en) Image distance transformation apparatus and method using bi-directional scan
JP4594848B2 (en) Inscribed rectangle detection apparatus and inscribed rectangle detection program
JP7352374B2 (en) Virtual viewpoint conversion device and program
US12015755B2 (en) Real-time omnidirectional stereo matching method using multi-view fisheye lenses and system thereof
JP2010044586A (en) Two dimensional-code reader and program thereof
CN112614190B (en) Method and device for projecting mapping
RU2470368C2 (en) Image processing method
KR100685858B1 (en) Method And System For Revising Distance Distortion
JP2009064193A (en) Resolution converter and method
Sun et al. Surface Normal Data Guided Depth Recovery with Graph Laplacian Regularization
Krinidis Fast 2-d distance transformations
JP2012014430A (en) Image processing device, control method and program