简体   繁体   English

在python中使用pyFITS计算图像的平均值

[英]Calculating the mean of an image with pyFITS in Python

i am trying to make a QR for random text, blur it with ImageFilter then find the undestorted image' mean and take this away from the distorted image' mean. 我正在尝试为随机文本制作QR​​,使用ImageFilter对其进行模糊处理,然后找到未失真图像的均值,并将其从失真图像的均值中移除。

i found pyFITS but i'm confused as to how it works to gather the image data, here is my code: 我找到了pyFITS,但是我对它如何收集图像数据感到困惑,这是我的代码:

def show_image1(filename):
     IM=Image.open(filename)
     IM.show()

    QR = "HIDUGHEDG[REJG[ERWJGFERWJ[GJREJGE[RJ[]]]]]"


if __name__ == "__main__":
    myqr = qrcode.make(QR)
    #myqr.show()
    myqr.save("myqr4.png") 



file1 = 'myqr4.png'

ima = pyfits.getdata('myqr4.jpg')

#blurred  = ndimage.gaussian_filter(file1, sigma=3)



im = Image.open('myqr4.png')
im2 = im.convert('RGBA')
im3 = im2.filter(ImageFilter.BLUR)
scipy.misc.imsave('blurred.jpg', im3)
im_blur = Image.open('blurred.jpg')
im_blur.show()

im = pyfits.getdata('blurred.jpg')

print ima - im

also ideally i would like to blur the image using 也是理想情况下,我想使用

#blurred  = ndimage.gaussian_filter(file1, sigma=3)

but it says 'undefined name 'ndimage' even though i have imported it with import scipy.ndimage 但是即使我已经使用import scipy.ndimage导入了它,但它却显示了'undefined name'ndimage'

but anyway i would then like to put 但无论如何,我然后想放

sigma = x

then loop the value of x (sigma) between 1 and 5, then display the mean values of each distorted image, is this possible? 然后将x(西格玛)的值在1到5之间循环,然后显示每个失真图像的平均值,这可能吗?

thanks for any help on any part of this. 感谢您对此方面的任何帮助。

Just you want to calculate the mean value of an image means, use scipy library with python. 只要您要计算图像均值的平均值,请将scipy库与python一起使用。 Sample code:- 示例代码:-

from scipy import misc
image_name = 'Birds.jpg'
calc_mean = misc.imread(image_name)
print calc_mean.mean()

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

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