Lab · 01

Telling animals apart by texture

For a university project, I tested whether a model could tell animals apart by the texture in their photos.

I turned textures into numbers using local binary patterns (LBP) and grey-level co-occurrence matrices (GLCM). I tried four classifiers and used confusion matrices to see which classes they mixed up.

Try it yourself ↓

Project mark
82%
Model accuracy in the project
About 70%
A close-up of black and white stripes on a Grévy’s zebra
Grévy’s zebra. Photo by Servali.

Try it yourself

Choose a sample photo, or use one of your own, to see what each method picks up and which texture it’s closest to. You can also drop a photo on the frame or paste one.

Zebra stripe sample
Your photoA crop of a zebra’s stripes.
GreyscaleColour goes. Texture is about light and dark, so every pixel becomes one grey value.
Local binary patternsEach pixel is compared with its eight neighbours. Each colour is one pattern of brighter and darker.
Grey-level pairsWhich grey values sit side by side. Lighter squares are pairs that occur more often, and the diagonal means neighbours share a grey.

Closest texture

…

    VerdictComparing patterns…
    Step 1 of 5

    Analysing the sample…

    The classifier compares your photo’s LBP histogram with four crops of each of the four animal photos, using k-nearest neighbours. Your photo never leaves your device. Try a jumper, a wooden table or a leopard print.

    About the methods

    Local binary patterns (LBP)

    LBP turns texture into numbers by comparing each pixel with its eight neighbours. In the map above, each colour shows how one pixel compares with those neighbours.

    Grey-level co-occurrence matrices (GLCM)

    GLCM counts which grey values sit next to each other. The pixel-pair direction sets whether neighbours are paired across or down. In the heat map, lighter squares show grey-value pairs that occur more often.

    Classifiers and confusion matrices

    I tried naïve Bayes, linear discriminant analysis, k-nearest neighbours and a multilayer perceptron. A confusion matrix showed which animal classes each classifier mixed up.

    Photo credits

    Zebra by Servali, CC BY 4.0, resized and cropped for display. Giraffe by Bjørn Christian Tørrissen, CC BY-SA 3.0. Leopard by SuperJew, CC BY-SA 3.0, cropped. Tiger by Bas Lammers, CC BY 2.0, cropped.