在公益诉讼/ scipy imresize。misc只适用于uint8图像?替代品吗?

时间:2022-03-07 00:23:34

It seems the imresize implemented in PIL/scipy.misc only works for uint8 images

它似乎是在PIL/scipy中实现的imresize。misc只适用于uint8图像。

>>> import scipy.misc
>>> im = np.random.rand(100,200)
>>> print im.dtype
float64

>>> im2 = scipy.misc.imresize(im, 0.5)
>>> print im2.dtype
uint8

Is there any way around this? I'd like to deal HDR images and therefore needs to deal with float64 or float32 images. Thanks.

有没有办法解决这个问题?我想要处理HDR图像,因此需要处理float64或float32图像。谢谢。

2 个解决方案

#1


10  

Thanks to cgohlke's comment. Below are two alternatives I found that works for float-number images.

由于cgohlke的评论。下面是我发现的两种用于浮动数字图像的方法。

  1. Use scipy.ndimage.interpolation.zoom
  2. 使用scipy.ndimage.interpolation.zoom

For single-channel images: im2 = scipy.ndimage.interpolation.zoom(im, 0.5)

对于单通道图像:im2 = scipy.ndimage.. zoom(im, 0.5)

For 3-channel images: im2 = scipy.ndimage.interpolation.zoom(im, (0.5, 0.5, 1.0))

对于3通道图像:im2 = scipy.ndimage.. zoom(im, (0.5, 0.5, 1.0))

  1. Use OpenCV.
  2. 使用OpenCV。

im2 = cv2.resize(im, (im.shape[1]/2, im.shape[0]/2))

im2 = cv2。调整(im(即时通讯。形状[1]/ 2,im.shape[0]/ 2)

This works for both single-channel and 3-channel images. Note that one needs to revert the shape order in second parameter.

这对单通道和三通道图像都有效。注意,需要在第二个参数中恢复形状顺序。

#2


1  

you could also use the mode='F' option in the imresize function

您还可以在imresize函数中使用mode='F'选项。

imresize(image, factor, mode='F')

#1


10  

Thanks to cgohlke's comment. Below are two alternatives I found that works for float-number images.

由于cgohlke的评论。下面是我发现的两种用于浮动数字图像的方法。

  1. Use scipy.ndimage.interpolation.zoom
  2. 使用scipy.ndimage.interpolation.zoom

For single-channel images: im2 = scipy.ndimage.interpolation.zoom(im, 0.5)

对于单通道图像:im2 = scipy.ndimage.. zoom(im, 0.5)

For 3-channel images: im2 = scipy.ndimage.interpolation.zoom(im, (0.5, 0.5, 1.0))

对于3通道图像:im2 = scipy.ndimage.. zoom(im, (0.5, 0.5, 1.0))

  1. Use OpenCV.
  2. 使用OpenCV。

im2 = cv2.resize(im, (im.shape[1]/2, im.shape[0]/2))

im2 = cv2。调整(im(即时通讯。形状[1]/ 2,im.shape[0]/ 2)

This works for both single-channel and 3-channel images. Note that one needs to revert the shape order in second parameter.

这对单通道和三通道图像都有效。注意,需要在第二个参数中恢复形状顺序。

#2


1  

you could also use the mode='F' option in the imresize function

您还可以在imresize函数中使用mode='F'选项。

imresize(image, factor, mode='F')