简体   繁体   English

删除np数组中值为0 255的像素

[英]Delete pixel with value 0 255 in np array

I am using Opencv and python 3.6 I have an image with this dimensions: 我正在使用Opencv和python 3.6,我有一个具有以下尺寸的图像:

depth = depth[0:240, 96:320]

So an image of (240,224). 因此是(240,224)的图像。 The image is in grayscale, and I don't want consider the 2 extreme values 0 / 255 of the pixels intensity. 图像是灰度的,我不想考虑像素强度的2个极限值0/255。

I already have a loop in my script. 我的脚本中已经有一个循环。 I think that I have to add a line where I take off these pixels like this: 我认为我必须添加一条线来去除这些像素,如下所示:

for b in depth: #cicle already existing
    if b < 255 and b > 0:  #added line
        a = a+1
        if a <= 121 and a >= 118:
            for f in range(25, 223):
                #print((x+b)%33)
                soundArr[int((f-25)/6)] = soundArr[int((f-25)/6)]+b[f]

but I obtain the error: 但我得到了错误:

The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

So how do I delete those pixels? 那么如何删除这些像素?

If I understand the question correctly you can use numpy.where in order to find the indices of 0 and 255 in your depth image. 如果我正确理解了该问题,则可以使用numpy.where来在深度图像中找到索引0和255。 Then when you iterate over the image you can disregard the results from numpy.where. 然后,当您遍历图像时,可以忽略numpy.where中的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM