程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python handles some column operations of pictures

編輯:Python

cvtColor function

This function has two arguments

1,src The original image to be transformed

2,code Conversion code identification

Example :

import cv2
image=cv2.imread("ddd.jpg")
image1=cv2.cvtColor(image,cv2.COLOR_BGR2BGRA)
cv2.imshow("",image1)
cv2.waitKey(0)
if __name__ == '__main__':
print()

split() and merge()

Example :

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

threshold() function

ret,image= cv2.threshold(src,thresh,maxval,type)

An important function to realize binarization

Parameter description

src The input image

image Output image

thresh threshold

maxval When the pixel value exceeds the threshold thresh When is assigned as maxval

type When the pixel value is less than the threshold value thresh The value of is type type Fill in the following 5 Two types of parameters

Example :

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

Customize threshold Binarization of functions

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

It's very slow. For images with too high resolution

Chroma function applyColorMap

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

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved