Decoding of chain codes embedded in images.
- type Colour = PixelRGB8
- type PixelPos = (Int, Int, Int)
- type Position = (Int, Int)
- type ChainCode = [PixelPos]
- readRGB8 :: FilePath -> IO (Either String (Image PixelRGB8))
- findSpot :: Image PixelRGB8 -> Colour -> Maybe Position
- intensity :: PixelRGB8 -> Double
- average :: PixelRGB8 -> Integer
- chainCode :: Image PixelRGB8 -> Colour -> Maybe ChainCode
- chainCodeWith :: Image PixelRGB8 -> Colour -> (Colour -> Bool) -> Maybe ChainCode
Position of a pixel along with the clock
direction used by
In a chain code, we'll keep the original pixel positions as well as the direction which we can use for signal processing.
We start checking at the top left corner of the image, checking each row
fully before progressing a column: we check
(height, width) then
(height, width + 1) and so on where top left corner of the image is (0, 0)
and positive height is towards the bottom. Uses colour
comparison with a small leeway of 1.
Averages each colour value and sees how close it is too fully-white.
Specialised version of
chainCodeWith which uses a comparison function
which simply asserts that the shape colour is not the same as the background.
Image parametrised by
PixelRGB8 and given a
Colour and a comparison function, we try to find the chain code in the
binary image which has the passed in colour. The comparison function's
purpose is to tell whether something is part of the shape.
Note that only a single shape is accepted inside of the image. The
starting positing is determined using