# Is there a simple way to get the colour of a pixel?

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:

ColorConvert[
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.

• 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? May 6 '20 at 15:09
• @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". May 6 '20 at 15:21
• Any feedback about the use of ColorProfileData is welcome ... May 6 '20 at 15:21
• @C.E. I am thoroughly confused. New question: mathematica.stackexchange.com/q/221271/12 May 6 '20 at 15:33