Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何重塑skimage.imread读取的png图像_Python_Image_Png_Scikit Image_Cv2 - Fatal编程技术网

Python 如何重塑skimage.imread读取的png图像

Python 如何重塑skimage.imread读取的png图像,python,image,png,scikit-image,cv2,Python,Image,Png,Scikit Image,Cv2,然后我读了一些jpg文件,这样 image = imread('aa.jpg') 结果我得到的数据帧的数字从1到255 我可以这样调整它的大小: from cv2 import resize image = resize(image, (256, 256) 但我对png也这么认为,结果并不理想 image = imread('aa2.png') # array with number within 0-1 range resize(image, (256,256)) # returns 1

然后我读了一些jpg文件,这样

image = imread('aa.jpg')
结果我得到的数据帧的数字从1到255

我可以这样调整它的大小:

from cv2 import resize
image = resize(image, (256, 256)
但我对png也这么认为,结果并不理想

image = imread('aa2.png')  # array with number within 0-1 range
resize(image, (256,256)) # returns 1 channel image
resize(image, (256,256, 3))   # returns 3 channel image
怪异形象

但是
imshow(图像)


我想您的图像或代码可能有问题

这里有一张免费图片供您尝试:

可能您对libpng有问题,请检查以下答案:

检查这段适用于PNG图像的简单代码

     import cv2 as cv
     image = cv.imread("foto.png")
     if __name__ == "__main__":
          while True:
                image = cv.resize(image,(200,200))
                cv.imshow("prueba",image)

                key = cv.waitKey(10)
                if key == 27:
                    cv.destroyAllWindows()
                    break   

     cv.destroyAllWindows()

我猜你的图像或代码有问题

这里有一张免费图片供您尝试:

可能您对libpng有问题,请检查以下答案:

检查这段适用于PNG图像的简单代码

     import cv2 as cv
     image = cv.imread("foto.png")
     if __name__ == "__main__":
          while True:
                image = cv.resize(image,(200,200))
                cv.imshow("prueba",image)

                key = cv.waitKey(10)
                if key == 27:
                    cv.destroyAllWindows()
                    break   

     cv.destroyAllWindows()

cv2.imread
默认情况下以3通道而不是4通道读取图像。传递参数
cv.IMREAD\u UNCHANGED
以读取PNG文件,然后尝试调整其大小,如下面的代码所示

import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt

img = cv.imread('Snip20190412_12.png', cv.IMREAD_UNCHANGED)
print(img.shape) #(215, 215, 4)

height, width = img.shape[:2]
res = cv.resize(img,(2*width, 2*height))
print(res.shape)#(430, 430, 4)
plt.imshow(res)

cv2.imread
默认情况下以3通道而不是4通道读取图像。传递参数
cv.IMREAD\u UNCHANGED
以读取PNG文件,然后尝试调整其大小,如下面的代码所示

import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt

img = cv.imread('Snip20190412_12.png', cv.IMREAD_UNCHANGED)
print(img.shape) #(215, 215, 4)

height, width = img.shape[:2]
res = cv.resize(img,(2*width, 2*height))
print(res.shape)#(430, 430, 4)
plt.imshow(res)

您正在寻找
skimage.transform.resize
skimage.transform.rescale
。请包含
import
语句,以便清楚您使用的是哪些模块,并且您的示例最少且完整。请同时附上您的
aa.png
图像。谢谢。您正在查找
skimage.transform.resize
skimage.transform.rescale
。请包含
import
语句,以便清楚地了解您正在使用的模块以及您的示例是最少和完整的。请同时附上您的
aa.png
图像。非常感谢。