Java tutorial
//package com.java2s; //License from project: Apache License import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.ColorMatrix; import android.graphics.ColorMatrixColorFilter; import android.graphics.Paint; public class Main { public static Bitmap divide(Bitmap bitmap1, Bitmap bitmap2) { double alpha = Double.MIN_VALUE; int width = bitmap1.getWidth(); int height = bitmap1.getHeight(); Bitmap grayBitmap1 = toGrayScale(bitmap1); Bitmap grayBitmap2 = toGrayScale(bitmap2); Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); for (int x = 0; x < width; x++) for (int y = 0; y < height; y++) { int value1 = Color.blue(grayBitmap1.getPixel(x, y)); int value2 = Color.blue(grayBitmap2.getPixel(x, y)); // int resultValue = (int) (Math.abs((Math.log((value1 + alpha)/(value2 + alpha))) * 1000)); int resultValue = (int) ((Math.abs(Math.log((value1 + alpha) / (value2 + alpha)))) * 255); result.setPixel(x, y, Color.rgb(resultValue, resultValue, resultValue)); } // grayBitmap1.recycle(); // grayBitmap2.recycle(); return result; } public static Bitmap toGrayScale(Bitmap bmpOriginal) { int width, height; height = bmpOriginal.getHeight(); width = bmpOriginal.getWidth(); Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); Canvas c = new Canvas(bmpGrayscale); Paint paint = new Paint(); ColorMatrix cm = new ColorMatrix(); cm.setSaturation(0); ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm); paint.setColorFilter(f); c.drawBitmap(bmpOriginal, 0, 0, paint); return bmpGrayscale; } }