如何在图像处理中减小图像大小(scipy/numpy/python)
你好,我有一个图像(1024 x 1024),我在 numpy 中使用“fromfile”命令将该图像的每个像素放入矩阵中。
如何通过修改矩阵 a 来减小图像的大小(例如 512 x 512)?
a = numpy.fromfile(( - path - ,'uint8').reshape((1024,1024))
我不知道如何修改矩阵 a 以减小图像的大小。因此,如果有人有任何想法,请分享您的知识,我将不胜感激。谢谢
编辑:
当我查看结果时,我发现我的读者读取了图像并将其放入“矩阵”中。所以我将“数组”更改为矩阵。
何塞告诉我,我只能将偶数列和偶数行放入一个新矩阵中。这会将图像缩小一半。我需要使用 scipy/numpy 中的什么命令来执行此操作?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想调整大小到特定分辨率,请使用 scipy.misc.imresize:
If you want to resize to specific resolution, use scipy.misc.imresize:
使用 scipy 中的缩放功能:
http://docs.scipy.org/doc/scipy/reference/ generated/scipy.ndimage.zoom.html#scipy.ndimage.zoom
Use the zoom function from scipy:
http://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.zoom.html#scipy.ndimage.zoom
我认为最简单的方法是只获取图像的一些列和一些行。制作数组的样本。举个例子,只有那些偶数行和偶数列,将其放入一个新数组中,您将得到一半大小的新图像。
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.