Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.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 如何为多个像素添加像素_Python_Python 3.x_Image_Image Processing_Tiff - Fatal编程技术网

Python 如何为多个像素添加像素

Python 如何为多个像素添加像素,python,python-3.x,image,image-processing,tiff,Python,Python 3.x,Image,Image Processing,Tiff,目前,我正在可视化tiff图像50个不同帧的特定位置上的当前像素强度值。要做到这一点,我打印出所有50帧的相同坐标值,一切都很完美。尽管如此,为了确保我看到的是正确的像素,我决定将它们转换为黑色,但我得到了标题中描述的以下错误 TypeError: Invalid shape (50, 128, 160) for image data 排队 imgplot=plt.imshow(图像列表) 例如,这些图像是tiff格式的,但被分割为50帧 我正在做的是: from os import list

目前,我正在可视化tiff图像50个不同帧的特定位置上的当前像素强度值。要做到这一点,我打印出所有50帧的相同坐标值,一切都很完美。尽管如此,为了确保我看到的是正确的像素,我决定将它们转换为黑色,但我得到了标题中描述的以下错误

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

imgplot=plt.imshow(图像列表)

例如,这些图像是tiff格式的,但被分割为50帧

我正在做的是:

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()

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

我不确定我是否完全理解您的问题,但看起来您正在尝试检查、更改和确认x/y坐标处的像素值

我建议您将图像转换为numpy阵列。您可以通过以下方式执行此操作:

import numpy as np
arr = np.array(img)
现在,您可以访问像素,就好像您正在对数组进行索引一样(或者使用numpy的奇特索引)

注意:numpy按高度/宽度顺序设置阵列,因此您可以通过
y/x
而不是
x/y
访问阵列。您可以使用
arr.shape

也可以对数组进行切片。例如,如果需要顶部/左侧50个像素,可以:

sub_arr = arr[0:50, 0:50]
编辑:看起来您只是想提取像素值并将其放入向量中。你可以这样做:

# list of coordinates to extract IN Y/X FORMAT 
coord_list = [[100, 45], [80, 45], ... ]

# not really sure what your feature vector looks like, just using a list
feat_vec = []

for img in imgs:
    # list for per-image features
    img_feats = []
    for coords in coord_list:
        img_feats.append(img[coords[0], coords[1]])
    feat_vec.append(img_feats) 

哪一行导致错误?共享您的图像可能会有所帮助。抱歉,我已更新了该线程。因此,我有50个图像/帧从一个图像分解,我试图把像素放在上面的坐标中。我正在使用getpixel成功打印出这些特定位置的值,但我希望通过更改这些像素的颜色来确认我读取的像素是正确的谢谢,但那不是真正的图像,它是一张带有轴和白色边框的图像。@MarkSetchell我已经用tif格式的实际图像进行了更新,希望能帮上忙这对我来说似乎没什么意义。您说您只想更改每个图像中的几个像素,那么为什么还要使用
matplotlib
?那是不必要的,因为它只是为了展示,当然?然后,您似乎一次加载了一个包含50幅图像的庞大列表。你为什么要那样做?这只意味着你需要50倍的内存——为什么不一次处理一个呢?该死,这就像我拼命想做的一样。
# list of coordinates to extract IN Y/X FORMAT 
coord_list = [[100, 45], [80, 45], ... ]

# not really sure what your feature vector looks like, just using a list
feat_vec = []

for img in imgs:
    # list for per-image features
    img_feats = []
    for coords in coord_list:
        img_feats.append(img[coords[0], coords[1]])
    feat_vec.append(img_feats)