[Haskell-cafe] Pixel by pixel image processing
hsyl20 at gmail.com
Wed Jun 3 09:52:00 UTC 2015
Here is a solution using JuicyPixels:
main :: IO ()
main = do
Right img <- readImage "test.png"
_ <- writeDynamicPng "test2.png" (dynamicPixelMap circleImage img)
circleImage :: Pixel a => Image a -> Image a
circleImage img = generateImage (\x y -> f x y $ pixelAt img x y) edge edge
edge = min (imageWidth img) (imageHeight img)
f x y a = if x'*x' + y'*y' < e'*e'
else colorMap (const 0) a
e' = edge `div` 2
x' = x - e'
y' = y - e'
2015-06-03 9:19 GMT+02:00 Geraldus <heraldhoi at gmail.com>:
> Hi cafe!
> I want to do some trivial masking manipulation on PNG images: take a
> picture, crop it to square shape and then make a circular mask, i.e. take
> all pixels that lies outside circle with radius equal to half of image
> width and placed at image center and replace that pixels with zero opacity
> once (hope this description is clear enough).
> I've found two packages for image processing so far: `friday`  and
> `unm-hip` , but can't figure out which of them suits my needs, maybe
> there are some other packages I miss?
>  https://hackage.haskell.org/package/friday
>  https://hackage.haskell.org/package/unm-hip
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe