Archive

Posts Tagged ‘effect’

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

Image Processing – Engraving Effect

June 22, 2011 3 comments

Engraving is also one of derivation from the edge detection algorithm, which makes use of Convolution Matrix.

You might need to refer to my previous article on Convolution Matrix for more information.

The matrix I’m using is:

[ -2 | 0 | 0 ]

[ 0 | 2 | 0 ]

[ 0 | 0 | 0 ]

The factor is 1 and offset is 95.

You’ll get this:

Original Image

Original Image

Applied Engraving Effect

Applied Engraving Effect

This is the implementation:

	public static Bitmap engrave(Bitmap src) {
		ConvolutionMatrix convMatrix = new ConvolutionMatrix(3);
		convMatrix.setAll(0);
		convMatrix.Matrix[0][0] = -2;
		convMatrix.Matrix[1][1] = 2;
		convMatrix.Factor = 1;
		convMatrix.Offset = 95;
		return ConvolutionMatrix.computeConvolution3x3(src, convMatrix);
	}

Hope you like it!

Cheers,
Pete Houston

Image Processing – Emboss Effect

June 22, 2011 2 comments

A cool, nice effect 🙂

Applied from Convolution Matrix concept with the following matrix:

[ -1 | 0 | -1 ]

[ 0 | 4 | 0 ]

[ -1 | 0 | -1 ]

The factor is 1 and offset is 127.

Got these results:

Original Image

Original Image

Applied Emboss Effect

Applied Emboss Effect

This is the implementation (the same old one used for Convolution Matrix on my articles, lol)

	public static Bitmap emboss(Bitmap src) {
		double[][] EmbossConfig = new double[][] {
			{ -1 ,  0, -1 },
			{  0 ,  4,  0 },
			{ -1 ,  0, -1 }
		};
		ConvolutionMatrix convMatrix = new ConvolutionMatrix(3);
		convMatrix.applyConfig(EmbossConfig);
		convMatrix.Factor = 1;
		convMatrix.Offset = 127;
		return ConvolutionMatrix.computeConvolution3x3(src, convMatrix);
	}

A cool effect, isn’t it?
Hope you like it!

Cheers,
Pete Houston

Image Processing – Smooth Effect

June 22, 2011 4 comments

The smooth effect makes use of Convolution Matrix, you might need to refer to my previous post on Convolution Matrix.

The applied matrix for the effect:

[ 1 | 1 | 1 ]

[ 1 | 5 | 1 ]

[ 1 | 1 | 1 ]

The factor is 13 and offset 1.

Below is the comparison:

Original Image

Original Image

Applied Smooth Effect

Applied Smooth Effect

It took me a while to compare these twos, look carefully I see the differences. Oh well, you may want to use another picture to test. However, I love this one 🙂

Here the implementation:

	public static Bitmap smooth(Bitmap src, double value) {
		ConvolutionMatrix convMatrix = new ConvolutionMatrix(3);
		convMatrix.setAll(1);
		convMatrix.Matrix[1][1] = value;
		convMatrix.Factor = value + 8;
		convMatrix.Offset = 1;
		return ConvolutionMatrix.computeConvolution3x3(src, convMatrix);
	}

Hope you like it!

Cheers,
Pete Houston

Image Processing – Mean Removal Effect

June 22, 2011 2 comments

Mean Removal Effect is also created by using Convolution Matrix.

Please refer to my previous article on Convolution Matrix for information.

The applied matrix is:

[ -1 | -1 | -1 ]

[ -1 |  9 | -1 ]

[ -1 | -1 | -1 ]

The factor is 1 and offset is 0.

Compare these two pixes : (well, it’s better to start with a blurry one)

Original Image

Original Image

Applied Mean Removal

Applied Mean Removal

The simple implementation:

	public static Bitmap applyMeanRemoval(Bitmap src) {
		double[][] MeanRemovalConfig = new double[][] {
			{ -1 , -1, -1 },
			{ -1 ,  9, -1 },
			{ -1 , -1, -1 }
		};
		ConvolutionMatrix convMatrix = new ConvolutionMatrix(3);
		convMatrix.applyConfig(MeanRemovalConfig);
		convMatrix.Factor = 1;
		convMatrix.Offset = 0;
		return ConvolutionMatrix.computeConvolution3x3(src, convMatrix);
	}

Hope you like it!

Cheers,
Pete Houston