Pixel by pixel image processing

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Pixel by pixel image processing

Geraldus
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` [1] and `unm-hip` [2], but can't figure out which of them suits my needs, maybe there are some other packages I miss?


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Pixel by pixel image processing

Alexey Vagarenko
Hello,

There is also https://hackage.haskell.org/package/JuicyPixels

среда, 3 июня 2015 г., 13:19:23 UTC+6 пользователь Geraldus написал:
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` [1] and `unm-hip` [2], but can't figure out which of them suits my needs, maybe there are some other packages I miss?

[1] <a href="https://hackage.haskell.org/package/friday" target="_blank" rel="nofollow" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Fhackage.haskell.org%2Fpackage%2Ffriday\46sa\75D\46sntz\0751\46usg\75AFQjCNHZvoau6v7uZOA1ncsmEHC78Mcq4g';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Fhackage.haskell.org%2Fpackage%2Ffriday\46sa\75D\46sntz\0751\46usg\75AFQjCNHZvoau6v7uZOA1ncsmEHC78Mcq4g';return true;">https://hackage.haskell.org/package/friday
[2] <a href="https://hackage.haskell.org/package/unm-hip" target="_blank" rel="nofollow" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Fhackage.haskell.org%2Fpackage%2Funm-hip\46sa\75D\46sntz\0751\46usg\75AFQjCNGimKTefk7bxYatG9WaLIWRGwuKDA';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Fhackage.haskell.org%2Fpackage%2Funm-hip\46sa\75D\46sntz\0751\46usg\75AFQjCNGimKTefk7bxYatG9WaLIWRGwuKDA';return true;">https://hackage.haskell.org/package/unm-hip

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Pixel by pixel image processing

Bram Neijt
I did some combine images into a single large image code using GTK,
Cairo and Pixbuf:
https://github.com/bneijt/commitbook/blob/master/src/Rendering.hs

I would consider Cairo[1] another.

Greetings,

Bram
[1] http://cairographics.org/

On Wed, Jun 3, 2015 at 9:29 AM, Alexey Vagarenko <[hidden email]> wrote:

> Hello,
>
> There is also https://hackage.haskell.org/package/JuicyPixels
>
> среда, 3 июня 2015 г., 13:19:23 UTC+6 пользователь Geraldus написал:
>>
>> 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` [1] and
>> `unm-hip` [2], but can't figure out which of them suits my needs, maybe
>> there are some other packages I miss?
>>
>> [1] https://hackage.haskell.org/package/friday
>> [2] https://hackage.haskell.org/package/unm-hip
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Pixel by pixel image processing

Sylvain HENRY
In reply to this post by Geraldus
Hi,

Here is a solution using JuicyPixels:

import Codec.Picture
import Codec.Picture.Types


main :: IO ()
main = do
   Right img <- readImage "test.png"
   _ <- writeDynamicPng "test2.png" (dynamicPixelMap circleImage img)
   return ()

circleImage :: Pixel a => Image a -> Image a
circleImage img = generateImage (\x y -> f x y $ pixelAt img x y) edge edge
   where
      edge = min (imageWidth img) (imageHeight img)
      f x y a = if x'*x' + y'*y' < e'*e'
            then a
            else colorMap (const 0) a
         where
            e' = edge `div` 2
            x' = x - e'
            y' = y - e'

Sylvain

2015-06-03 9:19 GMT+02:00 Geraldus <[hidden email]>:
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` [1] and `unm-hip` [2], but can't figure out which of them suits my needs, maybe there are some other packages I miss?


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe



_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Pixel by pixel image processing

Geraldus
Thank you everybody!
JuicyPixels was the first package I have thought about, but I've mistaken about its functionality and didn't mentioned it here.

Sylvain, thank you a lot! You've made my day! 

ср, 3 июня 2015 г. в 14:52, Sylvain Henry <[hidden email]>:
Hi,

Here is a solution using JuicyPixels:

import Codec.Picture
import Codec.Picture.Types


main :: IO ()
main = do
   Right img <- readImage "test.png"
   _ <- writeDynamicPng "test2.png" (dynamicPixelMap circleImage img)
   return ()

circleImage :: Pixel a => Image a -> Image a
circleImage img = generateImage (\x y -> f x y $ pixelAt img x y) edge edge
   where
      edge = min (imageWidth img) (imageHeight img)
      f x y a = if x'*x' + y'*y' < e'*e'
            then a
            else colorMap (const 0) a
         where
            e' = edge `div` 2
            x' = x - e'
            y' = y - e'

Sylvain

2015-06-03 9:19 GMT+02:00 Geraldus <[hidden email]>:
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` [1] and `unm-hip` [2], but can't figure out which of them suits my needs, maybe there are some other packages I miss?


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe