Raspberry Pi Computer Vision Programming by Ashwin Pajankar

Raspberry Pi Computer Vision Programming by Ashwin Pajankar

Author:Ashwin Pajankar
Language: eng
Format: epub
Publisher: Packt Publishing


The output will appear as follows:

Try passing various combination of the parameters to see how the resultant image changes. In the preceding example, parallelism between the lines is preserved because of the combination of the parameters we used. You might want to try different combinations of the parameters to see that the parallelism between the lines is not preserved.

Thresholding image

Thresholding is the simplest way to segment images. Although thresholding methods and algorithms are available for colored images, it works best on grayscale images. Thresholding usually (but not always) converts grayscale images into binary images (in a binary image, each pixel can only have one of two possible values: white or black). Thresholding the image is usually the first step in many image processing applications.

The way thresholding works is very simple. We define a threshold value. For a pixel in a grayscale image, if the value of grayscale intensity is greater than the threshold, we assign a value to the pixel (for example, white), else we assign a black value to the pixel. This is the simplest form of thresholding and there are many other variations of this method, which we will see now.

In OpenCV, the cv2.threshold() function is used to threshold images. It takes as input, grayscale image, threshold value, maxVal, and threshold method as parameters, and returns the thresholded image as output. The maxVal parameter is the value assigned to the pixel if the pixel intensity is greater (or less in some methods) than the threshold. There are five threshold methods available in OpenCV; in the beginning, the simplest form of thresholding we saw is cv2.THRESH_BINARY. Let's see the mathematical representation of all the threshold methods.

Say (x,y) is the input pixel; then, operations by threshold methods are as follows:

cv2.THRESH_BINARYIf intensity(x,y) > thresh, then set intensity(x,y) = maxVal; else set intensity(x,y) = 0.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.