My colleague asked me to help him out with this image:

Grains in an SEM image (78 pixels per micron)

He needs to know the grain size distribution, and they’ve been having trouble automating this. He knew I’d been doing some work with Mathematica’s image analysis capabilities so he thought maybe I could make some headway. This post shows my current progress.

My first idea was do use EdgeDetect to find the boundaries:

This is the result of using EdgeDetect in Mathematica on the original image

This seems to isolate most of the grains, but I need Mathematica to isolate the areas that the edges separate. What I decided to do was to darken up the edges by dilating them and subtracting them from the original image:

original image with edges darkened and the rest set to white

Now I use the very cool MorphologicalComponents command to get this:

overlay of the identified grains on the original image. If it’s colored, it’s identified.

Here’s an animation that slowly identifies the grains:

Slowly reveals the grains (the last frame is shown in the previous image)

Cool, huh? I thought so. I’m waiting to hear from my colleague to see if this is the sort of identification he needs. My guess is that he wants something like a histogram of the areas of the grains. With ComponentMeasurements, that’s super easy:

Histogram of the areas of the grains (in square microns)

Ok, so now I admit to you my ignorance. I have no idea how people do this, though I did find this standard (paywall) at the American Society for Testing and Materials (ASTM). I’m hoping some of you can help me out with refining this technique. It’s really fast in Mathematica to run it, and I think it’s pretty robust, but it does clearly miss a few grains and inadvertently joins a few.

Thoughts? Here are some starters:

- This is cool, but I’d love to know the exact Mathematica commands.
- This is dumb, there’s a much better way to do it, and here’s how . . .
- This is cool, can I send you all my data so that I can graduate sooner?
- This is dumb, we pay grad students to do this by hand so that they learn to hate. Don’t make this available.
- This is cool, but I bet it would struggle with . . .
- This is dumb, it only worked this time because . . .

### Like this:

Like Loading...

*Related*

## About Andy "SuperFly" Rundquist

Professor of physics at Hamline University in St. Paul, MN

This is very cool. I’m getting bummed that my grad program is a MATLAB shop instead of MMA.

All of these transformations are mostly straightforward mathematical calculations done at the pixel level. Mathematica just has some nice built in functions to do them. I wouldn’t be surprised to hear Matlab has similar functionality.

Very cool! Reminds me of two things that were associated with my grad research. Etch pit density (EPD) characterization and Electron Back Scatter Diffraction (EBSD, specifically crystallographic orientation mapping). The whole grad student counting thing has always been a joke for EPD calculations and I think I’ve actually seen a presentation showing that the brute force (i.e. grad student) method was the most reliable for counting accurately. ImageJ has some capability for this type of analysis if you spend some time with it. As far as EBSD, I think most systems come with analysis software. Oxford has a nice page about the technique, their equipment, and their software (http://www.ebsd.com/index.php/ebsd-analysis/types-of-ebsd-experiment/representation-of-grains-and-grain-boundaries). I suspect that the U of M has an SEM with EBSD capability. As far as raw SEM image analysis though, your stuff is a about as good as I’ve seen.

Cool, glad to hear that I might be onto something. I grabbed a screenshot of the EBSD data in that link and ran the same commands on it. Here’s the movie:http://twitpic.com/dxjxgv

Hi,

very impressive. I am kind of having the same problem as your friend. Are you willing to send me the Mathematica code?

Hello,

Would you allow us to use this image to illustrate our MountainsMap software?

We use segmentation method and it works well on this example. Thank you in advance.

If you contact me I can send you an image of what we obtain in one click.

Sure. Please just mention me and my colleagues whenever you post it somewhere. A link here to the results from your approach would be great!

Hi,

great work! exactly what I was looking for!

it’s a bit an old post and maybe you’re not working on this anymore, but would it be possible to access the code? since then, did you make additional progress on this topic?

thanks a lot

I think I have the code somewhere. email me at firstname.lastname at gmail

On Tue, Jul 19, 2016 at 11:04 AM, SuperFly Physics wrote:

>