The Counting sort is an integer based algorithm. Because of this restriction, I could only do sorting for hue colours. It creates a hashMap counter with "buckets" for each of the 360 hue colours and collects every pixel of that hue colour from the image.
It is called counting sort because, for a normal integers array, it just counts the frequency of each number in the array, but since pixels can be different from each other even having the same hue (they can have different brightness or saturation) we have to collect them in the order they appear, instead of just counting them. After creating this counter with hue buckets full of pixels, we just put those pixels in the image.
This is also one of the few linear sorting algorithms or O(n) sorting algorithm, so it is faster than quicksort. The drawback, besides only be applied to integer arrays, it needs to create the counter array for the buckets using additional memory and also some prior knowledge of the size of the counter array.
Song: Bluesy Vibes (Sting) - Doug Maxwell/Media Right Productions
Done in processing and available on GitHub:
https://github.com/volfegan/PixelSorting