How to reduce image size when processing images (scipy / numpy / python)

Hello, I have an image (1024 x 1024) and I used the "fromfile" command in numpy to put every pixel of this image into a matrix.

How to reduce image size (for example, to 512 x 512) by changing this matrix?

a = numpy.fromfile(( - path - ,'uint8').reshape((1024,1024)) 

I do not know how to change matrix a to reduce image size. Therefore, if anyone has an idea, please share your knowledge, and I will be grateful. Thanks


EDIT:

When I look at the result, I find that the reader has read the image and placed it in the โ€œmatrixโ€. So I changed the "array" to a matrix.

Jose told me that I can only take an even column and even draw a row and put it in a new matrix. This will reduce the image to half the size. What command in scipy / numpy do I need to use for this?

thanks

+7
source share
3 answers

I think the easiest way is to take only some columns and some lines of the image. Creating an array pattern. Take, for example, only those even rows and even columns, placing them in a new array, and you will have an image with half size.

0
source

If you want to resize to a specific resolution, use scipy.misc.imresize:

 import scipy.misc i_width = 640 i_height = 480 scipy.misc.imresize(original_image, (i_height, i_width)) 
+16
source

Use the scaling function from scipy:

http://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.zoom.html#scipy.ndimage.zoom

 from scipy.ndimage.interpolation import zoom a = np.ones((1024, 1024)) small_a = zoom(a, 0.5) 
+15
source

All Articles