In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article analyzes "how to implement the use of common image processing functions in Python". The content is detailed and easy to understand. Friends interested in "how to realize the use of common image processing functions in Python" can read it slowly and deeply with the idea of Xiaobian. I hope it can help everyone after reading. Let's learn how to use common image processing functions in Python together with Xiaobian.
cvtColor function
This function takes two parameters.
1, src Original image to be transformed
2, code conversion code identification
Examples:
import cv2image=cv2.imread("ddd.jpg")image1=cv2.cvtColor(image,cv2.COLOR_BGR2BGRA)cv2.imshow("",image1)cv2.waitKey(0)if __name__ == '__main__': print()split() and merge()
Examples:
import cv2image=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 cv2image=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()threshold()
ret,image= cv2.threshold(src,thresh,maxval,type)
An Important Function to Realize Binarization
parameter description
src Input image
image Output image
thresh
maxval is assigned maxval when the pixel value exceeds threshold thresh
type When the pixel value is less than the threshold value thresh, assign it to type. The following 5 types of parameters can be filled in.
Examples:
import cv2image=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() custom threshold function binarizes import cv2image= cv 2.imread ("/home/dfy/Pictures/Camera_photo/sss.jpg")width,height,n=image.shapeimage2=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]=0cv2.imshow('',image2)cv2.waitKey(0)if __name__ == '__main__': print()
It's slow for images that are too high resolution.
Chromaticity Function applyColorMapimport cv2image=cv2.imread("/home/dfy/Pictures/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() on how to implement the use of common image processing functions in Python to share here, I hope the above content can make everyone improve. If you want to learn more, please pay more attention to the updates of Xiaobian. Thank you for your attention to the website!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.