graphics recognition

Soldato
Joined
18 Oct 2012
Posts
8,339
so, have a bit of a challenge for you guys.

i have a series of images, many thousands, which are from a video tracking the growth of a crack. i can process these to be binary black/white pixels for clarity.

what i want to do is to track the movement of the crack, by counting the number of pixels from the fixed start point to the end of the crack. i need to do this for all the images and record the length (in pixels) versus picture number in some kind of text file.

anyone run into any (preferably open access) software that could do this?
 
can you post a colour original of a picture?

im not aware of any blackbox computer vision software. However if the area around the crack is largely seperable from the crack, e.g. an untextured smooth surface, then using OpenCv to code a very simple algorithm wouldn't take long.
 
However if the area around the crack is largely seperable from the crack, e.g. an untextured smooth surface

This was my thought to on reading OP. Rather than trying to identify the crack and calculate it's length, could you simply count the number of black/white pixels and extrapolate the length from there.
 
can you post a colour original of a picture?

im not aware of any blackbox computer vision software. However if the area around the crack is largely seperable from the crack, e.g. an untextured smooth surface, then using OpenCv to code a very simple algorithm wouldn't take long.

the original recording was a grayscale, no colour on the camera but it looks something like this:
5q6S4Da.png

which i can convert to pure black/white like this:
qeFA8Ae.png

i plan to improve the surface preperation a bit in future, so the artefacts shouldn't be a problem.

This was my thought to on reading OP. Rather than trying to identify the crack and calculate it's length, could you simply count the number of black/white pixels and extrapolate the length from there.

this is exactly what i want to do, i can manually calibrate a scale from a single image (which is what the markings are for) so all i need is a plot of the crack length in pixels versus the image number, the rest is a case of synchronising it with the rest of the data in excel.
 
so all i need is a plot of the crack length in pixels versus the image number

That's not what I meant, I was thinking of just counting the total number of black pixels in the entire image - no need for any image recognition or plotting lines on it. Having seen your image now, I dont think that'll work unless you can find some way to mask the background to white and still leave the view through the crack as black.
 
That's not what I meant, I was thinking of just counting the total number of black pixels in the entire image - no need for any image recognition or plotting lines on it. Having seen your image now, I dont think that'll work unless you can find some way to mask the background to white and still leave the view through the crack as black.

it might be possible to mask the outside. only problem is the crack grows over time, so the number of black pixels will be proportional to the area inside the crack rather than the actual length of the crack.
 
ok, so bit of an update to this.

i've managed to get the image isolated to show the crack as a singular object:
a9DYf83.png

do we think measuring the longest point to point distance would be doable?

i have literally zero coding experience so this is new ground for me.
 
guess the difficulty is determining the starting pixel to measure from, the ending pixel is fairly obvious(or near enough).

indeed, all i need is the line distance between the 2 furthest seperated pixels.

that image is the largest the crack gets, at the beginning it's a very thin line.

possibly starting at the first pixel from the right and measuring against the first pixel from the right until it's found the largest?
 
Just take the leftmost pixel and the rightmost pixel and calculate the distance between them.
It doesn't matter whether you use the higher or lower point on the left, before the crack formed those points were together so they will both be exactly the same distance from the end of the crack. (Although, in reality, the material can bend so each end point could be a different straight-line distance from the end of the crack. If you use the leftmost point then you should be measuring the straightest part of the material and getting the most accurate measurement of the crack)
 
Just take the leftmost pixel and the rightmost pixel and calculate the distance between them.
It doesn't matter whether you use the higher or lower point on the left, before the crack formed those points were together so they will both be exactly the same distance from the end of the crack. (Although, in reality, the material can bend so each end point could be a different straight-line distance from the end of the crack. If you use the leftmost point then you should be measuring the straightest part of the material and getting the most accurate measurement of the crack)

yeah this is what i'm thinking.

in some of the tests the part tilts up or down, so it might pick the top or bottom interchangeably but as you say that linear distance is the length of the crack from the start point minus bending which is going to be as close as we can get to a true measurement of the crack length, plus you can see there's some artefacts that sporadically appear meaning we can't always measure from the same edge anyway.

the only problem really is this is well outside of my expertise lol.
 
hmm, so I grabbed all the pixels, filtered to just white pixels, grabbed the first white pixel(on the X axis), last white pixel(on the X axis) and calculated the distance(pixels) between. This gives me 572 pixels from A to B in the image.

Code is quick and dirty so may be entirely flawed. May well just fall over with different images and different angles of the crack. :p

2NeZr27.png

Code:
            Bitmap img = new Bitmap("C:\\TempPath\\SourceImage.png");
            for (int x = 0; x < img.Width; x++)
            {
                for (int y = 0; y < img.Height; y++)
                {
                    Color pixel = img.GetPixel(x, y);

                    var newDataPoint = new PixelData
                    {
                        x = x,
                        y = y,
                        pixel = pixel
                    };
                    data.Add(newDataPoint);
                }
            }
       
            var allWhitePixels = data.Where(d => d.pixel.A == 255 && d.pixel.B == 255 && d.pixel.G == 255).OrderBy(d => d.x);
            Point left = new Point(allWhitePixels.FirstOrDefault().x, allWhitePixels.FirstOrDefault().y);
            Point right = new Point(allWhitePixels.LastOrDefault().x, allWhitePixels.LastOrDefault().y);
       
            double distance = Math.Sqrt(Math.Pow(right.X - left.X, 2) + Math.Pow(right.Y - left.Y, 2));


        private class PixelData
            {
            public int x { get; set; }
            public int y { get; set; }

            public Color pixel { get; set; }

        }
 
that looks the ticket, does it just measure horizontally or is that just the specific image coming out as being horizontal?

if it's the latter then all i need is that, for all the images in (folder) with the distances as some kind of csv (anything i can open in excel) by image number/name
 
that looks the ticket, does it just measure horizontally or is that just the specific image coming out as being horizontal?

if it's the latter then all i need is that, for all the images in (folder) with the distances as some kind of csv (anything i can open in excel) by image number/name

Actually horizontal or not doesnt matter. Its measuring between whichever points are leftmost and rightmost(of white pixels) on the x axis so should work regardless of the angle of the image.

May be a bit flawed if there are any white artifact pixels though which will throw the points out.

So rotated would measure this line.
EEDUdMp.png

Maybe good enough for a start, would have to have a play with it.
 
Actually horizontal or not doesnt matter. Its measuring between whichever points are leftmost and rightmost(of white pixels) on the x axis so should work regardless of the angle of the image.

May be a bit flawed if there are any white artifact pixels though which will throw the points out.

So rotated would measure this line
EEDUdMp.png

that's absolutely perfect, i'm working on making sure there aren't any artefacts in the image using the software i do have.

that tilt is you're showing there is worse than any of the real tests, so should work just fine.
 
Add a loop through your image folder, process each image, output to excel file with "closedxml".

(Using C# console app, which you can do for free with Visual studio community)

you may be underestimating how how bad my knowledge of all things coding is :p

*goes off to google visual studio community and c# coding for dummies*
 
Back
Top Bottom