I'm trying to detect a specific range of RGB color from an image with the lower threshold [180.150.0] and upper threshold [255,255,150]. I am just new on Mathematica please help me with clear details.

  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ – Michael E2 Dec 21 '15 at 6:21
  • 1
    $\begingroup$ You are more likely to receive help if you show what you have tried so far. I suggest you start by reading about basic image manipulation, note that RGB colour values are in the range 0-1 in Mathematica, and perhaps focus on ImageClip. $\endgroup$ – MikeLimaOscar Dec 21 '15 at 10:06
  • $\begingroup$ Please help us with clear details too! What do you mean by detect? Do you just want an output that says "colors in the range were found in the image" or something else? $\endgroup$ – Simon Woods Dec 21 '15 at 10:13
  • $\begingroup$ the notion of a "range" or 3-channel colors is not obviously defined. Do you want each component in the specified range? $\endgroup$ – george2079 Dec 21 '15 at 14:47

The obvious way to do this turns out to be very slow:

flower = ExampleData[{"TestImage", "Flower"}];
ImageApply[ If[ 
    180 <= #[[1]] 255 <= 255 &&
    150 <= #[[2]] 255 <= 255 &&
      0 <= #[[3]] 255 <= 150 , #, {0, 0, 0}] & , flower ]

enter image description here

much faster to use Binarize on each channel to create a mask:

   Binarize[ #[[1, 1]], {180/255, 1}], 
   Binarize[ #[[1, 2]], {150/255, 1}],
   Binarize[ #[[1, 3]], {0, 150/255}], #[[2]]] &@ 
      ({ColorSeparate[#], #} &)@flower

Note that if your notion of a color being in range doesn't decouple so simply you may need to use ImageApply

| improve this answer | |
  • $\begingroup$ Thank you so much Sir.It's completely clear and useful $\endgroup$ – Mr.E Dec 22 '15 at 7:36

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.