Image processing-chamfer distance transformation and image processing-chamfer Transformation

Source: Internet
Author: User

Image processing-chamfer distance transformation and image processing-chamfer Transformation

Corner width and Distance Transformation for image processing

Chamfer Distance Transform in image processing is often used in object matching and recognition,

The algorithm generates the distance value of each pixel based on a 3x3 window, which is divided into two steps to complete the distance transformation.

Step from the upper left corner, from left to right, move the window from top to bottom scan each pixel, detection in the center pixel x week

The minimum distance and position are saved in four pixels (0, 1, 2, and 3), as shown in the figure below:


Step 2: from the bottom up, from the right to the left, for each pixel, detection of adjacent pixels 4, 5, 6, 7 Save the minimum distance and

Location as the result, as shown in:


After completing these two steps, the result output is the result of the chamfer distance transformation. Complete image chamfer distance Variation

The code change can be divided into the following steps:

1. initialize the pixel array. The initial distance of all background color pixels is infinite, and the foreground pixel distance 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-distancesprivate int [] pos; // nn-positions, 32 bit indexprivate Color bakcgroundColor; public CDTFilter (Color bgColor) {this. bakcgroundColo R = bgColor;} @ Overridepublic 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 int index = 0; Arrays. fill (Dis, Float. MAX_VALUE); int numOfFC = 0; for (int row = 0; row 
Reprinted please indicate the source !!

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.