<jupyter_start><jupyter_text>Simple Thresholding1. Threshold function is used.2. In the Parameters first image is taken the, 127 is the threshold value, 255 is the Max_value of Gray Scale , then type of the Thresholding.3. Made the list of Titles and images of all the types of thresholding.4. Using for loop and matplotlib library displayed the output images.<jupyter_code>img = cv2.imread('Simplethreshold.jpg',0)
ret,thresh1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY)
ret,thresh2 = cv2.threshold(img,127,255,cv2.THRESH_BINARY_INV)
ret,thresh3 = cv2.threshold(img,127,255,cv2.THRESH_TRUNC)
ret,thresh4 = cv2.threshold(img,127,255,cv2.THRESH_TOZERO)
ret,thresh5 = cv2.threshold(img,127,255,cv2.THRESH_TOZERO_INV)

titles = ['Original Image','BINARY','BINARY_INV','TRUNC','TOZERO','TOZERO_INV']
images = [img, thresh1, thresh2, thresh3, thresh4, thresh5]

for i in range(6):
    plt.subplot(2,3,i+1),plt.imshow(images[i],'gray')
    plt.title(titles[i])
    plt.xticks([]),plt.yticks([])

plt.show()<jupyter_output><empty_output><jupyter_text>Adaptive Thresholding1.  Using Threshold function first I have done Thresholding for comapring it with adaptive.2. Then AdaptiveThreshold fucntion is used for For Adaptive mean threshold and Adaptive Gaussian Threshold.2. In the Parameters first image is taken the,  255 is the Max_value of Gray Scale , then Adaptive Method,then type of the Thresholding.3. Made the list of Titles and images of all the types of thresholding.4. Using for loop and matplotlib library displayed the output images.<jupyter_code>img1 = cv2.imread('Adaptive.jpg',0)
img1 = cv2.medianBlur(img1,5)
ret,th1 = cv2.threshold(img1,127,255,cv2.THRESH_BINARY)
th2 = cv2.adaptiveThreshold(img1,255,cv2.ADAPTIVE_THRESH_MEAN_C,\
            cv2.THRESH_BINARY,11,2)
th3 = cv2.adaptiveThreshold(img1,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\
            cv2.THRESH_BINARY,11,2)
titles_1 = ['Original Image', 'Global Thresholding (v = 127)',
            'Adaptive Mean Thresholding', 'Adaptive Gaussian Thresholding']
images_1 = [img1, th1, th2, th3]
for i in range(4):
    plt.subplot(2,2,i+1),plt.imshow(images_1[i],'gray')
    plt.title(titles_1[i])
    plt.xticks([]),plt.yticks([])
plt.show()<jupyter_output><empty_output><jupyter_text>Otsu Thresholding<jupyter_code>img2 = cv2.imread('leaf.jpg',0)
 
ret, imgf = cv2.threshold(img2, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)
 
plt.subplot(1,3,1), plt.imshow(img2,cmap = 'gray')
plt.title('Original Leaf Image' ), plt.xticks([]), plt.yticks([])
plt.subplot(1,3,2), plt.hist(img2.ravel(), 256)
plt.axvline(x=ret, color='r', linestyle='dashed', linewidth=2)
plt.title('Histogram'), plt.xticks([]), plt.yticks([])
plt.subplot(1,3,3), plt.imshow(imgf,cmap = 'gray')
plt.title('Otsu thresholding'), plt.xticks([]), plt.yticks([])
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14149274849663954, 'fraction_numerical': 0.054474708171206226, 'mean_word_length': 6.123425692695214, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '436193', 'license': 'MIT', 'n_tokens_mistral': 1172, 'n_tokens_neox': 1100, 'n_words': 227, 'path': 'PragyaSingh_OpenCV_ImageThresholding.ipynb', 'repo_name': 'pragya376/Open-contributions', 'size': '2827'}