3

enter image description here

I have to do some image processing but I don't know where to start. My problem is as follows :-

I have a 2D fiber image (attached with this post), in which the fiber edges are denoted by white color and the inside of the fiber is black. I want to choose any black pixel inside the fiber, and travel from it along the length of the fiber. This will involve comparing the contrast with the surrounding pixels and then travelling in the desired direction. My main aim is to find the length of the fiber

So can someone please tell me atleast where to start? I have made a rough algorithm in my mind on how to approach my problem but I don't know even which software/library to use.

Regards Adi

EDIT1 - Instead of OpenCV, I started using MATLAB since I found it much easier. I applied the Hough Transform and then Houghpeaks function with max no. of peaks = 100 so that all fibers are included. After that I got the following image. How do I find the length now?

EDIT2 - I found a research article on how to calculate length using Hough Transform but I'm not able to implement it in MATLAB. Someone please help

Aditya Singh
  • 93
  • 1
  • 4
  • Is there any particular language you are working in? What kind of image formats do you want to be able to use? – Gian Jul 28 '12 at 14:57
  • There is no particular language in which I am working with. Also, I know only C and C++. I can use any of the common image formats - jpg,png,tif – Aditya Singh Jul 28 '12 at 15:29
  • I found a [research article](http://www.cs.ou.edu/~atiq/papers/el-let92.pdf) on how to calculate length using Hough Transform but I'm not able to implement it in MATLAB. Someone please help – Aditya Singh Aug 03 '12 at 07:35

5 Answers5

2

If your images are all as clean as the one you posted, it's quite an easy problem.

The very first technique I'd try is using a Hough Transform to estimate the line parameters, and there is a good implementation of the algorithm in OpenCV. After you have them, you can estimate their length any way you want, based on whatever other constraints you have.

Francesco Callari
  • 11,300
  • 2
  • 25
  • 40
  • Hello Franco Even I was trying to use Hough Transform and had read the link you have provided regarding its implementation, but frankly I couldn't understand it. I understood upto the point where you calculate the parameters of a line passing through 3points. (Just while writing this, I got an idea. What if I try to find 4-5 successive points lying on the white edge and find the parameters of a line passing through them. Once I have the parameters, finding the length is pretty easy. The only problem now seems to be the scanning. Wassay?) Regards – Aditya Singh Jul 29 '12 at 08:32
  • Main idea of the Hough transform: Instead of thinking of a line as a relationship between x and y; y = ax + b, let them be a single point in (r, theta) space. Each point in your edge image gives rise to infinitely many lines that can cross this point. This way each edge pixel forms a curve in the (r, theta) space. The (r, theta) parameters that occur most often are likely to correspond to important lines in the image. – Håvard Geithus Jul 29 '12 at 16:07
  • The (r, theta) space needs to be quantized into a 2d-accumulator array. – Håvard Geithus Jul 29 '12 at 16:10
  • Nah, use ALL the white points to insert their associated parameters into the Hough array (think of it as adding a whole pencil of lines passing for a point, for every white point). Then find the local maxima in the accumlator array. To find the local maxima themselves you can use any of a number of techniques. The one I usually try first is locating the common values between the array and a dilated version of itself. – Francesco Callari Jul 30 '12 at 12:34
  • @FrancoCallari - But if i use all the points, I'll have to include some modifications for the blank region at the intersection of 2 lines. And that does not look easy – Aditya Singh Aug 01 '12 at 10:33
  • No, you will not need any modification at all. Just shove all the points in the Hough accumulator, then find the local maxima in it. – Francesco Callari Aug 01 '12 at 12:02
  • Instead of OpenCV, I started using MATLAB since I found it much easier. I applied the Hough Transform and then Houghpeaks function with max no. of peaks = 100 so that all fibers are included. After that I got the following image - http://goo.gl/kxtVw How do I find the length now? – Aditya Singh Aug 02 '12 at 09:11
  • Houghpeaks will give you the line parameter values (slope and intercept) associated to winning (peak) lines. Cluster the "on" pixels associating each of them to the closest line (using the parameters to tell the distance). The length of each line segment is the maximum of the distance between pairs of points in each cluster. The simplest implementation of all this is is O(N^2) in the number of points in each cluster, due to the last search, but you can easily accelerate that to O(N lg N) using a space partitioning tree. – Francesco Callari Aug 03 '12 at 13:27
0

Problem is two-fold as I see it: 1) locate start and end point from your starting position. 2) decide length between start and end points

Since I don't know your input data I assume it's pixel data with a 0..1 data on each pixel representing it's "whiteness".

In order to find end points I would do some kind of WALKER/AI that tries to walk in different locations, knowing original pos and last traversed direction then continuing along that route until "forward arc" is all white. This assumes fiber is somewhat straight (is it?).

Once you got start and end points you can input these into a a* path finding algorithm and give black pixels a low value and white very high. Then find shortest distance between start and end point, that is the length of the fiber.

Kinda hard to give more detail since I have no idea what techniques you gonna use and some example input data.

Daniel MesSer
  • 1,191
  • 1
  • 7
  • 13
  • Hello Daniel I just have an image (which I am attaching with in my initial post). I am reading on how to convert an image into pixels. – Aditya Singh Jul 28 '12 at 20:12
0

Assumptions: -This image can be considered a binary image where there are only 0s(black) and 1s(white). -all the fibers are straight and their starting and ending points are on borders. -we can come up with a limit for thickness in fiber(thickness of white lines).

Under these assumptions: start scanning the image border(start from wherever you want in whichever direction you want...just be consistent) until you encounter with the first white pixel.At this point your program will understand that this is definitely a starting point. By knowing this, you will gather all the white pixels until you reach a certain limit(or a threshold). The idea here is, if there is a fiber,you will get the angle between the fiber and the border the starting point is on...of course the more pixels you get(the inner you get)the surer you will be in the end. This is the trickiest part. after somehow ending up with a line...you need to calculate the angle(basic trigonometry). Since you know the starting point, the width/height of the image and the angle(or cos/sin of those) you will have the exact coordinate of the end point. Be advised...the exactness here is not really what you might have understood because we may(the thing is we will) have calculation errors in cos/sin values. So you need to hold the threshold as long as possible. So your end point will not be a point actually but rather an area indicating possibility that the ending point is somewhere inside that area. The rest is just simple maths.

Obviously you can put too much detail in this method like checking the both white lines that makes the fiber and deciding which one is longer or you can allow some margin for error since those lines will not be straight properly...this is where a conceptual thickness comes to the stage etc.

Programming: C# has nice stuff and easy for you to use...I'll put some code here...

newBitmap = new Bitmap(openFileDialog1.FileName);

for (int x = 0; x < newBitmap.Width; x++)
{
   for (int y = 0; y < newBitmap.Height; y++)
   {
      Color originalColor = newBitmap.GetPixel(x, y);//gets the pixel value...
      //things go here...
   }
}

you'll get the image from a openfiledialog and bitmap the image. inside the nested for loop this code scans the image left-to-right however you can change this...

Erdem E.
  • 170
  • 1
  • 5
  • This is way too vague. How do you handle interruptions/intersections with other lines? The white lines in the example image are a few pixels thick: how do you know which is the right direction to chain pixels when there are several possible? – Francesco Callari Jul 29 '12 at 04:10
0

Since you know C++ and C, I would recommend OpenCV . It is open-source so if you don't trust anyone like me, you won't have a problem ;). Also if you want to use C# like @VictorS. Mentioned I would use EmguCV which is the C# equivilant of OpenCV. Tutorials for OpenCV are included and for EmguCV can be found on their website. Hope this helps!

Liam McInroy
  • 4,339
  • 5
  • 32
  • 53
0

Download and install the latest version of 3Dslicer, Load your data and go the the package>EM segmenter without Atlas>

segmentation

Choose your anatomical tree in 2 different labels, the back one which is your purpose, the white edges. The choose the whole 2D image as your ROI and click on segment.

Here is the result, I labeled the edges in green and the black area in white

edges

black areas

You can modify your tree and change the structures you define. You can give more samples to your segmentation to make it more accurate.

fati
  • 125
  • 5