您好,登錄后才能下訂單哦!
這篇文章跟大家分析一下“如何實(shí)現(xiàn)Python中常用圖片處理函數(shù)的使用”。內(nèi)容詳細(xì)易懂,對(duì)“如何實(shí)現(xiàn)Python中常用圖片處理函數(shù)的使用”感興趣的朋友可以跟著小編的思路慢慢深入來(lái)閱讀一下,希望閱讀后能夠?qū)Υ蠹矣兴鶐椭?。下面跟著小編一起深入學(xué)習(xí)“如何實(shí)現(xiàn)Python中常用圖片處理函數(shù)的使用”的知識(shí)吧。
這個(gè)函數(shù)有兩個(gè)參數(shù)
1,src 要進(jìn)行變換的原圖像
2,code 轉(zhuǎn)換代碼標(biāo)識(shí)
例子:
import cv2 image=cv2.imread("ddd.jpg") image1=cv2.cvtColor(image,cv2.COLOR_BGR2BGRA) cv2.imshow("",image1) cv2.waitKey(0) if __name__ == '__main__': print()
例子:
import cv2 image=cv2.imread("ddd.jpg") # image1=cv2.cvtColor(image,cv2.COLOR_BGR2BGRA) r,g,b=cv2.split(image) cv2.imshow("r",r) cv2.imshow("g",g) cv2.imshow("b",b) cv2.waitKey(0) if __name__ == '__main__': print()
import cv2 image=cv2.imread("/home/dfy/Pictures/Camera_photo/Camera_photo/sss.jpg") # image1=cv2.cvtColor(image,cv2.COLOR_BGR2BGRA) r,g,b=cv2.split(image) cv2.imshow("r",r) cv2.imshow("g",g) cv2.imshow("b",b) image1=cv2.merge([b,g,r]) cv2.imshow("image",image1) cv2.waitKey(0) if __name__ == '__main__': print()
ret,image= cv2.threshold(src,thresh,maxval,type)
實(shí)現(xiàn)二值化的重要函數(shù)
參數(shù)說(shuō)明
src
輸入圖像
image
輸出圖像
thresh
閥值
maxval
當(dāng)像素值超過(guò)閥值thresh 時(shí)賦值為maxval
type
當(dāng)像素值小于閥值thresh的時(shí)賦值為type type可填下面5種類(lèi)型的參數(shù)
例子:
import cv2 image=cv2.imread("/home/dfy/Pictures/Camera_photo/Camera_photo/sss.jpg") # image1=cv2.cvtColor(image,cv2.COLOR_BGR2BGRA) # r,g,b=cv2.split(image) # cv2.imshow("",r) # cv2.imshow("",g) # cv2.imshow("",b) # image1=cv2.merge([b,g,r]) # cv2.imshow("image",image1) ret,image1=cv2.threshold(image,127,255,cv2.THRESH_BINARY) ret1,image2=cv2.threshold(image,127,255,cv2.THRESH_BINARY_INV) # ret2,image3=cv2.threshold(image,127,255,cv2.THRESH_TRIANGLE) ret3,image4=cv2.threshold(image,127,255,cv2.THRESH_TOZERO) ret4,image5=cv2.threshold(image,127,255,cv2.THRESH_TOZERO_INV) cv2.imshow("1",image1) cv2.imshow("2",image2) # cv2.imshow("3",image3) cv2.imshow("4",image4) cv2.imshow("5",image5) cv2.waitKey(0) if __name__ == '__main__': print()
import cv2 image=cv2.imread("/home/dfy/Pictures/Camera_photo/Camera_photo/sss.jpg") width,height,n=image.shape image2=image.copy() for i in range(width): for j in range(height): for channel in range(3): if image2[i][j][channel]>127: image2[i][j][channel]=255 else: image2[i][j][channel]=0 cv2.imshow('',image2) cv2.waitKey(0) if __name__ == '__main__': print()
這個(gè)速度很慢對(duì)于分辨率太高的圖
import cv2 image=cv2.imread("/home/dfy/Pictures/Camera_photo/Camera_photo/sss.jpg") image_color_map=cv2.applyColorMap(image,cv2.COLORMAP_JET) cv2.imshow("im",image_color_map) cv2.waitKey(0) if __name__ == '__main__': print()
關(guān)于如何實(shí)現(xiàn)Python中常用圖片處理函數(shù)的使用就分享到這里啦,希望上述內(nèi)容能夠讓大家有所提升。如果想要學(xué)習(xí)更多知識(shí),請(qǐng)大家多多留意小編的更新。謝謝大家關(guān)注一下億速云網(wǎng)站!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。