/** | |
* Make bitmap appropriate size, greyscale and inverted. MNIST model is originally teached on | |
* dataset of images 28x28px with white letter written on black background. | |
*/ | |
public static Bitmap prepareImageForClassification(Bitmap bitmap) { | |
ColorMatrix colorMatrix = new ColorMatrix(); | |
colorMatrix.setSaturation(0); | |
colorMatrix.postConcat(BLACKWHITE); | |
colorMatrix.postConcat(INVERT); | |
ColorMatrixColorFilter f = new ColorMatrixColorFilter(colorMatrix); | |
Paint paint = new Paint(); | |
paint.setColorFilter(f); | |
Bitmap bmpGrayscale = Bitmap.createScaledBitmap( | |
bitmap, | |
MnistModelConfig.INPUT_IMG_SIZE_WIDTH, | |
MnistModelConfig.INPUT_IMG_SIZE_HEIGHT, | |
false); | |
Canvas canvas = new Canvas(bmpGrayscale); | |
canvas.drawBitmap(bmpGrayscale, 0, 0, paint); | |
return bmpGrayscale; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment