Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reduce an image size in image processing (scipy/numpy/python)

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

How can I reduce the size of the image ( ex. to 512 x 512) by modify that matrix a?

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

I have no idea how to modify the matrix a to reduce the size of the image. So if somebody has any idea, please share your knowledge and I will be appreciated. Thanks


EDIT:

When I look at the result, I found that the reader I got read the image and put it into a "matrix". So I changed the "array" to matrix.

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

Thanks

like image 631
Hold_My_Anger Avatar asked May 22 '11 07:05

Hold_My_Anger


2 Answers

I think the easyiest way is to take only some columns and some rows of the image. Makeing a sample of the array. Take for example, only those even rows and the even columns, put it in a new array and you would have a half size new image.

like image 139
José Carlos Méndez Avatar answered Sep 22 '22 10:09

José Carlos Méndez


Use the zoom 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)
like image 43
tillsten Avatar answered Sep 26 '22 10:09

tillsten