unm-hip-0.3.1.6: A Library for the manipulation of images

Data.Image.Binary

Synopsis

Binary Images

class BinaryPixel px whereSource

A BinaryPixel can be in one of two states, on or off.

Methods

toBinary :: px -> BoolSource

off :: pxSource

on :: pxSource

Instances

 BinaryPixel Complex BinaryPixel Color BinaryPixel Gray

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

(<.) :: (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 >
```

(.<) :: (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 >
```

(>.) :: (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 >
```

(.>) :: (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 >
```

(==.) :: (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 >
```

(.==) :: (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 >
```

(/=.) :: (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 >
```

(./=) :: (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 >
```

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

(.<.) :: (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
``````

(.>.) :: (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
``````

(.==.) :: (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
``````

(./=.) :: (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
``````

````>>> ````let fmask = frog .< 150
````>>> ````applyMask fmask frog
```< Image 225x242 >
```

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

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

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

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

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

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

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

close' :: (Image img, BinaryPixel (Pixel img), Num (Pixel img), Eq (Pixel img)) => img -> imgSource

For convenience close' = close [[1,1],[1,1]]

````>>> ````close' noisyStop
``````

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

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,809.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,312.0,326.0,184.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),(11,42,72,73),(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.2686308492201,24.657712305025996),(41.74660633484163,92.20889894419307),(35.31025957972806,57.595797280593324),(35.583406113537116,129.9170305676856)]
```

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

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

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