hip-1.1.0.2: Haskell Image Processing (HIP) Library.

Copyright(c) Alexey Kuleshevich 2016
LicenseBSD3
MaintainerAlexey Kuleshevich <lehins@yandex.ru>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Graphics.Image.Processing

Contents

Description

 

Synopsis

Geometric

Sampling

downsampleRows :: Array arr cs e => Image arr cs e -> Image arr cs e Source #

Downsample an image by discarding every odd row.

downsampleCols :: Array arr cs e => Image arr cs e -> Image arr cs e Source #

Downsample an image by discarding every odd column.

downsample :: Array arr cs e => Image arr cs e -> Image arr cs e Source #

Downsample an image by discarding every odd row and column.

upsampleRows :: Array arr cs e => Image arr cs e -> Image arr cs e Source #

Upsample an image by inserting a row of back pixels after each row of a source image.

upsampleCols :: Array arr cs e => Image arr cs e -> Image arr cs e Source #

Upsample an image by inserting a column of back pixels after each column of a source image.

upsample :: Array arr cs e => Image arr cs e -> Image arr cs e Source #

Upsample an image by inserting a row and a column of back pixels after each row and a column of a source image.

Concatenation

leftToRight :: Array arr cs e => Image arr cs e -> Image arr cs e -> Image arr cs e Source #

Concatenate two images together into one. Both input images must have the same number of rows.

topToBottom :: Array arr cs e => Image arr cs e -> Image arr cs e -> Image arr cs e Source #

Concatenate two images together into one. Both input images must have the same number of columns.

Canvas

crop Source #

Arguments

:: Array arr cs e 
=> (Int, Int)

(i, j) starting index from within a source image.

-> (Int, Int)

(m, n) dimensions of a new image.

-> Image arr cs e

Source image.

-> Image arr cs e 

Crop an image, i.e. retrieves a sub-image image with m rows and n columns. Make sure (m + i, n + j) is not greater than dimensions of a source image.

Flipping

flipV :: Array arr cs e => Image arr cs e -> Image arr cs e Source #

Flip an image vertically.

>>> frog <- readImageRGB "images/frog.jpg"
>>> writeImage "images/frog_flipV.jpg" $ flipV frog

flipH :: Array arr cs e => Image arr cs e -> Image arr cs e Source #

Flip an image horizontally.

>>> frog <- readImageRGB "images/frog.jpg"
>>> writeImage "images/frog_flipH.jpg" $ flipH frog

Rotation

rotate90 :: Array arr cs e => Image arr cs e -> Image arr cs e Source #

Rotate an image clockwise by 90°.

>>> frog <- readImageRGB "images/frog.jpg"
>>> writeImage "images/frog_rotate90.jpg" $ rotate90 frog

rotate180 :: Array arr cs e => Image arr cs e -> Image arr cs e Source #

Rotate an image by 180°.

>>> frog <- readImageRGB "images/frog.jpg"
>>> writeImage "images/frog_rotate180.jpg" $ rotate180 frog

rotate270 :: Array arr cs e => Image arr cs e -> Image arr cs e Source #

Rotate an image clockwise by 270°.

>>> frog <- readImageRGB "images/frog.jpg"
>>> writeImage "images/frog_rotate270.jpg" $ rotate270 frog

rotate Source #

Arguments

:: (Array arr cs e, Elevator e, Interpolation method) 
=> method (Pixel cs e)

Interpolation method to be used

-> Double

Angle in radians

-> Image arr cs e

Source image

-> Image arr cs e

Rotated image

Rotate an image clockwise by an angle Θ in radians.

>>> frog <- readImageRGBA "images/frog.jpg"
>>> writeImage "images/frog_rotate330.png" $ rotate (Bilinear (Fill 0)) (11*pi/6) frog

Scaling

resize Source #

Arguments

:: (Interpolation method, Array arr cs e, Elevator e) 
=> method (Pixel cs e)

Interpolation method to be used during scaling.

-> (Int, Int)

Dimensions of a result image.

-> Image arr cs e

Source image.

-> Image arr cs e

Result image.

Resize an image using an interpolation method.

>>> frog <- readImageRGB "images/frog.jpg"
>>> writeImage "images/frog_resize.jpg" $ resize (Bilinear Edge) (100, 640) frog

scale Source #

Arguments

:: (Interpolation method, Array arr cs e, Elevator e) 
=> method (Pixel cs e)

Interpolation method to be used during scaling.

-> (Double, Double)

Positive scaling factors.

-> Image arr cs e

Source image.

-> Image arr cs e 

Scale an image. Same as resize, except scaling factors are supplied instead of new dimensions.

 scale (Bilinear Edge) (0.5, 2) frog == resize (Bilinear Edge) (100, 640) frog

Interpolation

class Interpolation method where Source #

Implementation for an interpolation method.

Minimal complete definition

interpolate

Methods

interpolate :: (Elevator e, Num e, ColorSpace cs) => method (Pixel cs e) -> (Int, Int) -> ((Int, Int) -> Pixel cs e) -> (Double, Double) -> Pixel cs e Source #

Construct a new pixel by using information from neighboring pixels.

Instances

Interpolation Bilinear Source # 

Methods

interpolate :: (Elevator e, Num e, ColorSpace cs) => Bilinear (Pixel cs e) -> (Int, Int) -> ((Int, Int) -> Pixel cs e) -> (Double, Double) -> Pixel cs e Source #

Interpolation Nearest Source # 

Methods

interpolate :: (Elevator e, Num e, ColorSpace cs) => Nearest (Pixel cs e) -> (Int, Int) -> ((Int, Int) -> Pixel cs e) -> (Double, Double) -> Pixel cs e Source #

data Nearest px Source #

Nearest Neighbor interpolation method.

Constructors

Nearest !(Border px) 

Instances

Interpolation Nearest Source # 

Methods

interpolate :: (Elevator e, Num e, ColorSpace cs) => Nearest (Pixel cs e) -> (Int, Int) -> ((Int, Int) -> Pixel cs e) -> (Double, Double) -> Pixel cs e Source #

data Bilinear px Source #

Bilinear interpolation method.

Constructors

Bilinear !(Border px) 

Instances

Interpolation Bilinear Source # 

Methods

interpolate :: (Elevator e, Num e, ColorSpace cs) => Bilinear (Pixel cs e) -> (Int, Int) -> ((Int, Int) -> Pixel cs e) -> (Double, Double) -> Pixel cs e Source #

Convolution

convolve Source #

Arguments

:: ManifestArray arr cs e 
=> Border (Pixel cs e)

Approach to be used near the borders.

-> Image arr cs e

Kernel image.

-> Image arr cs e

Source image.

-> Image arr cs e 

Convolution of an image using a kernel. Border resolution technique is required.

Example using Sobel operator:

>>> frog <- readImageY "frog.jpg"
>>> let frogX = convolve Edge (fromLists [[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]]) frog
>>> let frogY = convolve Edge (fromLists [[-1,-2,-1], [ 0, 0, 0], [ 1, 2, 1]]) frog
>>> displayImage $ normalize $ sqrt (frogX ^ 2 + frogY ^ 2)

convolveRows :: ManifestArray arr cs e => Border (Pixel cs e) -> [Pixel cs e] -> Image arr cs e -> Image arr cs e Source #

Convolve image's rows with a vector kernel represented by a list of pixels.

convolveCols :: ManifestArray arr cs e => Border (Pixel cs e) -> [Pixel cs e] -> Image arr cs e -> Image arr cs e Source #

Convolve image's columns with a vector kernel represented by a list of pixels.

Tools

data Border px Source #

Approach to be used near the borders during various transformations. Whenever a function needs information not only about a pixel of interest, but also about it's neighbours, it will go out of bounds around the image edges, hence is this set of approaches that can be used in such situtation.

Constructors

Fill !px

Fill in a constant pixel.

           outside |  Image  | outside
(Fill 0) : 0 0 0 0 | 1 2 3 4 | 0 0 0 0
Wrap

Wrap around from the opposite border of the image.

           outside |  Image  | outside
Wrap :     1 2 3 4 | 1 2 3 4 | 1 2 3 4
Edge

Replicate the pixel at the edge.

           outside |  Image  | outside
Edge :     1 1 1 1 | 1 2 3 4 | 4 4 4 4
Reflect

Mirror like reflection.

           outside |  Image  | outside
Reflect :  4 3 2 1 | 1 2 3 4 | 4 3 2 1
Continue

Also mirror like reflection, but without repeating the edge pixel.

           outside |  Image  | outside
Continue : 1 4 3 2 | 1 2 3 4 | 3 2 1 4

pixelGrid Source #

Arguments

:: (Array arr cs e, Elevator e) 
=> Word8

Magnification factor.

-> Image arr cs e

Source image.

-> Image arr cs e 

This function magnifies an image by a positive factor and draws a grid around the original pixels. It is here simply as useful inspection tool.

>>> frog <- readImageRGB "images/frog.jpg"
>>> writeImage "images/frog_eye_grid.png" $ pixelGrid 10 $ crop (51, 112) (20, 20) frog