Archive

Posts Tagged ‘image’

Image Processing – Saturation Filter

October 30, 2011 4 comments

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“.

http://en.wikipedia.org/wiki/HSL_and_HSV#Saturation

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;
	}

Cheers,

Pete Houston

Categories: Tutorials Tags: , , ,

Image Processing – Shading Filter

October 30, 2011 10 comments

Shading Filter” is a technique that use AND operator for the current pixel color and a desired-shading color.

Original Image

Original Image

Image w/ Shading (Sky Blue)

Image w/ Shading (Sky Blue)

Image /w Shading (Lawn Green)

Image /w Shading (Lawn Green)

Image w/ Shading (Violet)

Image w/ Shading (Violet)

I love her in Violet

Here the implementation:

	public static Bitmap applyShadingFilter(Bitmap source, int shadingColor) {
		// get image size
		int width = source.getWidth();
		int height = source.getHeight();
		int[] pixels = new int[width * height];
		// 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;
				// AND
				pixels[index] &= shadingColor;
			}
		}
		// output bitmap
		Bitmap bmOut = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
		bmOut.setPixels(pixels, 0, width, 0, 0, width, height);
		return bmOut;
	}

 

Cheers,
Pete Houston

Categories: Tutorials Tags: , , ,

Image Processing – Snow Effect

October 30, 2011 6 comments

Well, still base on randomizing the pixel color, in contrast to the Black Filter, if set all pixels having R,G,B values to the max (0xFF) when they’re greater than threshold, then we have the Snow Effect.

Original Image

Original Image

Image w/ Snow Effect

Image w/ Snow Effect

I think it’s nice 🙂

	public static Bitmap applySnowEffect(Bitmap source) {
		// get image size
		int width = source.getWidth();
		int height = source.getHeight();
		int[] pixels = new int[width * height];
		// get pixel array from source
		source.getPixels(pixels, 0, width, 0, 0, width, height);
		// random object
		Random random = new Random();
		
		int R, G, B, index = 0, thresHold = 50;
		// 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;				
				// get color
				R = Color.red(pixels[index]);
				G = Color.green(pixels[index]);
				B = Color.blue(pixels[index]);
				// generate threshold
				thresHold = random.nextInt(COLOR_MAX);
				if(R > thresHold && G > thresHold && B > thresHold) {
					pixels[index] = Color.rgb(COLOR_MAX, COLOR_MAX, COLOR_MAX);
				}							
			}
		}
		// output bitmap				
		Bitmap bmOut = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
		bmOut.setPixels(pixels, 0, width, 0, 0, width, height);
		return bmOut;
	}
Categories: Tutorials Tags: , , ,