Some General queries to Save an Image after resizing and best way to read the image so that it takes lowest memory.

asked 2018-09-08 01:20:16 -0600

Having a grayscale image of Lungs/TB in some high resolution say width * height I have resized(downsample) it to a new resolution say new_width * new_height using Image.Antialias format as its the best among others that are (Nearest_neighbour, Bilinear etc) to downsample for segmentation purpose.

Query#1

What's the best Image formats (jpeg, jpg, png) should I save the downsampled/resized image as they are based on some compressions e.g. lossless is used for jpeg, so that minimum amount of loss is entertained.

Query#2

Let us suppose that we saved the resized_image (300*300) in a png format. Its actual size 81kb. But when I am going to read this image as np.array using PIL it gives me a size of 360112 in float32 format and 720112 in float64 format.

from PIL import Image
from sys import getsizeof
img=np.asarray(Image.open(path),dtype=('float32'))/255.0
getsizeof(img)             # 360112bytes

Should this also not supposed to be 81kb. Same is the case for cv2.imread.

Query#3

What's the best way to read the image as a numpy array so that it takes the lowest memory.

edit retag flag offensive close merge delete

Comments

lossless is used for jpeg,

wrong. jpg is lossy, so avoid that and use png instead.

berak gravatar imageberak ( 2018-09-08 02:28:58 -0600 )edit
1

hmmm, but how is any of it related to opencv ?

berak gravatar imageberak ( 2018-09-08 02:30:00 -0600 )edit