# Detect cigarettes/cigars in a scene [closed]

In many countries, it is mandatory to show a statutory warning whenever smoking is depicted in TV episodes and films- yeah that's asinine. How to detect cigarettes and cigars (in many the scenes, the cigarette or cigar remains unlit) in a scene? I am new to Mathematica and for what it is worth, I tried these -

imgclus = ClusteringComponents[img, 8]; ArrayPlot[imgclus]
ArrayPlot[imgclus, ColorRules -> {3 -> Red, _ -> White}, FrameTicks -> True]


gave me this

Next I tried detecting cigars/cigarettes using various 'Elongation' numbers. An attempt is shown below

comp = MorphologicalComponents[img, .8];

ComponentMeasurements[ comp , "Elongation", # < 0.5 &]

{2 -> 0.42265, 4 -> 0., 6 -> 0., 7 -> 0., 8 -> 0., 9 -> 0.,
11 -> 0., 13 -> 0.155177, 24 -> 0.355479, 28 -> 0., 32 -> 0.,
33 -> 0.0741799, 35 -> 0., 36 -> 0.42265, 39 -> 0., 41 -> 0.313972,
42 -> 0., 45 -> 0., 46 -> 0., 47 -> 0., 48 -> 0., 49 -> 0.42265,
50 -> 0., 51 -> 0., 52 -> 0.400205, 53 -> 0.266162, 55 -> 0.,
56 -> 0., 62 -> 0., 63 -> 0., 64 -> 0., 68 -> 0.481634, 72 -> 0.,
74 -> 0., 75 -> 0., 77 -> 0.0348882, 79 -> 0., 83 -> 0., 84 -> 0.,
85 -> 0., 87 -> 0.387192, 88 -> 0., 89 -> 0., 90 -> 0., 93 -> 0.,
99 -> 0., 101 -> 0., 104 -> 0.}


By this time, I got frustrated and have put my question out here. Hope to get help

@VitaliyKaurov: At the moment I am using standard photos from web and images from "Coffee and Cigarettes" Some are:

-
It seems this site has an endless stream of “how to detect X in an image?”. I wonder when we’ll get to detecting the really kinky stuff… (guaranteed instant hot SE question) – F'x Oct 22 '12 at 9:27
@F'x Yeah, right. We had road signs, finger nails, data points here and ditto here, and Martian objects. It get's boring after a while. – Sjoerd C. de Vries Oct 22 '12 at 14:23
I have a feeling that this is your university project and something you should be working on yourself... as a hint, perhaps a Radon/Hough transform might be a decent starting point. Doing it for the coffee and cigarettes image shows a few bright spots that could be the cigarettes (I haven't mapped back to verify) – rm -rf Oct 22 '12 at 15:06
@whuber: That's like merging all "how do I create a plot that looks like X"-questions into one big question. Look at the answers, they're very different. But if you do have an answer that solves any problem of this kind, please post it. That might win you a few prices for AI research, too ;-) – nikie Oct 22 '12 at 15:18
@whuber: First, AFAIK there is no general solution to the segmentation problem. That alone means that the solution of one answer usually cannot be applied to all the other "similar" questions. Second, I'm pretty sure if you just looked for "longish bright shapes", you'd get way too many false positives. That's what makes this problem difficult. I guess you'd need to train a ML algorithm to recognize the area around the shape (hands, ashtrays) using e.g. SIFT or SURF features. From what I've read, that's how category level object recognition problems like this one are usually done. – nikie Oct 22 '12 at 15:41