我创建了一张像这样的灰度图像。
但是我收到的却是一个语法错误。
为什么?谢谢。
def create_new_image(size, luminance):
width, height = size
black_frame = int(luminance) * np.ones((width, height, 1), dtype=np.uint8)
return black_frame
亮度值luminance属于[0,255]的元素集
我使用imageio保存了图片
def save_image(image, output_path):
imageio.imwrite(output_path, image)
这里的output_path
类似于/valid_path/img.jpg
现在我想要加载我的灰度图像:
img = imageio.imread(file, format ='jpg')
但是我收到的却是一个语法错误。
raise SyntaxError("not a JPEG file")
File "<string>", line None
SyntaxError: not a JPEG file
如果我不指定格式,就会出现另一个错误。
"Could not find a format to read the specified file in %s mode" % modename
ValueError: Could not find a format to read the specified file in single-image mode
为什么?谢谢。
output_path
的确切值吗? - DarK_FirefoXoutput_path
只是您计算机中某个地方的路径。例如:output_path = '/home/DarKFirefox/Document/your/path/'
。它只是一个字符串。 - Leos313format=jpg
,它对我来说也可以正常工作。imageio
文档说明它将根据文件(可能是文件扩展名)选择正确的解码器/编码器。所以@Jürgen K,我鼓励您打印(output_path)并检查它是否是文件的正确路径。 - DarK_FirefoX