Threshold segmentation and threshold implementation


Binary thresholding

First, select a specific threshold value, such as 127

The new threshold generation rule is:

The gray value of pixels greater than or equal to 127 is set to the maximum value (for example, the maximum 8-bit gray value is 255)

The gray value of pixels with gray value less than 127 is set to 0

Anti binary thresholding

This thresholding is similar to binary thresholding. First, a specific gray value is selected as the threshold. Take the 8-bit grayscale image as an example:

Greater than the threshold is set to 0

Less than this threshold is set to 255

Truncation thresholding

First, you need to select a threshold. The pixels larger than the threshold in the image are set as the threshold, and those smaller than the threshold remain unchanged. For example, the threshold value is 127

Thresholds less than 127 do not change

Pixels greater than or equal to 127 are set as the threshold 127

De thresholding to 0

First select a threshold, and then process the image as follows:

Pixels greater than or equal to the threshold become 0

Pixel values less than this threshold remain unchanged

Implementation of threshold image threshold

Function threshold

retval,dst = cv2.threshold(src, thresh, maxval, type)

Binary thresholding keyword: cv2.thresh_ BINARY

Anti binary thresholding keyword: cv2.thresh_ BINARY_ INV

Truncation thresholding keyword: cv2.thresh_ TRUNC

De thresholding to 0 keyword: cv2.thresh_ TOZERO_ INV

This work adoptsCC agreement, reprint must indicate the author and the link to this article


Recommended Today


Supervisor [note] Supervisor – H view supervisor command help Supervisorctl – H view supervisorctl command help Supervisorctl help view the action command of supervisorctl Supervisorctl help any action to view the use of this action 1. Introduction Supervisor is a process control system. Generally speaking, it can monitor your process. If the process exits abnormally, […]