Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Measuring the average thickness of traces in an image

Here's the problem: I have a number of binary images composed by traces of different thickness. Below there are two images to illustrate the problem:

First Image - size: 711 x 643 px

711 x 643 example image

Second Image - size: 930 x 951 px

alt text

What I need is to measure the average thickness (in pixels) of the traces in the images. In fact, the average thickness of traces in an image is a somewhat subjective measure. So, what I need is a measure that have some correlation with the radius of the trace, as indicated in the figure below:

alt text

Notes

  • Since the measure doesn't need to be very precise, I am willing to trade precision for speed. In other words, speed is an important factor to the solution of this problem.

  • There might be intersections in the traces.

  • The trace thickness might not be constant, but an average measure is OK (even the maximum trace thickness is acceptable).

  • The trace will always be much longer than it is wide.

like image 356
Alceu Costa Avatar asked Sep 17 '10 13:09

Alceu Costa


People also ask

How do you calculate average thickness?

Divide the plate volume by the surface area to calculate the thickness. In this example, the thickness is 15.5 cubic cm / 96.774 square cm = 0.16 cm or 1.6 mm.

How do you measure coating thickness on a microscope?

The other method to measure coating thickness, optical microscopy (Figure 17), is a destructive technique that exposed the edge of a coating under an optical microscope. The sample must be sectioned, then mounted and polished to show the exposed edge of the hot-dip galvanized coating.

How do you determine the thickness of a layer?

For single layers, the layer thickness can be calculated directly from the distance of the intensity maxima (or minima), from the measured angle and the wavelength of the X-rays.

How do you measure thickness in physics?

You can measure paper thickness using a caliper. A sheet of paper or paperboard is inserted between the caliper's jaws. The jaws are then tightened and the distance between them is measured. Digital calipers are capable of displaying the thickness of a single sheet of paper.


2 Answers

I'd suggest this algorithm:

  1. Apply a distance transformation to the image, so that all background pixels are set to 0, all foreground pixels are set to the distance from the background
  2. Find the local maxima in the distance transformed image. These are points in the middle of the lines. Put their pixel values (i.e. distances from the background) image into a list
  3. Calculate the median or average of that list
like image 130
Niki Avatar answered Oct 17 '22 17:10

Niki


I was impressed by @nikie's answer, and gave it a try ...

I simplified the algorithm for just getting the maximum value, not the mean, so evading the local maxima detection algorithm. I think this is enough if the stroke is well-behaved (although for self intersecting lines it may not be accurate).

The program in Mathematica is:

m = Import["http://imgur.com/3Zs7m.png"]   (* Get image from web*)
s = Abs[ImageData[m] - 1];                 (* Invert colors to detect background *)
k = DistanceTransform[Image[s]]            (* White Pxs converted to distance to black*)
k // ImageAdjust                           (* Show the image *)
Max[ImageData[k]]                          (* Get the max stroke width *)

The generated result is

alt text

The numerical value (28.46 px X 2) fits pretty well my measurement of 56 px (Although your value is 100px :* )

Edit - Implemented the full algorithm

Well ... sort of ... instead of searching the local maxima, finding the fixed point of the distance transformation. Almost, but not quite completely unlike the same thing :)

m = Import["http://imgur.com/3Zs7m.png"];   (*Get image from web*)
s = Abs[ImageData[m] - 1];         (*Invert colors to detect background*)
k = DistanceTransform[Image[s]];   (*White Pxs converted to distance to black*)
Print["Distance to Background*"]
k // ImageAdjust                   (*Show the image*)
Print["Local Maxima"]
weights = 
    Binarize[FixedPoint[ImageAdjust@DistanceTransform[Image[#], .4] &,s]]  
Print["Stroke Width =", 
     2 Mean[Select[Flatten[ImageData[k]] Flatten[ImageData[weights]], # != 0 &]]]

alt text

As you may see, the result is very similar to the previous one, obtained with the simplified algorithm.

like image 40
Dr. belisarius Avatar answered Oct 17 '22 17:10

Dr. belisarius