image_func.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:Image-Processing-and-Steganogrphy 作者: motkeg 项目源码 文件源码
def Avg(img):
    R,G,B=0,0,0
    img=img.filter(ImageFilter.SMOOTH)
    pxls=img.load()

    N=img.size[0]*img.size[1]
    out_im =new("RGB", img.size, color = 1 )
    out_im2 =new("RGB", img.size, color = 1 )
    #img=cv2.bilateralFilter(np.array(pxls),9,75,75)


    print ("Calculate Avg..")
    for x in xrange (img.size[0]):
        for y in xrange(img.size[1]):
            R,G,B=R+pxls[x,y][0],G+pxls[x,y][1],B+pxls[x,y][2]

    R,G,B=R/N,G/N,B/N 
    for x in xrange (img.size[0]):
        for y in xrange(img.size[1]):
            tup=((pxls[x,y][0])/img.size[0],
                     (pxls[x,y][1])/img.size[0],
                     (pxls[x,y][2])/img.size[0])
            out_im.putpixel((x,y),tup)
            if((pxls[x,y][0]>R and  pxls[x,y][1]>G and pxls[x,y][2]>B)
                or (pxls[x,y][0]<R and  pxls[x,y][1]<G and pxls[x,y][2]<B)):
                out_im.putpixel((x,y),pxls[x,y])

    out_im.save('C:\Users\USER\workspace\Final Project\src\outputImage\OUTAVG.png')
    print ("Output Saved") 
    out_im.show()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号