Last active
March 29, 2019 04:12
-
-
Save frogermcs/b953a1632de105200aa7ce368ac5d6bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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