sagar suri
sagar suri

Reputation: 4731

How to resize bitmap to low resolution without loosing image information?

I am creating a deep learning based android app. I have a Canvas where I am allowing the user to draw something. Then I will pass the bitmap of the Canvas to my model for classification. I am using Tensorflow MNIST project as the base for my project. My problem is, in the MNIST example user are allowed to draw on a 28x28 size Canvas. But I don't want to do that because drawing on that Canvas is pixelating the drawing. I am drawing on a full size Canvas but while sending the Bitmap of the canvas to the Tensorflow model I want to resize it to 28x28 for classification (else I am getting ArrayIndexOutOfBoundException).

How can I resize the bitmap to 28x28 without loosing information ? or any other possible solution for this ?

Here is the image of the MNIST canvas:

enter image description here

This is the image of my application canvas. I tried resizing it to 28x28 but I am loosing the image information:

enter image description here

Upvotes: 0

Views: 335

Answers (1)

Deniz Beker
Deniz Beker

Reputation: 2174

Let's say you have an input of 100 x 100 image and you want to resize it to 28 x 28.

100 x 100 pixels -> 10000 features

28 x 28 pixels -> 784 features

It is mathematically impossible not to lose input information while resizing.

However there are other ways to work around.

  • Get rid of white areas around drawing. It will already filter most of the unnecessary pixels. Then you can apply resizing.
  • Try a different interpolation method. During the resizing operation, we are using different kinds of interpolations (bilinear, bicubic etc.).
  • Try to make the input images bigger for your network (resize 28 x 28 MNIST to 56 x 56 for example) and train with bigger size. Then, you will be losing less information for inference in cost of speed as it will be slightly slower to classify larger image.

Upvotes: 2

Related Questions