• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Scale bitmap without losing resolution

Because

Lurker
Hello everyone, I'm developing an Android app to do image recognition using Tensorflow. I'm taking a cue from this project. I'm having problems because I'm not using the Android camera but an external camera, specifically the camera of a DJI Mavic Air. So far I've taken the video stream of the camera and put it in a Textureview and then I took using the OnYuvDataReceived CallBack from which I can get the streaming of frames in Yuv. Now comes the problematic part: Tensorflow accepts only bitmaps that have size 416x416 for the recognition and the streaming of the DJI camera is 1080x720. Scaling the image to 416x416 becomes too flattened and the recognition is no longer real. So I wanted to know if there is a method to scale an image without losing too much resolution, at least to allow the recognition.
Thanks
 
You're converting from a size that's not proportional to a square, which is 416 x 416....
Not sure how that would work.
 
You're converting from a size that's not proportional to a square, which is 416 x 416....
Not sure how that would work.

If you look at the project linked, you can see that the author did in that way, he uses the lower android camera resolution (for my phone 640x480) and then he scale the bitmap to 416x416
 
To take a rectangular 1080x720 image and scale it down to 416x416, it's a mathematically impossible feat if you want to also a) retain the same image proportions, h x w and b) retain at least some recognizable image quality as you're literally removing pixels in the scaling process. In that linked site, you also need to factor in that the scaled down image also shows that subtle, yet clearly rectangular, cropping outline.
What you're asking is
1080 scaled down to 416 -- 38.5%
720 scaled down to 416 -- 57.8%
while still retaining the same image proportions (h x w) and at least some image quality. There has to be a some kind of compromise. Either you crop off parts of the image (as shown in that link) to retain the corresponding h x w, and use a lessor amount of scaling to at least minimize the inevitable loss of image quality; Or you have accept that your resulting images have to be scaled down disproportionately, resulting in a very skewed image.
Aspect ratio:
https://en.wikipedia.org/wiki/Display_aspect_ratio
Pixel density
https://en.wikipedia.org/wiki/Pixel_density#Calculation_of_monitor_PPI
 
You're either going to end up with 2 sides cropped off to produce the end result square, or a smushed image being square.
 
Back
Top Bottom