Tag: color block trunc Val Part container target set truncate
Cv2.threshold introduced, as shown, each number represents the size of its own grayscale value
The Cv2.threshod receives 5 kinds of parameter forms, namely Cv2.thresh_binary,cv2. Thresh_binary_inv,cv2. Thresh_trunc, Cv2. Thresh_tozero,cv2. Thresh_tozero_inv
(1) Thresh_binary (BINARY thresholding)
# binary Threshold, the original image, and the value of the pixel remains the same, otherwise 0. That is, the portion greater than the threshold becomes the maximum pixel value, and the part that is less than the threshold becomes 0if src (x, y) > thresh = maxValueElse = 0
(2) THRESH_BINARY_INV (Inverse BINARY thresholding)
# Inverse Binary Threshold, the original image of the threshold value, the value of the pixel is 0, otherwise remains unchanged. In contrast to (1), the portion greater than the threshold becomes 0, and the portion that is less than the threshold becomes the maximum pixel value if src (x, y) > thresh = 0Else = MaxValue
(3) Thresh_trunc (Truncate thresholding)
# Truncate Threshold, the original image pixel, the threshold value, which is equal to the threshold value, otherwise remains unchanged. That is, turn all pixels into a threshold below the horizontal if src (x, y) > thresh = threshElse = src (x, y)
(4) Thresh_tozero (Threshold to Zero)
# Threshold to Zero if src (x, y) > thresh= src (x, y)else = 0
(5) THRESH_TOZERO_INV (inverted Threshold to Zero)
# inverted Threshold to Zero if src (x, y) > thresh = 0Else = src (x, y)
For example, the Python code is:
" "OpenCV Threshold Example Copyright by Satya Mallick <[email protected]>" "#Import OpenCVImportCv2#Read Imagesrc = cv2.imread ("Threshold.png", Cv2. Imread_grayscale); #Basic Threhold Exampleth, dst = cv2.threshold (src, 0, 255, Cv2. Thresh_binary); Cv2.imwrite ("opencv-threshold-example.jpg", DST); #thresholding with MaxValue set toth, dst = cv2.threshold (src, 0, 128, Cv2. Thresh_binary); Cv2.imwrite ("opencv-thresh-binary-maxval.jpg", DST); #thresholding with threshold value set 127th, DST = Cv2.threshold (src,127,255, Cv2. Thresh_binary); Cv2.imwrite ("opencv-thresh-binary.jpg", DST); #thresholding using THRESH_BINARY_INVth, DST = Cv2.threshold (src,127,255, Cv2. THRESH_BINARY_INV); Cv2.imwrite ("opencv-thresh-binary-inv.jpg", DST); #thresholding using Thresh_truncth, DST = Cv2.threshold (src,127,255, Cv2. THRESH_TRUNC); Cv2.imwrite ("opencv-thresh-trunc.jpg", DST); #thresholding using Thresh_tozeroth, DST = Cv2.threshold (src,127,255, Cv2. Thresh_tozero); Cv2.imwrite ("opencv-thresh-tozero.jpg", DST); #thresholding using THRESH_TOZERO_INVth, DST = Cv2.threshold (src,127,255, Cv2. THRESH_TOZERO_INV); Cv2.imwrite ("opencv-thresh-to-zero-inv.jpg", DST);
Result diagram:
(1) (2) (3)
(4) (5)
Reference connection:
http://www.learnopencv.com/opencv-threshold-python-cpp/
Http://docs.opencv.org/trunk/d7/d4d/tutorial_py_thresholding.html
Python image processing