Archive

Archive for October, 2011

Image Processing – Hue Filter

October 30, 2011 Leave a comment

The same concept of the Saturation Filter but apply for Hue.

Original Image

Original Image

Image w/ Hue Filter (Level 3)

Image w/ Hue Filter (Level 3)

Image w/ Hue Filter (Level 9)

Image w/ Hue Filter (Level 9)

Here the implementation:

	public static Bitmap applyHueFilter(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[0] *= level;
				HSV[0] = (float) Math.max(0.0, Math.min(HSV[0], 360.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

Advertisements
Categories: Tutorials Tags: , , ,

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: , , ,

Image Processing – Black Filter (Increasing the Darkness)

October 30, 2011 4 comments

Base on randomizing image pixels, another filter is created, named “Black Filter“, or enhance the noise of darkness.

Original Image

Original Image

Image w/ Black Filter

Image w/ Black Filter

It looks like ink-dropping, isn’t it?

Basically, the algorithm is to generate a threshold number (0-255), if all R,G,B values of a pixel are less than the threshold, then set the pixel to black.

	public static Bitmap applyBlackFilter(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 = 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;
				// 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_MIN, COLOR_MIN, COLOR_MIN);
				}
			}
		}
		// 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 – Flea / Noise Effect

October 30, 2011 Leave a comment

Back to Image Processing Lab, today I’d like to introduce a new effect; well, you might know it already, it’s called “Flea Effect” or known as “Noise“.

Original Image

Original Image

Image w/ Flea Effect

Image w/ Flea Effect

The algorithm is pretty much simple

>> Take OR operation of the current pixel color with a new random color.

Here the implementation:

	public static final int COLOR_MIN = 0x00;
	public static final int COLOR_MAX = 0xFF;

	public static Bitmap applyFleaEffect(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);
		// a random object
		Random random = new Random();

		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;
				// get random color
				int randColor = Color.rgb(random.nextInt(COLOR_MAX),
						random.nextInt(COLOR_MAX), random.nextInt(COLOR_MAX));
				// OR
				pixels[index] |= randColor;
			}
		}
		// output bitmap
		Bitmap bmOut = Bitmap.createBitmap(width, height, source.getConfig());
		bmOut.setPixels(pixels, 0, width, 0, 0, width, height);
		return bmOut;
	}

Cheers,
Pete Houston

Categories: Tutorials Tags: , , , ,

Presentation Paper – Android Common Mistakes

October 29, 2011 2 comments

Publication: Android Common Mistakes
Author: Pete Houston (aka. ‘xjaphx’)
Release Date: 29-Oct-2011
Documentation Format: PPTX (PowerPoint Presentation 2007)

Download: Android Common Mistakes

Description:
– A short illustration of Android common mistakes that many programmers/developers have taken nowadays.

 

Feel free to use my papers but please leave the credit to the author!

Cheers,
Pete Houston