Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.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_Image_Image Processing_Pixel_Image Segmentation - Fatal编程技术网

Python 计算每行中的像素变化

Python 计算每行中的像素变化,python,image,image-processing,pixel,image-segmentation,Python,Image,Image Processing,Pixel,Image Segmentation,我想计算图像每一行的像素变化(这意味着从黑色到白色或从白色到黑色的任何变化), 如下图所示: 我写了这段代码,但第二部分错了: change = [0 for k in range(test.shape[0])] total = [] for x in range(test.shape[0]-1): change[x]=0 for y in range(test.shape[1]-1): if test[x,y+1] != test[x,y]:

我想计算图像每一行的像素变化(这意味着从黑色到白色或从白色到黑色的任何变化), 如下图所示:

我写了这段代码,但第二部分错了:

change = [0 for k in range(test.shape[0])]
total = []
for x in range(test.shape[0]-1):
    change[x]=0
    for y in range(test.shape[1]-1):
        if test[x,y+1] != test[x,y]:
            change[x] = change[x] + 1
        elif test[x+1,y+1] != test[x+1, y]:
                change[x] = change[x] + 1

    total.append(change[x])

要计算行上的更改,只需将每一个像素与同一行上的下一个像素进行比较

在代码中,只需删除
elif

change = [0 for k in range(test.shape[0])]  # changes per row
total = []
for x in range(test.shape[0]):  # each row
    change[x]=0   # not needed
    for y in range(test.shape[1]-1):  # each column
        if test[x,y+1] != test[x,y]:
            change[x] = change[x] + 1
    #    elif test[x+1,y+1] != test[x+1, y]:   # not needed
    #            change[x] = change[x] + 1     # not needed

    total.append(change[x])
您可以尝试使用Numpy:

out=np.sum(np.absolute(np.diff(np.double(img), axis=1))/255.0, axis=1)

你想获取每行的更改计数吗?@Mike67是的,没错,但是如果你检查照片,我的代码无法获取数字3的交叉点是的,我喜欢你所做的,但它无法检测数字3(如图所示)