Task 051: image colour palette

Your task is to design an algorithm for the automatic calculation of a representative color palette of an input raster image. The inspiration for this assignment is a project "Cinema Palettes" My Modern Met. Your algorithm should analyze the input image and provide 3 to 10 characteristic colors. If the image has a smaller number of hues (unique colors), you can fill the rest of the palette with additional colors, for example, based on some color schema from: Adobe Color CC.


The template application 051colormap from the repository grcis serves as the basis of this project. This is a simple application in which it is possible to load an input image, and a resulting palette is then calculated. Within the application, the method Colormap.Generate() is responsible for calculating the palette. This method must be re-written - relevant location in the source Colormap.cs is highlighted with comment brackets:

  // !!!{{
  // !!!}}

Your code modifications do not have to be restricted to the area given by the brackets: if you want, you can also add helper data structures, and the like. The only restriction is that all changes you make to the framework must be in the subset of files that are to be submitted as solution (see below).


Technical details

The input image is passed to your method via the Bitmap input parameter, from which you can read data via BitMap.GetPixel(x,y) (details can be found here: Bitmap). The prototype already does this, to make it easier for you. The number of colours that should be outputed can be found in numCol (but you do not have to use this parameter, though - you can work with fixed palette lengths, or make this dependent on the image).
The output palette is written into the array colors, which you have to initialise to the correct size before using it, like so: colors = new Color[ 4 ]; for e.g. four colours.

Please hand in only the modified file Colormap.cs! DO NOT send us the entire Visual Studio project! If you have an input image for which your program generates particularly nice or interesting results, you can also attach it to the mail - but please keep the file size small!

Performance considerations

For a palette analysis, smaller input images of 600x400 pixels (or so) are usually sufficient. Restricting yourself to smaller input images is particularly important if you work with more sophisticated palette identification algorithms.


If you need functions for conversions between color spaces, or similar mathematical infrastructure: a place to look for such things is common/MathSupport.cs.


There are web pages that showcase palette extraction, such as My Modern Met. Relevant techniques can be found under the topics of: Cluster analysis (e.g., K-means clustering) and Color quantization. Nice palettes (not from images) can be created with Adobe Color CC.

What to hand in

You have to send the file Colormap.cs via mail to the lecturer.
In the first line, put your name in a comment.


Hand in the assignment until: 30. 10. 2022


Basic: 8 points
1 bod: for correct pallete length,
Additional bonus points for good handling of difficult images (small or big amount of colors, distinctive but not numerous color(s), ...)


Visual Studio project: 051colormap.

Source file

Modify and hand in the source file: Colormap.cs
As a comment in the first line, please include your name!


For testing purposes you can use images from the grcis repository, from data. You can also try out some other images, especially some difficult ones - your algorithm should be able to provide nice palette for any input image.

Copyright (C) 2010-2022 J. Pelikán & V. Tázlar, last change: 2023-10-16 02:32:07 +0200 (Mon, 16 Oct 2023)