Science in progress part II: Making the computer do the hard work

In my last post I described my test set-up and how my current experiments are performed. At the end of the post we were left with 200 to 300 pictures like this:

Example picture used to measure crack length.
Initial picture of the specimen.

The goal is to use these pictures to measure how long the crack was at each of the measurement points during the test. The simple but time-consuming way of doing this would be to open each picture one-by-one in Photoshop and then measure how many pixels across the crack was. With the graph paper included in the picture you can then convert the number of pixels into a length in millimetres.

While this process is fine if you only have a dozen or so pictures, doing all this by hand for several hundred pictures per specimen sounds way too much like hard work. Fortunately I have a computer to help me out! Using a program called Matlab (known, loved, and possibly hated by engineers and scientists everywhere) I’ve written a simple image processing script that can automatically determine how long the crack was.

I’m not a super-star programmer, so the first step is to crop the image so that (as much as possible) the crack is the only horizontal hard edge left in the image. This helps the program to not get confused. You can see what the cropped image looks like below. Clicking on the image will show you a larger version.

Cropped image
Picture after cropping to only show the crack.

To a computer a picture is just a collection of numbers. In my case each pixel has a number ranging from 0 to 255, representing how black a pixel is. 255 is white, 0 is black, and in between are 254 shades of grey. Whether you realise it or not, doing image manipulation on a computer means doing math with those numbers. Thanks in part to Instagra,m a very common manipulation is applying a filter. A filter is nothing more than an instruction to the computer to change the number associated with a certain pixel based on the numbers of the surrounding pixels (e.g. taking the average of all of them to smooth and blur an image). In my case I apply a Sobel filter (http://en.wikipedia.org/wiki/Sobel_operator) which has the effect of highlighting edges, as you can see below.

Image after applying a Sobel filter
Image after applying a Sobel filter.

Once the edges are highlighted I convert the image into a binary image. Instead of having 256 possible shades, each pixel is assigned a value of either pure white or pure black. If you want to sound fancy you can call this a ‘thresholding operation’.

Image after thresholding
Image after thresholding.

After thresholding I apply another filter that dilates all the white areas, which means small areas will be joined together if they are separated by only one or two black pixels. This ensures that one or two darker pixels won’t cause the crack to be prematurely terminated.

Image after dilation
Image after dilation.

The final step is to throw out any white areas in the picture below a certain size. If all went well this leaves me with a completely black picture, with one white area representing the crack.

Final image, containing only the crack.
Final image, containing only the crack.

Then it’s just a case of measuring how far to the right the right-most white pixel is and you know how long the crack is!

Repeat this operation for each picture, match up the picture with the number of cycles the test had been running at the moment it was taken, and you can draw a pretty graph of how the crack grew during the test.

Graph of crack length during the test
Graph of the crack growth during the test. Number of fatigue cycles along the horizontal axis and crack length in mm along the vertical axis.

Next time we’ll continue with the hard part: doing data analysis to actually learn something useful from this data.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s