imagehaskellrgbhip

Haskell Image Processing (HIP) operate on Pixel RGB


I'm new to this library and I want a way to operate a (for example) Pixel RGB Double like:

p <- <RGB:(1.0e-2|9.80392156862745e-4|9.900990099009901e-3)>

I know substracts or sums affects the whole RGB

pixel p = p + 1
<RGB:(1.01|1.0009803921568627|1.00990099009901)>

Is there a way to operate the Red, Blue or Green part alone instead of operate the three colors at once?


Solution

  • For RGB, the data declaration looks like this:

    data instance Pixel RGB a = PixelRGB a a a
    

    The three fields are the red, green, and blue fields, respectively. So you can do all the usual Haskell-y things like pattern matching and reconstructing. For example:

    redder (PixelRGB r g b) = PixelRGB ((r+1)/2) g b
    

    The data declarations for other instances of this data family are shown at the top of the main documentation page.