The change is pretty straightforward. We have to iterate over pixels and change them. To iterate over them, we can use this:
[mapPixel image x y | x <- [0..imageWidth image - 1], y <- [0..imageHeight image - 1]]
That’s pretty straightforward. We can then retrieve the pixels and store them in a list. mapPixel could simply take the pixel, and output a [Float]. We could even generalize that to any kind of image:
class (Pixel a) => ConvertPixel a where
convertPixel :: a -> [Float]
Let’s see the implementation for PixelRGBF for instance:
instance ConvertPixel PixelRGBF where
convertPixel (PixelRGBF r g b) = [realToFrac r,realToFrac g,realToFrac b]
The change is pretty straightforward. We have to iterate over pixels and change them. To iterate over them, we can use this:
That’s pretty straightforward. We can then retrieve the pixels and store them in a list.
mapPixel
could simply take the pixel, and output a[Float]
. We could even generalize that to any kind of image:Let’s see the implementation for
PixelRGBF
for instance:How simple is that heh? :) For
YCbCr8
, using this conversion formula: