3
$\begingroup$

I have an image:

pic = Import[
  "http://note.youdao.com/yws/public/resource/\
2c5a562224240edcf1631fcd39810f56/55FA538207424C0A98AB548724994AE1"]

enter link description here

that I want to binarize. When I try to do it in Mathematica, the results is enter image description here

My code is

bin = MorphologicalBinarize[pic // ColorNegate, {0.4, 0.6}]

I tried this many times. The result was always bad. I want to binarize the image so I can count the lattice (including that adjacent to the border). Can anyone help me?

$\endgroup$
5
  • 1
    $\begingroup$ Can you try reposting your first image to imgur? $\endgroup$ Jul 5, 2015 at 14:22
  • 3
    $\begingroup$ From the looks of your output image (please repost the original though) you should try LocalAdaptiveBinarize. $\endgroup$
    – user484
    Jul 5, 2015 at 19:51
  • $\begingroup$ @J.M. Can I repost my picture to imgur when I'm commenting? $\endgroup$
    – yode
    Dec 10, 2015 at 6:10
  • $\begingroup$ Sure, why not?${}$ $\endgroup$ Dec 10, 2015 at 6:12
  • $\begingroup$ How to do it?Or where is the tutorial? $\endgroup$
    – yode
    Dec 10, 2015 at 6:14

1 Answer 1

7
$\begingroup$

As suggested by Rahul, LocalAdaptiveBinarize is your friend:

LocalAdaptiveBinarize[pic, 15]

enter image description here

In order to count things, you can use the MorphologicalComponents command. Here we colorize it to get a visualization of how well the morphological processing segments the data:

MorphologicalComponents[LocalAdaptiveBinarize[pic, 15]] // Colorize

enter image description here

Of course, MorphologicalComponents is very versatile and can help gather statistics about your image and the segmentation.

$\endgroup$
1
  • 1
    $\begingroup$ +1, I would also suggest a bigger radius so you don't get the extra noise in the middle of the pieces. $\endgroup$
    – user484
    Jul 6, 2015 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.