How to use Python to change negatives with one button
This article is about how to use Python to change negatives with one click. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Preface
Knowledge points:
1. Image processing.
2.OpenCV
3.numpy
Basic knowledge of 4.python
Environment:
Windows
Pycharm
Python3
Steps
Pour into the library
Import numpy as npimport cv2
Change the name if you install it directly at the command prompt
Pip install OpenCV-python
Image import
Img = cv2.imread ('timg.jpg')
Scalin
Rows,cols,channels = img.shapeprint (rows,cols,channels) img = cv2.resize (img,None,fx=0.5,fy=0.5) rows,cols,channels = img.shapeprint (rows,cols,channels)
Display and process the content of the image
Convert an image to a binary image
Cv2.imshow ('img',img) hsv = cv2.cvtColor (img,cv2.COLOR_BGR2HSV) cv2.imshow (' hsv',hsv) lower_blue = np.array upper_blue = np.array ([110255255])
Binarization function
Mask = cv2.inRange (hsv,lower_blue,upper_blue) cv2.imshow ('Mask',mask)
Corrosion
Erosion = cv2.erode (mask,None,iterations=1) cv2.imshow ('erosion',erosion)
Expansion
Dilation = cv2.dilate (mask, None,iterations=1) cv2.imshow ('dilation',dilation)
For i in range (rows): for j in range (cols): if dilation [iMagnej] = = 25525: img [iMagnej] = (0mem0255) # rgb (255Lot0) BGR () cv2.imshow ('res',img)
Save
Cv2.imwrite ('ting.png',img) cv2.waitKey (0) # 0 infinitely waiting for cv2.destroyAllWindows () # destroy all windows thank you for reading! This is the end of this article on "how to use Python to change negatives with one click". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!