I am using one of the Tensorflow models provided by Google in the codelabs to apply Artistic Styles on the images.
I am using the below code to apply styles:
private fun stylizeImage(bitmap: Bitmap) {
val intValues = IntArray(desiredWidth * desiredHeight)
val floatValues = FloatArray(desiredWidth * desiredHeight* 3)
bitmap.getPixels(intValues, 0, bitmap.width, 0, 0, bitmap.width, bitmap.height)
for (i in 0 until intValues.size) {
val value = intValues[i]
floatValues[i * 3] = ((value shr 16) and 0xFF) / 255.0f
floatValues[i * 3 + 1] = ((value shr 8) and 0xFF) / 255.0f
floatValues[i * 3 + 2] = (value and 0xFF) / 255.0f
}
// Copy the input data into TensorFlow.
inferenceInterface.feed(INPUT_NODE, floatValues, 1, bitmap.width.toLong(), bitmap.height.toLong(), 3)
inferenceInterface.feed(STYLE_NODE, styleVals, NUM_STYLES.toLong())
// Execute the output node's dependency sub-graph.
inferenceInterface.run(arrayOf(OUTPUT_NODE), false)
// Copy the data from TensorFlow back into our array.
inferenceInterface.fetch(OUTPUT_NODE, floatValues)
for (i in 0 until intValues.size) {
intValues[i] = (0xFF000000.toInt()
or ((floatValues[i * 3] * 255).toInt() shl 16)
or ((floatValues[i * 3 + 1] * 255).toInt() shl 8)
or (floatValues[i * 3 + 2] * 255).toInt())
}
val newBm = Bitmap.createBitmap(intValues, bitmap.width, bitmap.height, Bitmap.Config.ARGB_8888)
imageView.setImageBitmap(newBm)
}
The problem is that the above code works fine if the dimensions of the desiredWidth and the desiredHeight are the same (Square images). If the dimensions are different (Rectangular images), the output image is not as expected and some patterns are repeated as shown below. 
Any help will be appreciated. Thanks.
from Unable to stylize Bitmap having different height and width
No comments:
Post a Comment