发布网友 发布时间:2024-09-17 09:10
共1个回答
热心网友 时间:2024-10-01 08:39
本篇文章给大家谈谈python照片对比大概多久,以及Python图片对比对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:1、python不同时间拍摄的图片如何对比差异2、python如何进行图像比对3、学会python大概要多久?4、.py文件用jupyter打开运行图片需要多长时间5、使用Python制作对比图片相似度的程序python不同时间拍摄的图片如何对比差异比较不同
使用PIL(Pillowlibrary)库
安装pipinstallpillow,然后直接用其中的ImageChops函数
fromPILimportImagefromPILimportImageChops
defcompare_images(path_one,path_two,diff_save_location):
??"""
??比较图片,如果有不同则生成展示不同的图片
??@参数一:path_one:第一张图片的路径
??@参数二:path_two:第二张图片的路径
??@参数三:diff_save_location:不同图的保存路径
??"""
??image_one=Image.open(path_one)
??image_two=Image.open(path_two)
??diff=ImageChops.difference(image_one,image_two)
??ifdiff.getbbox()isNone:????#图片间没有任何不同则直接退出
????return
??else:
????diff.save(diff_save_location)
if__name__=='__main__':
??compare_images('/path/to/瀑布.jpg',?????????'/path/to/瀑布改.jpg',?????????'/path/to/不同.jpg')
结果,底部的不同被显示出来了
python如何进行图像比对
import?Image
import?ImageChops
im1?=?Image.open('1.jpg')
im2?=?Image.open('2.jpg')
diff?=?ImageChops.difference(im1,?im2).getbbox()
print?a?+?b?+?'is:?'?+?str(diff)
学会python大概要多久?一周或者一个月。
如果完全靠自己自学,又是从零基础开始学习Python的情况下,按照每个人的学习和理解能力的不同,我认为大致上需要半年到一年半左右的时间。
当然了,Python学习起来还是比较简单的,如果有其他编程语言经验,入门Python还是非常快的,花1-2个月左右的时间学完基础,就可以自己编写一些小的程序练练手了,5-6个月的时间就可以上手做项目了。
从一定程度上来说,一些零基础的初学者想要利用两个月的时间掌握好Python是不太可能的,学习完Python后想要应聘相对应的工作岗位,即便是选择最快的学习方式也是很难实现的,无法快速实现就业。
.py文件用jupyter打开运行图片需要多长时间30秒到40秒左右,但是有时候程序打不开。
jupyter程序的文件是。ipynb格式,如果要引用。py文件时,首先是要导入,可以通过下面方法,如有一个pythonDemo。py文件,想使用这个文件中的函数,需要使用,importpythonDemopython文件是当作一个模块,import文件名,就是导入该模块。
如果修改了。py文件,通过上面importpythonDemo是无法对修改的内容生效,这时需要重新装载模块,方法如下:fromimpimportreload,reload(pythonDemo)。
使用Python制作对比图片相似度的程序importmedia
defred_average(pic):
'''Returnanintegerthatrepresentstheaverageredofthepicture.
'''
total=0
forpixelinpic:
total=total+media.get_red(pixel)
red_average=total/(media.get_width(pic)*media.get_height(pic))
returnred_average
defgreen_average(pic):
'''Returnanintegerthatrepresentstheaveragegreenofthepicture
'''
total=0
forpixelinpic:
total=total+media.get_green(pixel)
green_average=total/(media.get_width(pic)*media.get_height(pic))
returngreen_average
defblue_average(pic):
'''Returnanintegerthatrepresentstheaverageblueofthepicture
'''
total=0
forpixelinpic:
total=total+media.get_blue(pixel)
blue_average=total/(media.get_width(pic)*media.get_height(pic))
returnblue_average
defscale_red(pic,value):
'''Returnthepicturethattheaverageoftheredisvaluewhichhasbeenset.
'''
averaged=red_average(pic)
factor=float(value)/averaged
forpixelinpic:
new_red=min(255,int(factor*media.get_red(pixel)))
media.set_red(pixel,new_red)
returnpic
defscale_green(pic,value):
'''Returnthepicturethattheaverageofthegreenisvaluewhichhasbeenset.
'''
averaged=green_average(pic)
factor=float(value)/averaged
forpixelinpic:
new_green=min(255,int(factor*media.get_green(pixel)))
media.set_green(pixel,new_green)
returnpic
defscale_blue(pic,value):
'''Returnthepicturethattheaverageoftheblueisvaluewhichhasbeenset.
'''
averaged=blue_average(pic)
factor=float(value)/averaged
forpixelinpic:
new_blue=min(255,int(factor*media.get_blue(pixel)))
media.set_blue(pixel,new_blue)
returnpic
defexpand_height(pic,factor):
'''Returnanewpicturethathasbeenverticallystretchedbythefactorwhichhasbeenset.
'''
new_width=pic.get_width()
new_height=pic.get_height()*factor
newpic=media.create_pic(new_width,new_height,media.black)
forpixelinpic:
x=media.get_x(pixel)
y=media.get_y(pixel)
newpixel=media.get_pixel(newpic,x,y*factor)
fornewpixelinnewpic:
new_red=media.get_red(pixel)
new_green=media.get_green(pixel)
new_blue=media.get_blue(pixel)
media.set_red(newpixel,new_red)
media.set_green(newpixel,new_green)
media.set_blue(newpixel,new_blue)
returnnewpic
defexpand_width(pic,factor):
'''Returnanewpicturethathasbeenhorizontallystretchedbythefactorwhichhasbeenset.
'''
new_width=pic.get_width()*factor
new_height=pic.get_height()
newpic=media.create_pic(new_width,new_height,media.black)
fornewpixelinnewpic:
x=media.get_x(newpixel)
y=media.get_y(newpixel)
pixel=media.get_pixel(pic,x/factor,y)
new_red=media.get_red(pixel)
new_green=media.get_green(pixel)
new_blue=media.get_blue(pixel)
media.set_red(newpixel,new_red)
media.set_green(newpixel,new_green)
media.set_blue(newpixel,new_blue)
returnnewpic
defreduce_height(pic,factor):
'''returnanewpicthathasbeencompressedverticallybythefactorwhichhasbeenset
'''
#Createanew,all-blackpicwiththeappropriatenewheightand
#oldwidth;(allcolourcomponentsarezero).
new_width=pic.get_width
new_height=(pic.get_height()-1)/factor+1
newpic=media.create_pic(new_width,new_height,media.black)
#Iteratethroughallthepixelsintheoriginal(large)image,andcopy
#aportionofeachpixel'scolourcomponentsintothecorrect
#pixelpositioninthesmallerimage.
forpixelinpic:
#Findthecorrespondingpixelinthenewpic.
x=media.get_x(pixel)
y=media.get_y(pixel)
newpixel=media.get_pixel(newpic,x,y/factor)
#Addtheappropriatefractionofthispixel'scolourcomponents
#tothecomponentsofthecorrespondingpixelinthenewpic.
new_red=newpixel.get_red()+pixel.get_red()/factor
new_green=newpixel.get_green()+pixel.get_green()/factor
new_blue=newpixel.get_blue()+pixel.get_blue()/fctor
media.set_red(newpixel,new_red)
media.set_green(newpixel,new_green)
media.set_blue(newpixel,new_blue)
returnnewpic
defreduce_width(pic,factor):
'''Returnanewpicthathasbeenhorizontallycompressedbythefactorwhichhasbeenset.
'''
new_width=(media.get_width()-1)/factor+1
new_height=media.get_height()
newpic=media.create_pic(new_width,new_height,media.black)
forpixelinpic:
x=media.get_x(pixel)
y=media.get_y(pixel)
new_pixel=media.get_pixel(newpic,x/factor,y)
new_red=newpixel.get_red()+pixel.get_red()/factor
new_green=newpixel.get_green()+pixel.get()/factor
new_blue=newpixel.get_blue()+pixel.get()/factor
media.set_red(newpixel,new_red)
media.set_green(newpixel,new_green)
media.set_blue(newpixel,new_blue)
returnnewpic
defdistance(pixel1,pixel2):
red1=media.get_red(pixel1)
green1=media.get_green(pixel1)
blue1=media.get_blue(pixel1)
red2=media.get_red(pixel2)
green2=media.get_green(pixel2)
blue2=media.get_blue(pixel2)
sum=abs(red1-red2)+abs(green1-green2)+abs(blue1-blu2)
returnsum
defsimple_difference(pic1,pic2):
forpixelinpic1:
x=media.get_x(pixel)
y=media.get_y(pixel)
pixel2=media.get_pixel(pic2,x,y)
sum=media.distance(pixel,pixel2)
returnsum
defsmart_difference(pic1,pic2):
height1=media.get_height(pic1)
height2=media.get_height(pic2)
factorh=float(height1/height2)
iffactorh=1:
height1=media.reduce_height(pic1,factorh)
else:
height2=media.reduce_height(pic2,1/factorh)
width1=media.get_width(pic1)
width2=media.get_width(pic2)
factorw=float(width1/width2)
iffactorw=1:
width1=reduce_width(pic1,factorw)
else:
width2=reduce_width(pic2,1/factorw)
red1=red_average(pic1)
green1=green_average(pic1)
blue1=blue_average(pic1)
red2=media.scale_red(pic2,red1)
green2=media.scale_green(pic2,green1)
blue2=media.scale_blue(pic2,blue1)
#if__name__=='__main__':
#media.show(newpic)
python照片对比大概多久的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于Python图片对比、python照片对比大概多久的信息别忘了在本站进行查找喔。