Safe Haskell | None |
---|
- class BinaryPixel px where
- toBinaryImage :: (Image img, BinaryPixel (Pixel img)) => (Pixel img -> Bool) -> img -> img
- (<.) :: (Image img, BinaryPixel (Pixel img), Ord (Pixel img), Pixel img ~ a) => a -> img -> img
- (.<) :: (Image img, BinaryPixel (Pixel img), Ord (Pixel img), Pixel img ~ a) => img -> a -> img
- (>.) :: (Image img, BinaryPixel (Pixel img), Ord (Pixel img), Pixel img ~ a) => a -> img -> img
- (.>) :: (Image img, BinaryPixel (Pixel img), Ord (Pixel img), Pixel img ~ a) => img -> a -> img
- (==.) :: (Image img, BinaryPixel (Pixel img), Eq (Pixel img), Pixel img ~ a) => a -> img -> img
- (.==) :: (Image img, BinaryPixel (Pixel img), Eq (Pixel img), Pixel img ~ a) => img -> a -> img
- (/=.) :: (Image img, BinaryPixel (Pixel img), Eq (Pixel img), Pixel img ~ a) => a -> img -> img
- (./=) :: (Image img, BinaryPixel (Pixel img), Eq (Pixel img), Pixel img ~ a) => img -> a -> img
- compareImage :: (Image img, BinaryPixel (Pixel img), Ord (Pixel img)) => (Pixel img -> Pixel img -> Bool) -> img -> img -> img
- (.<.) :: (Image img, BinaryPixel (Pixel img), Ord (Pixel img)) => img -> img -> img
- (.>.) :: (Image img, BinaryPixel (Pixel img), Ord (Pixel img)) => img -> img -> img
- (.==.) :: (Image img, BinaryPixel (Pixel img), Eq (Pixel img)) => img -> img -> img
- (./=.) :: (Image img, BinaryPixel (Pixel img), Eq (Pixel img)) => img -> img -> img
- erode :: (Image img, BinaryPixel (Pixel img), Num (Pixel img), Eq (Pixel img)) => [[Pixel img]] -> img -> img
- erode' :: (Image img, BinaryPixel (Pixel img), Num (Pixel img), Eq (Pixel img)) => img -> img
- dilate :: (Image img, BinaryPixel (Pixel img), Num (Pixel img), Eq (Pixel img)) => [[Pixel img]] -> img -> img
- dilate' :: (Image img, BinaryPixel (Pixel img), Num (Pixel img), Eq (Pixel img)) => img -> img
- open :: (Image img, BinaryPixel (Pixel img), Num (Pixel img), Eq (Pixel img)) => [[Pixel img]] -> img -> img
- open' :: (Image img, BinaryPixel (Pixel img), Num (Pixel img), Eq (Pixel img)) => img -> img
- close :: (Image img, BinaryPixel (Pixel img), Num (Pixel img), Eq (Pixel img)) => [[Pixel img]] -> img -> img
- close' :: (Image img, BinaryPixel (Pixel img), Num (Pixel img), Eq (Pixel img)) => img -> img
- label :: (Image img, BinaryPixel (Pixel img), Image img', Pixel img' ~ Double) => img -> img'
- areas :: (Image img, MaxMin (Pixel img), RealFrac (Pixel img)) => img -> Vector Double
- perimeters :: (Image img, MaxMin (Pixel img), Pixel img ~ Double) => img -> Vector Double
- boundingBoxes :: (Image img, MaxMin (Pixel img), Pixel img ~ Double) => img -> [(Int, Int, Int, Int)]
- centersOfMass :: (Image img, MaxMin (Pixel img), Pixel img ~ Double) => img -> [(Double, Double)]
- distanceTransform :: (Image img, BinaryPixel (Pixel img), Image img', Pixel img' ~ Double) => img -> img'
- outline :: (Image img, BinaryPixel (Pixel img), Eq (Pixel img)) => img -> img
- outline' :: (Image img, BinaryPixel (Pixel img), Eq (Pixel img)) => Pixel img -> Pixel img -> img -> img
Binary Images
class BinaryPixel px whereSource
A BinaryPixel can be in one of two states, on or off.
toBinaryImage :: (Image img, BinaryPixel (Pixel img)) => (Pixel img -> Bool) -> img -> imgSource
Given a function of a pixel to a boolean and an image, returns the Binary version of that image.
>>>
stop <- readColorImage "images/stop.ppm"
>>>
let binaryStop = toBinaryImage (\(RGB (r, g, b)) -> r > 196 && g > 0 && b > 0) stop
https://raw.github.com/jcollard/unm-hip/master/examples/stop.jpg
https://raw.github.com/jcollard/unm-hip/master/examples/binarystop.jpg
(<.) :: (Image img, BinaryPixel (Pixel img), Ord (Pixel img), Pixel img ~ a) => a -> img -> imgSource
Given a Pixel p and an image img, return a Binary image where the pixel at (i, j) is on if p is less than the corresponding pixel in img at (i,j) and off otherwise.
>>>
frog <. 50
< Image 225x242 >
https://raw.github.com/jcollard/unm-hip/master/examples/greaterthanfrog.jpg
(.<) :: (Image img, BinaryPixel (Pixel img), Ord (Pixel img), Pixel img ~ a) => img -> a -> imgSource
Given an image, img, and a Pixel p, return a Binary image where the pixel at (i, j) is on if the corresponding pixel in img at (i,j) is less than p and off otherwise.
>>>
frog <- readImage "images/frog.pgm"
>>>
frog .< 50
< Image 225x242 >
https://raw.github.com/jcollard/unm-hip/master/examples/lessthanfrog.jpg
(>.) :: (Image img, BinaryPixel (Pixel img), Ord (Pixel img), Pixel img ~ a) => a -> img -> imgSource
Given a Pixel p and an image img, return a Binary image where the pixel at (i, j) is on if p is greater than the corresponding pixel in img at (i,j) and off otherwise.
>>>
50 >. frog
< Image 225x242 >
https://raw.github.com/jcollard/unm-hip/master/examples/lessthanfrog.jpg
(.>) :: (Image img, BinaryPixel (Pixel img), Ord (Pixel img), Pixel img ~ a) => img -> a -> imgSource
Given an image, img, and a Pixel p, return a Binary image where the pixel at (i, j) is on if the corresponding pixel in img at (i,j) is greater than p and off otherwise.
>>>
50 <. frog
< Image 225x242 >
https://raw.github.com/jcollard/unm-hip/master/examples/greaterthanfrog.jpg
(==.) :: (Image img, BinaryPixel (Pixel img), Eq (Pixel img), Pixel img ~ a) => a -> img -> imgSource
Given a Pixel p and an image img, return a Binary image where the pixel at (i, j) is on if the corresponding pixel in img at (i,j) is equal to p and off otherwise.
>>>
50 ==. frog
< Image 225x242 >
https://raw.github.com/jcollard/unm-hip/master/examples/frogequals.jpg
(.==) :: (Image img, BinaryPixel (Pixel img), Eq (Pixel img), Pixel img ~ a) => img -> a -> imgSource
Given an image, img, and a Pixel p, return a Binary image where the pixel at (i, j) is on if the corresponding pixel in img at (i,j) is equal to p and off otherwise.
>>>
frog .== 50
< Image 225x242 >
https://raw.github.com/jcollard/unm-hip/master/examples/frogequals.jpg
(/=.) :: (Image img, BinaryPixel (Pixel img), Eq (Pixel img), Pixel img ~ a) => a -> img -> imgSource
Given a Pixel p and an image img, return a Binary image where the pixel at (i, j) is on if the corresponding pixel in img at (i,j) is equal to p and off otherwise.
>>>
50 /=. frog
< Image 225x242 >
https://raw.github.com/jcollard/unm-hip/master/examples/notequals.jpg
(./=) :: (Image img, BinaryPixel (Pixel img), Eq (Pixel img), Pixel img ~ a) => img -> a -> imgSource
Given an image, img, and a Pixel p, return a Binary image where the pixel at (i, j) is on if the corresponding pixel in img at (i,j) is equal to p and off otherwise.
>>>
frog ./= 50
< Image 225x242 >
https://raw.github.com/jcollard/unm-hip/master/examples/notequals.jpg
compareImage :: (Image img, BinaryPixel (Pixel img), Ord (Pixel img)) => (Pixel img -> Pixel img -> Bool) -> img -> img -> imgSource
Given a function of two pixels to a boolean pred and two images X and Y, return a binary image that for each pixel (i,j) is on if the pixel pred X(i,j) Y(i,j) return True and off otherwise.
>>>
let fade = makeImage 225 242 (\ r _ -> fromIntegral r) :: GrayImage
>>>
let fademask = compareImage (>) frog fade
https://raw.github.com/jcollard/unm-hip/master/examples/fade.jpg
https://raw.github.com/jcollard/unm-hip/master/examples/fademask.jpg
(.<.) :: (Image img, BinaryPixel (Pixel img), Ord (Pixel img)) => img -> img -> imgSource
Given two images X and Y, return a binary image that for each pixel (i, j) is on if X(i,j) < Y(i,j) and off otherwise.
>>>
let fademask2 = frog .<. fade
https://raw.github.com/jcollard/unm-hip/master/examples/fademask2.jpg
(.>.) :: (Image img, BinaryPixel (Pixel img), Ord (Pixel img)) => img -> img -> imgSource
Given two images X and Y, return a binary image that for each pixel (i, j) is on if X(i,j) > Y(i,j) and off otherwise.
>>>
let fademask = frog .>. fade
https://raw.github.com/jcollard/unm-hip/master/examples/fademask.jpg
(.==.) :: (Image img, BinaryPixel (Pixel img), Eq (Pixel img)) => img -> img -> imgSource
Given two images X and Y, return a binray image that for each pixel (i, j) is on if X(i,j) == Y(i,j) and off otherwise.
>>>
let fademask3 = frog .==. fade
https://raw.github.com/jcollard/unm-hip/master/examples/fademask3.jpg
(./=.) :: (Image img, BinaryPixel (Pixel img), Eq (Pixel img)) => img -> img -> imgSource
Given two images X and Y, return a bniry image that for each pixel (i, j) is on if X(i,j) == Y(i,j) and off otherwise.
>>>
let fademask4 = frog ./=. fade
https://raw.github.com/jcollard/unm-hip/master/examples/fademask4.jpg
Binary Morphology
erode :: (Image img, BinaryPixel (Pixel img), Num (Pixel img), Eq (Pixel img)) => [[Pixel img]] -> img -> imgSource
Given a 2D list consisting solely of pixels representing a structuring element, and a binary image, erode returns the morphological erosion of the image with the structuring element.
>>>
stop <- readColorImage "images/stop.ppm"
>>>
let binaryStop = toBinaryImage (\(RGB (r, g, b)) -> r > 196 && g > 0 && b > 0) stop
>>>
let erosion = erode [[1,1],[1,1]] binaryStop
>>>
binaryStop - erosion
< Image 86x159 >
https://raw.github.com/jcollard/unm-hip/master/examples/stop.jpg
https://raw.github.com/jcollard/unm-hip/master/examples/binarystop.jpg
https://raw.github.com/jcollard/unm-hip/master/examples/erode.jpg
https://raw.github.com/jcollard/unm-hip/master/examples/erosion.jpg
erode' :: (Image img, BinaryPixel (Pixel img), Num (Pixel img), Eq (Pixel img)) => img -> imgSource
For convenience erode' = erode [[1,1],[1,1]]
>>>
erode' binaryStop
< Image 86x159 >
https://raw.github.com/jcollard/unm-hip/master/examples/erode.jpg
dilate :: (Image img, BinaryPixel (Pixel img), Num (Pixel img), Eq (Pixel img)) => [[Pixel img]] -> img -> imgSource
Given a 2D list consisting solely of pixels representing a structuring element, and a binary image, dilate returns the morphological dilation of the image with the structuring element.
>>>
let dilated = dilate [[1,1],[1,1]] binaryStop
>>>
dilate - binaryStop
< Image 86x159 >
https://raw.github.com/jcollard/unm-hip/master/examples/dilate.jpg
https://raw.github.com/jcollard/unm-hip/master/examples/dilated.jpg
dilate' :: (Image img, BinaryPixel (Pixel img), Num (Pixel img), Eq (Pixel img)) => img -> imgSource
For convenience dilate' = dilate [[1,1],[1,1]]
>>>
dilate' binaryStop
< Image 86x159 >
https://raw.github.com/jcollard/unm-hip/master/examples/dilate.jpg
open :: (Image img, BinaryPixel (Pixel img), Num (Pixel img), Eq (Pixel img)) => [[Pixel img]] -> img -> imgSource
Given a 2D list consisting solely of pixels representing a structuring element, and a binary image, dilate returns the morphological opening of the image with the structuring element.
>>>
noise <- readColorImage "images/noise.ppm"
>>>
let noisyStop = binaryStop ./=. noise
>>>
open noisyStop
< Image 86x159 >
https://raw.github.com/jcollard/unm-hip/master/examples/noise.jpg
https://raw.github.com/jcollard/unm-hip/master/examples/noisystop.jpg
https://raw.github.com/jcollard/unm-hip/master/examples/open.jpg
open' :: (Image img, BinaryPixel (Pixel img), Num (Pixel img), Eq (Pixel img)) => img -> imgSource
For convenience open' = open [[1,1],[1,1]]
>>>
open' noisyStop
< Image 86x159 >
https://raw.github.com/jcollard/unm-hip/master/examples/open.jpg
close :: (Image img, BinaryPixel (Pixel img), Num (Pixel img), Eq (Pixel img)) => [[Pixel img]] -> img -> imgSource
Given a 2D list consisting solely of pixels representing a structuring element, and a binary image, dilate returns the morphological closing of the image with the structuring element.
>>>
close [[1,1],[1,1]] noisyStop
https://raw.github.com/jcollard/unm-hip/master/examples/close.jpg
close' :: (Image img, BinaryPixel (Pixel img), Num (Pixel img), Eq (Pixel img)) => img -> imgSource
For convenience close' = close [[1,1],[1,1]]
>>>
close' noisyStop
https://raw.github.com/jcollard/unm-hip/master/examples/close.jpg
Functions on Binary Images
label :: (Image img, BinaryPixel (Pixel img), Image img', Pixel img' ~ Double) => img -> img'Source
Given a binary image, label returns an image where pixels in distinct connected components (based on 4-neighbor connectivity) have distinct integer values. These values range from 1 to n where n is the number of connected components in image.
>>>
label binaryStop
< Image 86x159 >
https://raw.github.com/jcollard/unm-hip/master/examples/label.jpg
areas :: (Image img, MaxMin (Pixel img), RealFrac (Pixel img)) => img -> Vector DoubleSource
Given an image, areas returns a vector where the n-th component equals the number of pixels with value n. If image is the result of applying label to a binary image, then the vector represents the areas of the connected-components of the binary-image. If not, areas returns the histogram of the image.
>>>
areas . label $ binaryStop
fromList [9241.0,1149.0,1323.0,5.0,809.0,3.0,1144.0]
perimeters :: (Image img, MaxMin (Pixel img), Pixel img ~ Double) => img -> Vector DoubleSource
Given an image, perimeters returns a vector where the n-th component equals the number of pixels with value n which are adjacent to pixels of value 0 and the 0-th component equals the sum of the other components. If image is the result of applying label to a binary image, then the vector represents the perimeters of the connected-components of the binary-image.
>>>
perimeters . label $ binaryStop
fromList [1082.0,307.0,323.0,5.0,184.0,3.0,260.0]
boundingBoxes :: (Image img, MaxMin (Pixel img), Pixel img ~ Double) => img -> [(Int, Int, Int, Int)]Source
Given an image, the result of applying label to a binary-image, boundingBoxes returns a vector where the n-th component is a four element tuple representing the minimum and maximum row and column indices of pixels of the n-th connected-component of the image.
>>>
boundingBoxes . label $ binaryStop
[(10,8,73,41),(10,75,74,110),(12,12,16,16),(11,42,72,73),(13,80,15,82),(11,117,72,150)]
centersOfMass :: (Image img, MaxMin (Pixel img), Pixel img ~ Double) => img -> [(Double, Double)]Source
Given an image, the result of applying label to a binary-image, centersOfMass returns a vector where the n-th component is a tuple representing the average row and column indices of pixels of the n-th connected-component of the image.
>>>
centersOfMass . label $ binaryStop
[(42.391644908616186,24.70409051348999),(41.80952380952381,92.23431594860166),(14.0,14.0),(35.31025957972806,57.595797280593324),(14.0,81.0),(35.59178321678322,129.90734265734267)]
distanceTransform :: (Image img, BinaryPixel (Pixel img), Image img', Pixel img' ~ Double) => img -> img'Source
Given a binary image, distanceTransform returns an image representing the 2D distance transform of the image. The distance transform is accurate to within a 2% error for euclidean distance.
>>>
distanceTransform binaryStop :: GrayImage
< Image 86x159 >
https://raw.github.com/jcollard/unm-hip/master/examples/distancetransform.jpg
outline :: (Image img, BinaryPixel (Pixel img), Eq (Pixel img)) => img -> imgSource
Given an image, outline returns an image where edge pixels are set to the value on and non-edge pixels are set to the value off. Pixel (i, j) is an edge pixel iff its value is different than the value of either pixel (i, j+1) or pixel (i+1, j).
>>>
outline binaryStop
< Image 86x159 >
https://raw.github.com/jcollard/unm-hip/master/examples/outline.jpg
outline' :: (Image img, BinaryPixel (Pixel img), Eq (Pixel img)) => Pixel img -> Pixel img -> img -> imgSource
Given two doubles nonEdge and edge, and an image, outline' returns an image where edge pixels are set to the value edge and non-edge pixels are set to the value nonEdge. Pixel (i, j) is an edge pixel iff its value is different than the value of either pixel (i, j+1) or pixel (i+1, j).
>>>
outline' (RGB (255, 255, 255)) (RGB (0, 0, 255)) binaryStop
< Image 86x159 >
https://raw.github.com/jcollard/unm-hip/master/examples/outline2.jpg