導航:首頁 > 編程語言 > python求灰度均值

python求灰度均值

發布時間:2025-01-20 03:02:05

① '求助'python怎麼判斷圖片是否為灰度圖

這里判斷是否為灰度圖的標準是:每一個像素所對應的R、G、B的值是否相等。

def is_color_image(url):
im=Image.open(url)
pix=im.convert('RGB')
width=im.size[0]
height=im.size[1]
oimage_color_type="Grey Image"
is_color=[]
for x in range(width):
for y in range(height):
r,g,b=pix.getpixel((x,y))
r=int(r)
g=int(g)
b=int(b)
if (r==g) and (g==b):
pass
else:
oimage_color_type='Color Image'
return oimage_color_type

② 如何使用python來判斷圖片相似度

from PIL import Imageimport os#import hashlib def getGray(image_file): tmpls=[] for h in range(0, image_file.size[1]):#h for w in range(0, image_file.size[0]):#w tmpls.append( image_file.getpixel((w,h)) ) return tmpls def getAvg(ls):#獲取平均灰度值 return sum(ls)/len(ls) def getMH(a,b):#比較100個字元有幾個字元相同 dist = 0; for i in range(0,len(a)): if a[i]==b[i]: dist=dist+1 return dist def getImgHash(fne): image_file = Image.open(fne) # 打開 image_file=image_file.resize((12, 12))#重置圖片大小我12px X 12px image_file=image_file.convert("L")#轉256灰度圖 Grayls=getGray(image_file)#灰度集合 avg=getAvg(Grayls)#灰度平均值 bitls=''#接收獲取0或1 #除去變寬1px遍歷像素 for h in range(1, image_file.size[1]-1):#h for w in range(1, image_file.size[0]-1):#w if image_file.getpixel((w,h))>=avg:#像素的值比較平均值 大於記為1 小於記為0 bitls=bitls+'1' else: bitls=bitls+'0' return bitls''' m2 = hashlib.md5() m2.update(bitls) print m2.hexdigest(),bitls return m2.hexdigest()''' a=getImgHash("./Test/測試圖片.jpg")#圖片地址自行替換files = os.listdir("./Test")#圖片文件夾地址自行替換for file in files: b=getImgHash("./Test/"+str(file)) compare=getMH(a,b) print file,u'相似度',str(compare)+'%'

閱讀全文

與python求灰度均值相關的資料

熱點內容
世界上最快的動物是什麼app 瀏覽:889
一打開微信文件夾就卡 瀏覽:265
什麼軟體可以做指標源碼 瀏覽:464
java程序員飽和 瀏覽:149
路由器怎麼加密更安全 瀏覽:695
內存卡加密卡是什麼意思 瀏覽:695
幫別人做app需要注意什麼 瀏覽:668
android獲取string字元 瀏覽:181
python中的計數器 瀏覽:622
海地加密驅動安裝 瀏覽:844
慧凈電子12單片機開發板 瀏覽:940
什麼網段伺服器好 瀏覽:598
伺服器商店怎麼造 瀏覽:934
有什麼跳鬼步舞的app 瀏覽:250
倚天2如何自己搭建伺服器 瀏覽:553
我的世界如何讓伺服器刷神寵 瀏覽:624
為什麼程序員要盡量進大廠 瀏覽:3
phpfiletype 瀏覽:936
PHP用戶登錄管理系統源碼 瀏覽:199
你適合做程序員嗎 瀏覽:896