开发者

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


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

import scipy.misc

i_width = 640
i_height = 480

scipy.misc.imresize(original_image, (i_height, i_width))


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)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜