hip-1.5.6.0: 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 Source #

Arguments

:: Array arr cs e 
=> (Int -> Bool)

Rows predicate

-> (Int -> Bool)

Columns predicate

-> Image arr cs e

Source image

-> Image arr cs e 

Downsample an image. Drop all rows and colums that satisfy the predicates. For example, in order to discard every 5th row and keep every even indexed column:

>>> frog <- readImageRGB RPU "images/frog.jpg"
>>> displayImage $ downsample ((0 ==) . (`mod` 5)) odd frog

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 => (Int -> (Int, Int)) -> (Int -> (Int, Int)) -> Image arr cs e -> Image arr cs e Source #

Upsample an image by inserting rows and columns with zero valued pixels into an image. Supplied functions specify how many rows/columns shoud be inserted (before, after) a particular row/column. Returning a negative value in a tuple will result in an error. E.g. insert 2 columns before and 4 columns after every 10th column, while leaving rows count unchanged:

>>> frog <- readImageRGB RPU "images/frog.jpg"
>>> displayImage $ upsample (const (0, 0)) (\ k -> if k `mod` 10 == 0 then (2, 4) else (0, 0)) frog

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

translate Source #

Arguments

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

Border resolution strategy

-> (Int, Int)

Number of rows and columns image will be shifted by.

-> Image arr cs e 
-> Image arr cs e 

Shift an image towards its bottom right corner by (delatM, deltaN) rows and columns, while specifying a border resolution strategy.

>>> frog <- readImageRGB VU "images/frog.jpg"
>>> writeImage "images/frog_translate_wrap.jpg" $ translate Wrap (50, 100) frog
>>> writeImage "images/frog_translate_edge.jpg" $ translate Edge (50, 100) frog

Since: 1.2.0.0

canvasSize Source #

Arguments

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

Border resolution strategy

-> (Int, Int)

New dimensions of the image

-> Image arr cs e

Source image

-> Image arr cs e 

Change the size of an image. Pixel values and positions will not change, except the ones outside the border, which are handled according to supplied resolution strategy.

For example, it can be used to make a tile from the image above, or simply scale the canvas and place it in a middle:

>>> logo <- readImageRGBA VU "images/logo_40.png"
>>> let incBy (fm, fn) = (rows logo * fm, cols logo * fn)
>>> writeImage "images/logo_tile.png" $ canvasSize Wrap (incBy (6, 10)) logo
>>> writeImage "images/logo_center.png" $ translate (Fill 0) (incBy (2, 3)) $ canvasSize (Fill 0) (incBy (5, 7)) logo

Since: 1.2.1.0

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 (i + m, j + n) is not greater than dimensions of a source image, otherwise it will result in an error.

superimpose Source #

Arguments

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

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

-> Image arr cs e

Image to be positioned above the source image.

-> Image arr cs e

Source image.

-> Image arr cs e 

Place one image on top of a source image, starting at a particular location within a source image.

Flipping

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

Flip an image vertically.

>>> frog <- readImageRGB VU "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 VU "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 VU "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 VU "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 VU "images/frog.jpg"
>>> writeImage "images/frog_rotate270.jpg" $ rotate270 frog

rotate Source #

Arguments

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

Interpolation method to be used

-> Border (Pixel cs e)

Border handling strategy

-> 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 VU "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) 
=> method

Interpolation method to be used during scaling.

-> Border (Pixel cs e)

Border handling strategy

-> (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 VU "images/frog.jpg"
>>> writeImage "images/frog_resize.jpg" $ resize Bilinear Edge (100, 640) frog

scale Source #

Arguments

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

Interpolation method to be used during scaling.

-> Border (Pixel cs e)

Border handling strategy

-> (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

:: ColorSpace cs e 
=> method

Interpolation method

-> Border (Pixel cs e)

Border resolution strategy

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

Instances
Interpolation Bicubic Source # 
Instance details

Defined in Graphics.Image.Processing.Interpolation

Methods

interpolate :: ColorSpace cs e => Bicubic -> Border (Pixel cs e) -> (Int, Int) -> ((Int, Int) -> Pixel cs e) -> (Double, Double) -> Pixel cs e Source #

Interpolation Bilinear Source # 
Instance details

Defined in Graphics.Image.Processing.Interpolation

Methods

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

Interpolation Nearest Source # 
Instance details

Defined in Graphics.Image.Processing.Interpolation

Methods

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

data Nearest Source #

Nearest Neighbor interpolation method.

Constructors

Nearest 
Instances
Show Nearest Source # 
Instance details

Defined in Graphics.Image.Processing.Interpolation

Interpolation Nearest Source # 
Instance details

Defined in Graphics.Image.Processing.Interpolation

Methods

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

data Bilinear Source #

Bilinear interpolation method.

Constructors

Bilinear 
Instances
Show Bilinear Source # 
Instance details

Defined in Graphics.Image.Processing.Interpolation

Interpolation Bilinear Source # 
Instance details

Defined in Graphics.Image.Processing.Interpolation

Methods

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

newtype Bicubic Source #

Bicubic interpolation method. The parameter is usually set from -0.5 to -1.0.

Constructors

Bicubic Double 
Instances
Show Bicubic Source # 
Instance details

Defined in Graphics.Image.Processing.Interpolation

Interpolation Bicubic Source # 
Instance details

Defined in Graphics.Image.Processing.Interpolation

Methods

interpolate :: ColorSpace cs e => Bicubic -> Border (Pixel cs e) -> (Int, Int) -> ((Int, Int) -> Pixel cs e) -> (Double, Double) -> Pixel cs e Source #

Convolution

Convolution

convolve Source #

Arguments

:: (Array arr X e, Array arr cs e) 
=> Border (Pixel cs e)

Approach to be used near the borders.

-> Image arr X 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 RPU "images/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 :: (Array arr X e, Array arr cs e) => Border (Pixel cs e) -> [Pixel X 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 :: (Array arr X e, Array arr cs e) => Border (Pixel cs e) -> [Pixel X e] -> Image arr cs e -> Image arr cs e Source #

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

Correlation

correlate :: (Array arr X e, Array arr cs e) => Border (Pixel cs e) -> Image arr X e -> Image arr cs e -> Image arr cs e Source #

Correlate an image with a kernel. Border resolution technique is required.

Filters

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
Instances
Show px => Show (Border px) Source # 
Instance details

Defined in Graphics.Image.Interface

Methods

showsPrec :: Int -> Border px -> ShowS #

show :: Border px -> String #

showList :: [Border px] -> ShowS #

pixelGrid Source #

Arguments

:: Array arr cs 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 VU "images/frog.jpg"
>>> writeImage "images/frog_eye_grid.png" $ pixelGrid 10 $ crop (51, 112) (20, 20) frog