fg to be foreground pixels.
About Image Processing Examples.
Image Matrix
distform to it.
The value of each output pixel is the distance to the closest input foreground (value 100) pixel:
◦ For input foreground pixels, the output distance is zero
◦ For horizontal and vertical neighbors, the distance is 1
◦ For diagonal neighbors, the distance is the square root of 2 or 1.414
Image with a Single Nonzero Pixel
1. Define an image with a single, nonzero pixel.
distform to the image:
The distance increases monotonically as we move away from the foreground pixel (the center pixel) in the input image.
The distance transform produces an approximately Euclidean distance. In the above example, you can see that the exact Euclidean distance transform output for matrix location (0,1) should be:
whereas in our output image the value is 5.243.
Image of a Circular Object
1. Define an image of a circle:
scale function to scale the circle.
WRITEBMP function to write the scaled circle to a file.
distform function to the circle, scale it and save the results to a new file.
5. Insert the images from the two files and compare the result.
|
|
|
|
(sc.bmp)
|
(scdist.bmp)
|
The distance values are zero for all points within the circle and increase monotonically as we move outward, but they are not exactly equal to the Euclidean distance, or the output would be radially symmetric.
Two Binary Images of a Single Object
1. Read in an image.
translate function to create translated versions of the image and write the translated images to files.
3. Insert the images from the three files and compare the result.
|
|
|
|
|
(flower.bmp)
|
(flower_d2.bmp)
|
(flower_d3.bmp)
|
distform function to calculate the distance transform of D1.
D3 and compute the mean of the entire image. This represents a measure of the distance between the two images.
D1 and the other images increases with the degree of translation.
6. Compute the Hausdorff distance
mean.
Two Edge Images
You can compare the performance of edge detectors by computing the distance between two edge images. Use either the mean or the maximum of the masked distances as a measure of the edge distance.
READ_IMAGE function to read an image file.
binarize to the image and write the results to external files.
3. Insert, and visually compare, the two images.
|
|
|
|
(lena_e1.bmp)
|
(lena_e2.bmp)
|
4. Calculate the overall distance between the edges.