2

I would like to automatically measure a point-to-point distance in a batch of more than 100 images using Matlab 2014a. Specifically these images are tube sections and I want to measure the distance between the inner and outer circumferences (tubes wall thickness) from 0 to 360° with a given step of discretization obtaining a profile plot. The purpose of this profile plot is to see if the profile remains constant or changes among the samples.

I tried to use the edge function (with sobel, canny etc…) to identify the image borders but this function identifies also some inner edges due to scratches of the tube and dirt captured by the microscope. Does anyone know how to identify only the inner and outer border and perform a point to point distance measure?

I would like to obtain a plot which has on the x-axis the 0-2π scale, and on the y-axis the distance between the inner and outer circumferences. Thanks in advance!

Here is link to an image sample that you can download.

  • What OS are you using? – Mark Setchell Sep 09 '14 at 16:29
  • Mmmm... I have been looking at this and it is quite a difficult problem. Does your setup when you photograph the pipes ensure that the pipe is centralised? Because, if not, mis-positioning the centre of the circle makes the thicknesses all wrong because you are not measuring exactly along the radius so one side appears thicker and the other thinner if the centre of the circle is not correctly calculated. – Mark Setchell Sep 09 '14 at 20:45
  • I can use either Mac OS X or Windows. The external diameter is around 1.5 mm. I've machined and aluminum stand to hold the tube as vertical as possible, while i use sharp blades and a guide to precisely cut the tube. I acquire the image with a Mitutoyo microscope. – Matteo Maggioni Sep 10 '14 at 07:08
  • I think it's better to have a good contrast between the object and the background if possible. – dhanushka Sep 10 '14 at 09:02

3 Answers3

1

I have been having a look at this, but I use ImageMagick and OpenCV rather than Matlab, however I am sure you can convert the ideas to Matlab quite readily if that is your preference.

Finding Circles - Well, Hough Transforms make a big mess of this and seem to create a million circles all over the place, so I am thinking that is maybe not a solution. I then got thinking about "depolarising" the image and working in the straight line space it creates. It is quite easily depolarised with a simple ImageMagick -distort command like this:

convert tubo.tif -distort depolar 0 straight.jpg

That gives you an image like this:

enter image description here

The next thing is to slice the image into vertical strips corresponding to your discretisation. I didn't see any mention of actual numbers so I went with dividing the image into 10 vertical strips, each one the full height of the straightened image and 10% of its width. I did that in ImageMagick like this:

convert straight.jpg -crop 10%x100% out.jpg

which gives me 10 images called out-0.jpg, out-1.jpg ... out-9.jpg

Here is one:

enter image description here

I then resized the width of each of the 10 images, down to 50 pixels. I think I would really resize down to 1 pixel wide then it would average the pixels across the strip and give me a single transition point from background to pipe and then back to background. But you cannot easily see a 1 pixel wide image on here, so I went with a width of 50 pixels.

After that, I animated it, so you can see what is going on. I did that like this:

convert -delay 20 -loop 0 out* animated.gif

Which gives this:

enter image description here

So the whole code looks like this:

convert tubo.tif -distort depolar 0 straight.jpg
convert straight.jpg -crop 10%x100% out.jpg
for f in out* ; do
   convert $f -resize 50x! $f
done
convert -delay 20 -loop 0 out* animated.gif

There are lots of things to think about still... where to choose the image centre for depolarising, what thresholds to use, whether to use any morphology to close gaps cause during binarisation, whether any contrast enhancement helps or just moves the edges.

Another thing I note is that the inner area of the original image (inside the middle of the pipe) has a mean pixel value of 89 and a standard deviation of 4.5 (meaning it is quite homogeneous) whereas the actual pipe has a mean of 120 and a MUCH higher standard deviation of 25, so this could give some insight into how to threshold - maybe by texture/homogeneity.

By the way, ImageMagick and OpenCV are readily installed on OSX with homebrew. See my answer here.

Community
  • 1
  • 1
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
1

The tube is clearly distinguishable from its background by considering local variance or total variation. With a few lines in Matlab you can get a reasonable binary image:

  sx=filter2(ones(15)/15^2,im,'valid');
  sx2=filter2(ones(15)/15^2,im.^2,'valid');
  varMap=sx2-sx.^2;
  bin = imopen(varMap>15,ones(7));

enter image description here This is clearly not enough to solve your problem, as you have to detect the edges in some manner. I can recommend one of two approaches: 1. Assume some reasonable model for the edges e.g. ellipse, find candidates for inner/outer edges in the binary, and find best parameters for your model using linear regression or ransac.

  1. Convert the original image to polar and run some dynamic programming/ Dijstra's SSSP to find an (approximately horizontal) edge. As score for good edge, you can use the vertical derivative of the polar images. Dynamic Programming cannot guaranty a circular path, but good heuristics exist to solve this. The binary image can be used here for primary evaluation of the tube's center.
Ophir Gvirtzer
  • 604
  • 4
  • 8
0

You can detect the inner and the outer circles using imfindcircles. The region between the two circles can serve as your initial segmentation. You can use it as initialization for a more sophisticated segmentation algorithm such as active contours, which may give you a more precise boundary.

Dima
  • 38,860
  • 14
  • 75
  • 115
  • Thanks for your suggestion, but actually I'm not looking for a perfect circle. – Matteo Maggioni Sep 10 '14 at 07:31
  • Yes, I understand that. Finding the two circles is only the initial step, to get the rough area of interest. See the edit to my answer. – Dima Sep 10 '14 at 12:50