Chamfer distance transformation in java image processing

Chamfer distance transform in image processing is often used in object matching recognition. The algorithm basically generates the distance value of each pixel based on 3x3 window, which is divided into two steps to complete the distance transformation. The first step starts from the upper left corner, moves the window from left to right and from top to bottom to scan each pixel, Detect four pixels 0, 1, 2 and 3 around the center pixel x, and save the minimum distance and position as the result, as shown below:

The second step is to detect adjacent pixels 4, 5, 6 and 7 from bottom to top, right to left, and save the minimum distance and position as the result, as shown in the figure:

After completing these two steps, the result output is the result of chamfer distance transformation. The complete code implementation of image chamfer distance transformation can be divided into the following steps:

1. Initialize the pixel array. The initial distance of all background color pixels is infinity, and the distance of foreground pixels is 0

2. Start the first step in chamfer distance transformation and save the results

3. Complete the second step of chamfer distance transformation based on the results of the first step

4. Display all different gray values according to the distance transformation results to form an image

The final results are shown as follows (the left shows the original image and the right shows the results after CDT)

The source code of complete binary image chamfer distance transformation is as follows:

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>