I have an image:

pic = Import[

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?

  • 1
    $\begingroup$ Can you try reposting your first image to imgur? $\endgroup$ – J. M.'s discontentment Jul 5 '15 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 '15 at 19:51
  • $\begingroup$ @J.M. Can I repost my picture to imgur when I'm commenting? $\endgroup$ – yode Dec 10 '15 at 6:10
  • $\begingroup$ Sure, why not?${}$ $\endgroup$ – J. M.'s discontentment Dec 10 '15 at 6:12
  • $\begingroup$ How to do it?Or where is the tutorial? $\endgroup$ – yode Dec 10 '15 at 6:14

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.

| improve this answer | |
  • 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 '15 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.