Copyright | (c) Alexey Kuleshevich 2016 |
---|---|
License | BSD3 |
Maintainer | Alexey Kuleshevich <[email protected]> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Graphics.Image.Processing
Description
- downsampleRows :: Array arr cs e => Image arr cs e -> Image arr cs e
- downsampleCols :: Array arr cs e => Image arr cs e -> Image arr cs e
- downsample :: Array arr cs e => Image arr cs e -> Image arr cs e
- downsampleF :: Array arr cs e => (Int, Int) -> Image arr cs e -> Image arr cs e
- upsampleRows :: Array arr cs e => Image arr cs e -> Image arr cs e
- upsampleCols :: Array arr cs e => Image arr cs e -> Image arr cs e
- upsample :: Array arr cs e => Image arr cs e -> Image arr cs e
- upsampleF :: Array arr cs e => (Int, Int) -> Image arr cs e -> Image arr cs e
- leftToRight :: Array arr cs e => Image arr cs e -> Image arr cs e -> Image arr cs e
- topToBottom :: Array arr cs e => Image arr cs e -> Image arr cs e -> Image arr cs e
- translate :: Array arr cs e => Border (Pixel cs e) -> (Int, Int) -> Image arr cs e -> Image arr cs e
- canvasSize :: Array arr cs e => Border (Pixel cs e) -> (Int, Int) -> Image arr cs e -> Image arr cs e
- crop :: Array arr cs e => (Int, Int) -> (Int, Int) -> Image arr cs e -> Image arr cs e
- superimpose :: Array arr cs e => (Int, Int) -> Image arr cs e -> Image arr cs e -> Image arr cs e
- flipV :: Array arr cs e => Image arr cs e -> Image arr cs e
- flipH :: Array arr cs e => Image arr cs e -> Image arr cs e
- rotate90 :: Array arr cs e => Image arr cs e -> Image arr cs e
- rotate180 :: Array arr cs e => Image arr cs e -> Image arr cs e
- rotate270 :: Array arr cs e => Image arr cs e -> Image arr cs e
- rotate :: (Array arr cs e, Interpolation method) => method -> Border (Pixel cs e) -> Double -> Image arr cs e -> Image arr cs e
- resize :: (Interpolation method, Array arr cs e) => method -> Border (Pixel cs e) -> (Int, Int) -> Image arr cs e -> Image arr cs e
- scale :: (Interpolation method, Array arr cs e) => method -> Border (Pixel cs e) -> (Double, Double) -> Image arr cs e -> Image arr cs e
- class Interpolation method where
- data Nearest = Nearest
- data Bilinear = Bilinear
- convolve :: Array arr cs e => Border (Pixel cs e) -> Image arr cs e -> Image arr cs e -> Image arr cs e
- convolveRows :: Array arr cs e => Border (Pixel cs e) -> [Pixel cs e] -> Image arr cs e -> Image arr cs e
- convolveCols :: Array arr cs e => Border (Pixel cs e) -> [Pixel cs e] -> Image arr cs e -> Image arr cs e
- data Border px
- pixelGrid :: Array arr cs e => Word8 -> Image arr cs e -> Image arr cs e
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.
upsampleF :: Array arr cs e => (Int, Int) -> Image arr cs e -> Image arr cs e Source #
Upsample an image by a positive factor. Every
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
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
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
Arguments
:: Array arr cs e | |
=> (Int, Int) |
|
-> (Int, Int) |
|
-> 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.
Arguments
:: Array arr cs e | |
=> (Int, Int) |
|
-> 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
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
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
Interpolation
class Interpolation method where Source #
Implementation for an interpolation method.
Minimal complete definition
Methods
interpolate :: (Num (Pixel cs e), ColorSpace cs e) => method -> Border (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
Nearest Neighbor interpolation method.
Constructors
Nearest |
Bilinear interpolation method.
Constructors
Bilinear |
Convolution
Arguments
:: Array 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 RP "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 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 :: Array 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
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
( |
Wrap | Wrap around from the opposite border of the image. outside | Image | outside
|
Edge | Replicate the pixel at the edge. outside | Image | outside
|
Reflect | Mirror like reflection. outside | Image | outside
|
Continue | Also mirror like reflection, but without repeating the edge pixel. outside | Image | outside
|
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