Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.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 Processing - Fatal编程技术网

需要帮助比较Python中的两张图片吗

需要帮助比较Python中的两张图片吗,python,image-processing,Python,Image Processing,嘿,伙计们,我正在为我的计算机科学课做作业,我不知道我哪里出了问题。该函数应拍摄两张照片,即pic1和pic2,并返回它们的不同程度 这是我的 def smart_difference(pic1, pic2): '''Given two Pictures, pic1 and pic2 of any size and colour, return the difference''' red = red_average(pic2) blue = blue_avera

嘿,伙计们,我正在为我的计算机科学课做作业,我不知道我哪里出了问题。该函数应拍摄两张照片,即pic1和pic2,并返回它们的不同程度

这是我的

def smart_difference(pic1, pic2):
    '''Given two Pictures, pic1 and pic2 of any size and colour, return the 
    difference'''
    red = red_average(pic2)
    blue = blue_average(pic2)
    green = green_average(pic2)

    pic1_height, pic1_width = media.get_height(pic1), media.get_width(pic1)
    pic2_height, pic2_width = media.get_height(pic2), media.get_width(pic2)
    if (pic1_height > pic2_height) and (pic1_width > pic2_width): 
        new_pic1 = media.create_picture(pic2_width, pic2_height)
        new_pic2 = pic2
    elif (pic1_height > pic2_height) and (pic2_width > pic1_width):
        new_pic1 = media.create_picture(pic2_width, pic1_height)
        new_pic2 = media.create_picture(pic2_width, pic1_height)
    elif (pic2_height > pic1_height) and (pic2_width > pic1_width):
        new_pic1 = pic1
        new_pic2 = media.create_picture(pic1_width, pic1_height)
    elif (pic2_height > pic1_height) and (pic1_width > pic2_width):
        new_pic1 = media.create_picture(pic2_width, pic1_height)
        new_pic2 = media.create_picture(pic2_width, pic1_height)

    scale_red(new_pic1, red)
    scale_blue(new_pic1, blue)
    scale_green(new_pic1, green)
    scale_red(new_pic2, red)
    scale_blue(new_pic2, blue)
    scale_green(new_pic2, green)
    return simple_difference(new_pic1, new_pic2)
我运行了一个自测文件,它是我们分配给我们的,但我一直在这里得到一个错误,有人能帮忙吗


*注意:Simple_difference是我之前编写的另一个函数,它查找两张图片中像素之间的距离并相应缩放,错误是:AssertError:smart_difference后的结果应该在0到1200之间,而不是35000

以下是我为简单的差异所做的:

def简单区别概念1,图2: '给定两张尺寸相同的图片,即pic1和pic2,返回 两幅图片的彩色距离总和。”

sum_distance = 0
for pix1, pix2 in zip(pic1, pic2):
    sum_distance += distance(pix1, pix2)
return sum_distance

我正在使用一个媒体库,我们的类必须使用它,运行Python2.5。。。这有点荒谬,但这就是我们必须使用的

告诉我们错误是什么,如果你需要帮助,你如何量化差异?你得到了什么错误?你在使用什么库?看起来不像PIL…我想他使用的是PyGraphics 2.0。可能相关:我如何量化两幅图像之间的差异