Python 如何保存np.tile图像
我想获得尺寸为60*25*25*1的平铺图像,并将它们保存在与原始图像同名的文件夹中。目前,我得到60*25*25形状的图像。最后,我想用这些图像形成大小为[batchsize,60,25,25,1]的张量,以输入到我的模型中 有人能帮我吗 我正在使用的代码Python 如何保存np.tile图像,python,numpy,Python,Numpy,我想获得尺寸为60*25*25*1的平铺图像,并将它们保存在与原始图像同名的文件夹中。目前,我得到60*25*25形状的图像。最后,我想用这些图像形成大小为[batchsize,60,25,25,1]的张量,以输入到我的模型中 有人能帮我吗 我正在使用的代码 outPath = "C:/output-images/" path = "C:/input-images" # iterate through the names of contents of
outPath = "C:/output-images/"
path = "C:/input-images"
# iterate through the names of contents of the folder
for image_path in os.listdir(path):
# create the full input path and read the file
input_path = os.path.join(path, image_path)
image_to_tile = np.array(Image.open(input_path))
print(image_to_tile.shape)
# rotate the image
tiled = np.tile(image_to_tile, [60,1,1])
print(tiled.shape)
# create full output path, 'example.jpg'
# becomes 'rotate_example.jpg', save the file to disk
fullpath = os.path.join(outPath, 'tiled-' + image_path)
cv2.imwrite(fullpath, tiled)
输出:
(25, 25)
(60, 25, 25)
---------------------------------------------------------------------------
error Traceback (most recent call last)
<ipython-input-85-8a74569fa0d7> in <module>
15 # becomes 'rotate_example.jpg', save the file to disk
16 fullpath = os.path.join(outPath, 'tiled-' + image_path)
---> 17 cv2.imwrite(fullpath, tiled)
error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-zsozjuva\opencv\modules\imgcodecs\src\loadsave.cpp:674: error: (-215:Assertion failed) image.channels() == 1 || image.channels() == 3 || image.channels() == 4 in function 'cv::imwrite_'
(25,25)
(60, 25, 25)
---------------------------------------------------------------------------
错误回溯(最近一次呼叫上次)
在里面
15#变成“rotate_example.jpg”,将文件保存到磁盘
16 fullpath=os.path.join(输出路径“平铺-”+图像路径)
--->17 cv2.imwrite(完整路径,平铺)
错误:OpenCV(4.4.0)C:\Users\appveyor\AppData\Local\Temp\1\pip req build zsozjuva\OpenCV\modules\imgcodecs\src\loadsave.cpp:674:错误:(-215:断言失败)image.channels()=1 | | image.channels()=3 | | image.channels()=4在函数“cv::imwrite”