Java Image Processing-chamfer distance transformation, java Image Processing-Chamfering

Source: Internet
Author: User

Java Image Processing-chamfer distance transformation, java Image Processing-Chamfering

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 a 3x3 window, the distance is changed in two steps. The first step is to scan each pixel from the upper left corner, left to right, and move the window from top to bottom, the minimum distance and position are saved in four pixels (0, 1, 2, and 3) around the center pixel x, as shown in the figure below:

In the second step, the minimum distance and position of each pixel are detected from bottom up, right to left, and 4, 5, 6, and 7 adjacent pixels are saved as the result, which is shown as follows:

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

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

2. Start the first step in the shift of the chamfer distance and save the result.

3. Based on the first step result, complete the second step in the chamfer distance transformation.

4. display all gray-scale values based on the distance transformation result to form an image

The final result is shown as follows (the source image on the left and the result after the CDT on the right)

The source code of the Complete Binary Image chamfering distance transformation is as follows:

Package com. gloomyfish. image. transform; import java. awt. color; import java. awt. image. bufferedImage; import java. util. arrays; import com. gloomyfish. filter. study. abstractBufferedImageOp; public class CDTFilter extends actbufferedimageop {private float [] dis; // nn-distances private int [] pos; // nn-positions, 32 bit index private Color bakcgroundColor; public CDTFilter (Color bgColor) {this. bak CgroundColor = bgColor;} @ Override public BufferedImage filter (BufferedImage src, BufferedImage dest) {int width = src. getWidth (); int height = src. getHeight (); if (dest = null) dest = createCompatibleDestImage (src, null); int [] inPixels = new int [width * height]; pos = new int [width * height]; dis = new float [width * height]; src. getRGB (0, 0, width, height, inPixels, 0, width); // random distance transformation point in T index = 0; Arrays. fill (dis, Float. MAX_VALUE); int numOfFC = 0; for (int row = 0; row 

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.