I am developing a Image editing app for Android. For this I need to convert my image to a pencil sketch.
Can you please help me in this.
I am developing a Image editing app for Android. For this I need to convert my image to a pencil sketch.
Can you please help me in this.
You require some image processing library to do that.
You can try ImageJ or Marvin.
For more information, you can refer this SO post: What is the best java image processing library/approach?
TO Convert The Image to pencil sketch you need to apply 3 filters
GRAYSCALE FILTER
INVERT THE COLORS
GAUSSIAN BLUR
after successfully applying these filters use colordodgeblend function to make pencil like sketch
Grayscale filter
ColorMatrix matrix = new ColorMatrix();
matrix.setSaturation(0);
ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
imgView.setColorFilter(filter);
CODE TO APPLY INVERT FILTER
float[] colorMatrix_Negative = {
-1.0f, 0, 0, 0, 255, //red
0, -1.0f, 0, 0, 255, //green
0, 0, -1.0f, 0, 255, //blue
0, 0, 0, 1.0f, 0 //alpha};
ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.set(colorMatrix_Negative);
ColorFilter colorFilter_Negative = new ColorMatrixColorFilter(colorMatrix_Negative);
CODE FOR GAUSSIAN BLUR
public static Bitmap applyGaussianBlur(Bitmap src) {
double[][] GaussianBlurConfig = new double[][]{
{-1, 0, -1},
{0, 4, 0},
{-1, 0, -1}
};
ConvolutionMatrix convMatrix = new ConvolutionMatrix(3);
convMatrix.applyConfig(GaussianBlurConfig);
convMatrix.Factor = 1;
convMatrix.Offset = 150;
//return out put bitmap return ConvolutionMatrix.computeConvolution3x3(src, convMatrix);
}