问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

python照片对比大概多久(Python 图片对比)

发布网友 发布时间:2024-09-25 19:48

我来回答

1个回答

热心网友 时间:2024-10-04 10:58

本篇文章给大家谈谈python照片对比大概多久,以及Python 图片对比对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

1、python 不同时间拍摄的图片如何对比差异2、python如何进行图像比对3、学会python大概要多久?4、.py文件用jupyter打开运行图片需要多长时间5、使用Python 制作对比图片相似度的程序python 不同时间拍摄的图片如何对比差异

比较不同

使用PIL(Pillow library)库

安装 pip install pillow,然后直接用其中的ImageChops函数

from PIL import Imagefrom PIL import ImageChops

def compare_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)

? ?if diff.getbbox() is None: ? ? ? ?# 图片间没有任何不同则直接退出

? ? ? ?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 制作对比图片相似度的程序

import media

def red_average(pic):

'''Return an integer that represents the average red of the picture.

'''

total=0

for pixel in pic:

total = total + media.get_red(pixel)

red_average = total / (media.get_width(pic)*media.get_height(pic))

return red_average

def green_average(pic):

'''Return an integer that represents the average green of the picture

'''

total = 0

for pixel in pic:

total = total + media.get_green(pixel)

green_average = total / (media.get_width(pic)*media.get_height(pic))

return green_average

def blue_average(pic):

'''Return an integer that represents the average blue of the picture

'''

total = 0

for pixel in pic:

total = total + media.get_blue(pixel)

blue_average = total / (media.get_width(pic)*media.get_height(pic))

return blue_average

def scale_red(pic, value):

'''Return the picture that the average of the red is value which has been set.

'''

averaged = red_average(pic)

factor = float(value) / averaged

for pixel in pic:

new_red = min(255, int(factor * media.get_red(pixel)))

media.set_red(pixel,new_red)

return pic

def scale_green(pic, value):

'''Return the picture that the average of the green is value which has been set.

'''

averaged = green_average(pic)

factor = float(value) / averaged

for pixel in pic:

new_green = min(255, int(factor * media.get_green(pixel)))

media.set_green(pixel,new_green)

return pic

def scale_blue(pic, value):

'''Return the picture that the average of the blue is value which has been set.

'''

averaged = blue_average(pic)

factor = float(value) / averaged

for pixel in pic:

new_blue = min(255, int(factor * media.get_blue(pixel)))

media.set_blue(pixel,new_blue)

return pic

def expand_height(pic, factor):

'''Return a newpicture that has been vertically stretched by the factor which has been set.

'''

new_width = pic.get_width()

new_height = pic.get_height()*factor

newpic = media.create_pic(new_width, new_height, media.black)

for pixel in pic:

x = media.get_x(pixel)

y = media.get_y(pixel)

newpixel = media.get_pixel(newpic, x, y*factor)

for newpixel in newpic:

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)

return newpic

def expand_width(pic,factor):

'''Return a newpicture that has been horizontally stretched by the factor which has been set.

'''

new_width = pic.get_width() * factor

new_height = pic.get_height()

newpic = media.create_pic(new_width,new_height,media.black)

for newpixel in newpic:

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)

return newpic

def reduce_height(pic, factor):

'''return a new pic that has been compressed vertically by the factor which has been set

'''

# Create a new, all-black pic with the appropriate new height and

# old width; (all colour components are zero).

new_width = pic.get_width

new_height = (pic.get_height() - 1) / factor + 1

newpic = media.create_pic(new_width, new_height, media.black)

# Iterate through all the pixels in the original (large) image, and copy

# a portion of each pixel's colour components into the correct

# pixel position in the smaller image.

for pixel in pic:

# Find the corresponding pixel in the new pic.

x = media.get_x(pixel)

y = media.get_y(pixel)

newpixel = media.get_pixel(newpic, x, y / factor)

# Add the appropriate fraction of this pixel's colour components

# to the components of the corresponding pixel in the new pic.

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)

return newpic

def reduce_width(pic,factor):

'''Return a newpic that has been horizontally compressed by the factor which has been set.

'''

new_width = (media.get_width() - 1) / factor + 1

new_height = media.get_height()

newpic = media.create_pic(new_width, new_height, media.black)

for pixel in pic:

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)

return newpic

def distance(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)

return sum

def simple_difference(pic1, pic2):

for pixel in pic1:

x = media.get_x(pixel)

y = media.get_y(pixel)

pixel2 = media.get_pixel(pic2, x, y)

sum = media.distance(pixel, pixel2)

return sum

def smart_difference(pic1,pic2):

height1 = media.get_height(pic1)

height2 = media.get_height(pic2)

factorh = float(height1 / height2)

if factorh = 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)

if factorw = 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照片对比大概多久的信息别忘了在本站进行查找喔。

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
清明节扫墓要注意哪些事项? 宿根草本类 是哪些 草本花卉和宿根花卉的区别是什么? 草本花卉和宿根花卉有什么区别? 《没人告诉我.没人理解我》是哪首歌的歌词 ? 王叔要用两辆车运水果,每次每辆车装满,一辆车是2吨,一辆车是3吨... 13吨货物怎样运输合适呢 ...一辆3t运费200元。13t水果怎样合理安排,运费最少? ...2吨,每辆运费140元,大卡车限重3吨.每辆车运费200 有13吨钢材!载重量2吨的卡车、每次的运费是140员、载重量3吨的卡车每次... Python办公自动化pandas库基础--使用loc,iloc读取Excel综合案例_百度... PyTorch学习笔记——repeat()和expand()区别 芭芭农场种红包能得现金吗? ...拉不出来,后来又梦见一条无头的大蛇向我吐毒液,不让我过路,_百度知... 颞骨与侧颅底手术解剖图谱内容简介 颞骨高分辨力CT作者简介 颞骨解剖及手术径路内容简介 文件无法移动,提示请确定磁盘未满或未被写保护并未被使用,怎么办?怎么... ...6、9、12…第四行4、8、12、16…排成的一个数阵的一部分,_百度... 下面是一个数阵的一部分,算一算,数“110"出现了多少次 ...凸透镜成像的规律”实验中,蜡烛经凸透镜成像的情况与什么有关... HP scanjet 7650详细参数 【新车百问】长安CS75PLUS 首保应该做哪些内容? 长安汽车首保必须三个月内? 长安汽车首保都有哪些项目 长安汽车首保都有哪些项目? 珍妮为什么没把病传染给阿甘 为什么珍妮不接受阿甘的表白? 有人说阿甘正传中珍妮的了艾滋病,但是为什么又和阿甘发生了关系_百度知 ... amd锐龙R5和i5哪个好? 浏览器报错:Cannotreadpropertiesofundefined(reading'pageIndex... 住房公积金贷款 最多多少钱 公积金存款1万3,每月缴纳420,想买第2套房... 觉醒年代哪个电视台播出 觉醒年代什么电视台播出 打印机脱机怎么回事儿怎么解决 觉醒年代电视剧播出时间 周公解梦梦见自己在水中游泳还看见大轮船,梦见别人游泳是什么预兆 手机打印机脱机是什么原因? 十二生肖里属蛇女对应的是什么星座 24×62的竖式计算? 镜头24-70是什么意思? 索尼2470镜头适合拍什么 高考振臂高呼文案 2462的竖式怎么列 62×24列竖式计算? 旅游带24-70够用吗_旅游拍摄需要用什么镜头 祝朋友高考顺利的文案 高考顺利的文案 2.4X6.2的过程怎么写 股票QQ群收费骗人怎么举报啊,这个骗子网名叫股婴 不是别人提醒我还没... yy五项是什么意 怎么查中考报名号和身份证号?