Home > Tutorials > Image Processing – Saturation Filter

Image Processing – Saturation Filter

By converting RGB to HSV, we can adjust pixel color in different way, in this case, I’d like to filter only Saturation value, I guess this technique is called “Saturation Filter“.


Original Image

Original Image

Image w/ Saturation Filter (Level 1)

Image w/ Saturation Filter (Level 1)

It’s kinda similar to some technique of color enhancement, but I’m not really sure.

Here the implementation:

	public static Bitmap applySaturationFilter(Bitmap source, int level) {
		// get image size
		int width = source.getWidth();
		int height = source.getHeight();
		int[] pixels = new int[width * height];
		float[] HSV = new float[3];
		// get pixel array from source
		source.getPixels(pixels, 0, width, 0, 0, width, height);

		int index = 0;
		// iteration through pixels
		for(int y = 0; y < height; ++y) {
			for(int x = 0; x < width; ++x) {
				// get current index in 2D-matrix
				index = y * width + x;
				// convert to HSV
				Color.colorToHSV(pixels[index], HSV);
				// increase Saturation level
				HSV[1] *= level;
				HSV[1] = (float) Math.max(0.0, Math.min(HSV[1], 1.0));
				// take color back
				pixels[index] |= Color.HSVToColor(HSV);
		// output bitmap
		Bitmap bmOut = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
		bmOut.setPixels(pixels, 0, width, 0, 0, width, height);
		return bmOut;


Pete Houston

Categories: Tutorials Tags: , , ,
  1. aamir
    June 3, 2013 at 1:55 pm

    how to apply posterize effect on imageview? please help me to solve this

  2. crexito
    September 29, 2012 at 4:18 am

    Hey Pete, ur code looks right but this operator “|=” makes the final effect to be distorced. U should have used “=” instead of “|=”. Ur final imagem will look much better =)

  3. jakky
    March 30, 2012 at 1:24 pm

    Hi Pete please help me to apply vignette effect on image in android
    thanks a lot……

  4. jakky
    March 29, 2012 at 5:29 pm

    how to apply vignette effect on image by code in android

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: