2
$\begingroup$

My goal for this is to simply count the number of eggshells in the image.

eggshells

Using color negate only leads to this

shell = Import["https://i.imgur.com/PZNt7JQ.jpg"];
binshell = FillingTransform[ColorNegate[Binarize[shell]]]

negate

With luck, I at least came up with something clearer using

binshell = LocalAdaptiveBinarize[shell, 25];

binarize

What is the best way to count the total number of eggshells?

$\endgroup$
  • $\begingroup$ Are these photos always white on a green background? That would help separating items a lot. $\endgroup$ – kirma Apr 28 '18 at 18:14
  • $\begingroup$ Yep. I specifically chose green background. $\endgroup$ – visatete Apr 28 '18 at 18:16
  • $\begingroup$ Try ColorQuantize with parameter 2 (or maybe 3 or 4). $\endgroup$ – David G. Stork Apr 28 '18 at 18:18
  • $\begingroup$ Tried ColorQuantize. Using colornegate after only makes the whole image white. I however tried detecting all the white stuff using this as guide link but this is merely the result link $\endgroup$ – visatete Apr 28 '18 at 18:36
  • 1
    $\begingroup$ Very ad hoc, with too much magic: Import["https://i.imgur.com/PZNt7JQ.jpg"] // ColorSeparate[#, "S"] & // Binarize[#, 0.25] & // ColorNegate // Dilation[#, 5] & // MorphologicalComponents // Max (* 11 *) $\endgroup$ – kirma Apr 28 '18 at 18:54
10
$\begingroup$

Here's one way:

{r, g, b} = ColorSeparate[Import["https://i.imgur.com/PZNt7JQ.jpg"]];
bw = MorphologicalBinarize[b, 0.5]

enter image description here

ComponentMeasurements[bw, #Count > 200 &] // Length
11
$\endgroup$
  • 2
    $\begingroup$ Or Max@MorphologicalComponents@SelectComponents[bw, "Area", # > 200 &] in pre-v11. $\endgroup$ – corey979 Apr 28 '18 at 19:58

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.