image thumbnail

Colour based segmentation

version (101 KB) by Michala
Compute the area of the given color (color band) in the image


Updated 28 Feb 2014

View License

The script computes how many [%] of the image the chosen colour (colour band) occupies.
Input: you have to know the RGB numbers (or bands) of the colour of interest.
The colour bands better capture the colour fluctuations.
Output: [%] of the image that are occupied by the given color(s). Images of Red, Blue, and Green masks of the original colour image, histograms of red, blue, and green parts of the image, distribution of the size of the blobs, mask excluding the small blobs, mask with the filled holes, comaprison of the original and final image, summary table: number of the blobs, their areas [pixel], and their colour. The resultant table is saved in *.xls file - blobs' area, colour, colour bands (user input), minimal size of the blobs (user input), [%] of the image covered by the chosen colour.

1) you can decide whether you want to get rid of small blobs of the colour areas (area smaller than given "user-input" value will be excluded)
2) you are asked if you want to fill the holes in the blobs found.
3) use "imtool" to explore the RBG colors in the image

Image source: Rocks under the Microscope

1) rgb table:
2) bwareaopen -
3) matlab webinar:

Cite As

Michala (2021). Colour based segmentation (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2011b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: sublabel, SimpleColorDetection()

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!