hip-1.0.1: 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" (computeS $ 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)

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

Reuslt 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.

Methods

interpolate Source

Arguments

:: (Elevator e, Num e, ColorSpace cs) 
=> method (Pixel cs e)

Interpolation method

-> (Int, Int)

Image dimensions m rows and n columns.

-> ((Int, Int) -> Pixel cs e)

Lookup function that returns a pixel at ith and jth location.

-> (Double, Double)

Real values of i and j index

-> Pixel cs e 

Construct a new pixel by using information from neighboring pixels.

data Nearest px Source

Nearest Neighbor interpolation method.

Constructors

Nearest !(Border px) 

data Bilinear px Source

Bilinear interpolation method.

Constructors

Bilinear !(Border px) 

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.

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 border during transformations, which, besides a pixel of interest, also use it's neighbors, consequently going out of bounds at the edges of an image.

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