如何对多个像素放置像素

问题描述 投票:0回答:1

[当前,我正在可视化tiff图像的50个不同帧的非常特定位置上的当前像素强度值。为此,即时为所有50帧打印出相同的坐标值,一切工作正常。不过,为了确保我看到的是正确的像素,我决定将它们转换为黑色,但是出现标题中所述的以下错误。

TypeError: Invalid shape (50, 128, 160) for image data

在线

imgplot = plt.imshow(imageList)

图像为tiff格式,但是例如分成50帧

enter image description hereenter image description here

我在做什么是:

from os import listdir
from PIL import Image as PImage

def loadImages(path):

    imagesList = listdir(path)
    loadedImages = []
    for image in imagesList:
        img = PImage.open(path + image)
        loadedImages.append(img)


    return loadedImages



imgs = loadImages('C:/Dataset/Frames/')

for img in imgs:

    imgplot = plt.imshow(img)
    img.putpixel((45, 100), (0))
    img.putpixel((45, 80), (0))
    img.putpixel((50, 65), (0))
    img.putpixel((50, 110), (0))
    img.putpixel((40, 110), (0))
    img.putpixel((35, 90), (0))
    img.putpixel((25, 90), (0))
    img.putpixel((25, 110), (0))
    img.putpixel((64, 89), (0))
    img.putpixel((25, 100), (0))
    img.putpixel((40, 65), (0))
    img.putpixel((65, 60), (0))
    img.putpixel((65, 120), (0))
    img.putpixel((82, 75), (0))
    img.putpixel((82, 105), (0))
    img.putpixel((78, 88), (0))
    img.putpixel((110, 90), (0))
    img.putpixel((90, 89), (0))
    img.putpixel((100, 65), (0))
    img.putpixel((100, 110), (0))
    plt.show()

我基本上要做的是,以任何可能的方式更改文件夹中每个图像的这些恒定坐标中的值。

python python-3.x image image-processing tiff
1个回答
0
投票

我不确定我是否完全理解您的问题,但是您似乎正在尝试检查,更改和确认x / y坐标上的像素值。

首先,我建议将图像转换为numpy数组。您可以使用:

import numpy as np
arr = np.array(img)

现在,您可以像访问数组索引一样访问像素(或使用numpy的奇特索引)。

print(arr[0,0])

注意:numpy以高度/宽度顺序设置数组,因此您可以通过y/x而不是x/y访问数组。您可以通过arr.shape确定形状>

© www.soinside.com 2019 - 2024. All rights reserved.