chain-codes-0.2.0.0: Library decoding chain codes from images

Safe HaskellNone

Data.ChainCodes

Description

Decoding of chain codes embedded in images.

Synopsis

Documentation

type Colour = PixelRGB8Source

Friendly alias for PixelRGB8

type PixelPos = (Int, Int, Int)Source

Position of a pixel along with the clock direction used by chainCode.

type Position = (Int, Int)Source

Simple alias for Int pair

type ChainCode = [PixelPos]Source

In a chain code, we'll keep the original pixel positions as well as the direction which we can use for signal processing.

readRGB8 :: FilePath -> IO (Either String (Image PixelRGB8))Source

Reads in an Image that uses PixelRGB8 as its base. Rejects any other format.

findSpot :: Image PixelRGB8 -> Colour -> Maybe PositionSource

Given an Image parametrised by PixelRGB8 and given a Colour, we try to find the first pixel that matches the Colour.

We start checking at the top left corner of the image, checking each row fully before progressing a column: we check (width, height) then (width, height + 1) and so on where top left corner of the image is (0, 0) and positive height is towards the bottom.

chainCode :: Image PixelRGB8 -> Colour -> Maybe ChainCodeSource

Given an Image parametrised by PixelRGB8 and given a Colour, we try to find the chain code in the binary image which has the passed in colour. Note that this is the colour of your shape and any other colour is assumed to be the background: to process a black shape, pass in a black colour.

Note that only a single shape is accepted inside of the image. The starting positing is determined using findSpot.

The output list contains unique positions only: the beginning and end position are not treated the same. If findSpot fails, we return Nothing.