标签: python-imageio

使用Python Imageio的gif中的透明背景

基本上,我正在使用以下代码从图像制作gif,我的图像png具有透明背景,但是gif具有黑色背景。我不知道如何使gif具有透明背景。

#gif writer
with io.get_writer('my.gif', mode='I', duration=0.1) as writer:
    for filename in file_names:
        image = io.imread(filename)
        writer.append_data(image)
#writer.close()
Run Code Online (Sandbox Code Playgroud)

其中filenames是要使用的所有文件名的数组。

python python-imageio

5
推荐指数
1
解决办法
1394
查看次数

python中的图像尺寸错误

试图匹配两个图像以找出它们之间的分数。但它显示了一些尺寸错误。无法解决问题。我的代码如下:

from skimage.measure import compare_ssim
#import argparse
#import imutils
import cv2

img1="1.png"
img2="2.png"


# load the two input images
imageA = cv2.imread(img1)
imageB = cv2.imread(img2)

# convert the images to grayscale
grayA = cv2.cvtColor(imageA, cv2.COLOR_BGR2GRAY)
grayB = cv2.cvtColor(imageB, cv2.COLOR_BGR2GRAY)


# compute the Structural Similarity Index (SSIM) between the two
# images, ensuring that the difference image is returned
(score, diff) = compare_ssim(grayA, grayB, full=True)
diff = (diff * 255).astype("uint8")
print("SSIM: {}".format(score))
Run Code Online (Sandbox Code Playgroud)

这给 n 一个错误:

raise ValueError('Input images must have the …
Run Code Online (Sandbox Code Playgroud)

python image-processing python-imaging-library python-3.x python-imageio

5
推荐指数
2
解决办法
9064
查看次数

使用 ImageIO 和 Python 将 EXR 转换为 JPEG

我只是想将 EXR 转换为 jpg 图像,但是结果却非常暗。有谁知道我在这里做错了什么?我正在标准化图像值,然后将它们放入 0-255 颜色空间。尽管如此,它仍然看起来不正确。

用于测试 exr 图像的 Dropbox 链接:https ://www.dropbox.com/s/9a5z6fjsyth7w98/torus.exr ? dl =0

在此处输入图片说明

import sys, os
import imageio

def convert_exr_to_jpg(exr_file, jpg_file):
    if not os.path.isfile(exr_file):
        return False

    filename, extension = os.path.splitext(exr_file)
    if not extension.lower().endswith('.exr'):
        return False

    # imageio.plugins.freeimage.download() #DOWNLOAD IT
    image = imageio.imread(exr_file, format='EXR-FI')

    # remove alpha channel for jpg conversion
    image = image[:,:,:3]

    # normalize the image
    data = image.astype(image.dtype) / image.max() # normalize the data to 0 - 1
    data = 255 * data # …
Run Code Online (Sandbox Code Playgroud)

python python-imageio

5
推荐指数
1
解决办法
3641
查看次数

ImageIO 中的质量损失

我有一系列高分辨率图像,我想使用 ImageIO 在 Python(3.6) 中将其转换为 MP4 文件。有没有什么办法可以在不压缩或不损失质量的情况下做到这一点?

目前我使用的代码:

fileList = []
path = "./Images/MP4/relu-3layers-32units-M1/"
name = "img"
for file in os.listdir(path):
    if file.startswith(name):
        complete_path = path + file
        fileList.append(complete_path)

 writer = imageio.get_writer('test.mp4', fps = 30)

 for im in fileList:
      writer.append_data(imageio.imread(im))
 writer.close()
Run Code Online (Sandbox Code Playgroud)

它生成视频,但质量大大降低。有任何解决这个问题的方法吗?

video python-3.x python-imageio

5
推荐指数
1
解决办法
1522
查看次数

VOC2012:PIL Image.open 将 PNG 转换为 2d 数组

我正在使用 VOC2012 数据集。输入图像为 PNG 格式,当我使用 imageio 打开图像时,其形状为 (375, 500, 4)。当我使用 PIL 打开图像时,形状突然变成 (500, 375)。PNG 图像在最后一个轴上应有四个维度:rgb 和 alpha。这是示例图像

该图像显然是彩色图像,因此它应该具有 3 个维度(高度、宽度、深度)。PIL 似乎表明它只有两个维度:宽度和高度。

PNG图像可以用二维数组表示吗?请帮忙!所以此刻迷失了。谢谢!

from PIL import Image
from keras.preprocessing.image import img_to_array
import os, imageio
import numpy as np

root_path = '/Users/johnson/Downloads/'

imageio_img = imageio.imread(
    os.path.join(root_path, '2009_003193.png')
)

# (375, 500, 4)
print(imageio_img.shape)
# [  0 128 192 224 255]
print(np.unique(imageio_img))


PIL_img = Image.open(
    os.path.join(root_path, '2009_003193.png')
)

# (500, 375)
print(PIL_img.size)

PIL_img_to_array = img_to_array(PIL_img)
# (375, 500, 1)
print(PIL_img_to_array.shape)
# [  0. …
Run Code Online (Sandbox Code Playgroud)

python-imaging-library deep-learning keras python-imageio

5
推荐指数
1
解决办法
2163
查看次数

如何从圆形蒙版图像制作gif?

下载带有图像的邮政编码

我有一个带有圆形蒙版png图像的文件夹:

在此处输入图片说明 在此处输入图片说明 在此处输入图片说明

通常,我使用以下代码制作gif文件:

import imageio
import os

imglist = []
images = []
path = ('\\').join(__file__.split('\\')[:-1]) + '\\' + 'images\\'
for r, _, f in os.walk(path):
    for i in f:
        imglist.append(r + i)

for filename in imglist:
    if filename.endswith('.png'):
        images.append(imageio.imread(filename))

frames_per_second = 24
gifpath = ('\\').join(__file__.split('\\')[:-1]) + '\\' + 'GIF.gif'
imageio.mimsave(gifpath, images, duration = 1/frames_per_second)
Run Code Online (Sandbox Code Playgroud)

这对于普通图像效果很好,但似乎忽略了蒙版图像。gif看起来像这样:

在此处输入图片说明

知道如何制作圆形gif吗?

python opencv gif python-imaging-library python-imageio

5
推荐指数
1
解决办法
136
查看次数

无法在python3中导入模块imageio

使用 python3,我无法将 imageio 模块导入到我需要的 python 程序中,因为我尝试对我拥有的 PNG 图像列表进行动画处理。到目前为止我已经尝试过:

“pip3 install imageio”都以我自己和 root 身份运行。安装成功,但仍然出现错误,如主题行所示。我想我可以尝试“apt-get install(包名称)”,但需要确定 package_name。

欢迎任何想法 - TIA。

python-3.x python-imageio

5
推荐指数
1
解决办法
1万
查看次数

来自一组png图像的python imageio mp4视频

如何使用模块从一组 png 图像制作 mp4 视频imageio?我试过这个:

import imageio
import glob
writer = imageio.get_writer('test.mp4', fps=20)
for png_path in glob.glob('*.png'):
    im = imageio.imread(png_path),
    writer.append_data(im[:, :, 1])
writer.close()
Run Code Online (Sandbox Code Playgroud)

我也试着更换im[:, :, 1]im。我究竟做错了什么?我很高兴使用另一个模块。

python video mp4 python-imageio

4
推荐指数
2
解决办法
1万
查看次数

ValueError:找不到在模式“ i”下读取指定文件的格式

我正在尝试将png文件读入在docker中运行的python-flask应用程序中,并收到一条错误消息,内容为

ValueError:找不到在模式“ i”下读取指定文件的格式

我已经使用HTML文件上传了文件,现在我正尝试阅读该文件以进行进一步处理。我看到scipy.misc.imread已被弃用,我正尝试将其替换为imageio.imread

if request.method=='POST':
    file = request.files['image']
    if not file: 
        return render_template('index.html', label="No file")
    #img = misc.imread(file)
    img = imageio.imread(file)
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

File "./appimclass.py", line 34, in make_prediction

img = imageio.imread(file)

File "/usr/local/lib/python3.6/site-packages/imageio/core/functions.py", line 221, in imread

reader = read(uri, format, "i", **kwargs)

File "/usr/local/lib/python3.6/site-packages/imageio/core/functions.py", line 139, in get_reader

"Could not find a format to read the specified file " "in mode %r" % mode
Run Code Online (Sandbox Code Playgroud)

python-3.x python-imageio

3
推荐指数
2
解决办法
5073
查看次数

如何使用“imageio”在视频中查找帧?

我有一个视频,我想从视频中仅提取特定的帧。

目前我所做的是:

index = [1,2,3,4,5,6,7,8]
img_list = []
for i, frame in enumerate(iio.imiter("imageio:cockatoo.mp4")):
    if i in index:
        img_list.append(frame)

img_array = np.asarray(img_list)
Run Code Online (Sandbox Code Playgroud)

有没有办法只“寻找”我想要的帧,就像在 opencv 中完成的那样,如此处所示

python opencv video-processing python-imageio

3
推荐指数
1
解决办法
1961
查看次数