PixelValue will extract the channel values at a certain pixel. It returns a vector of numbers, not a colour. Is there a simple way to extract the colour of a pixel as an expression that is ColorQ? The image could have an arbitrary colour space.


Perhaps something like this:

 PixelValue[im, pos],
 OptionValue[Options[im], ColorSpace] -> ImageColorSpace[im]

where im is an image and pos is a pixel position, e.g., {100, 150}.

The basic idea is to use ColorConvert to automatically get the correct head for the image's colour space (e.g. RGBColor or CMYKColor). For this, we need the syntax ColorConvert[list, colspace1 -> colspace2] where colspace1 should define the interpretation of the values in the list.

  • $\begingroup$ Could you explain the second argument? To me the left-hand side of the arrow seems like it should return the same as the right-hand side. What is the difference? $\endgroup$ – C. E. May 6 '20 at 15:09
  • 1
    $\begingroup$ @C.E. Sorry, I should have been more verbose (I'm trying to get something working in parallel to asking...) What I am still confused about is the impact of the ColorSpace being a ColorProfileData object. I was trying to deal with this. For example, take the first example from the ColorProfileData doc page. The version I showed here effectively does ColorConvert[{a,b,c,d}, ColorProfileData[...] -> "CMYK"]. I think this is the correct interpretation of the colour. We cannot have a ColorProfileData in a colour object (like CMYKColor ), so on the RHS I just used "CMYK". $\endgroup$ – Szabolcs May 6 '20 at 15:21
  • $\begingroup$ Any feedback about the use of ColorProfileData is welcome ... $\endgroup$ – Szabolcs May 6 '20 at 15:21
  • $\begingroup$ @C.E. I am thoroughly confused. New question: mathematica.stackexchange.com/q/221271/12 $\endgroup$ – Szabolcs May 6 '20 at 15:33

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.