After purchasing a box of alphabet pasta for the kids, I wondered if there was way to extract the frequency of appearance of letters in the box by taken a sample and the analyzing the picture.
i = Import["http://i.imgur.com/qpFUSTo.jpg?1"];
a = Import["http://i.imgur.com/rHD21Gm.jpg"];
bwimg = Binarize@i; bwa = Binarize@a;
x = Table[
ImageCorrelate[bwimg, ImageRotate[bwa, i],
NormalizedSquaredEuclideanDistance], {i, 0, 141 Pi/72, Pi/72}];
y = Table[
Dilation[ColorNegate@Binarize[x[[i]], 0.07], DiskMatrix[50]], {i,
Length[x]}]; z =
Fold[ImageAdd, First@y, Rest@y]; HighlightImage[bwimg, z,
HighlightColor -> Lighter@Green];
HighlightImage[i, z, HighlightColor -> Lighter@Green]
The result was less than promising, as a) it is time consuming, and b) several letters were missed by the process. I marked with Red and Orange arrows several letters that were missed.
Tried with the Binarize parameter (currently set at 0.07), but increasing it brought false positives into the mix.
Thought about MorphologicalComponents, which is very fast, and if the Colorize option can differentiate the objects, maybe it could be used to extract each letter, then maybe ImageAlign and group together. But that is beyond my skillset.
Any light on how to differentiate and tally the different letters would be appreciated.