How to use the mahotas.thresholding function in mahotas

To help you get started, we’ve selected a few mahotas examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Sardhendu / License-Plate-Detection / SVM / c_pre_processing.py View on Github external
def perform_HOG(image_orig):
    hog= a_HOG_computation.HOG(orientations=18, pixelsPerCell=(9,9), cellsPerBlock=(3,3), visualise=True, normalize=True) 
    #print file
    

    # Convert the coloured image into grayscale image
    image_resized=imutils.resize(image_orig, width=300)
    image_gray=cv2.cvtColor(image_resized, cv2.COLOR_BGR2GRAY)

    # Do thresholding
    image_thresh=image_gray
    T=mahotas.thresholding.otsu(image_gray) # will find an optimal value of T from the image
    image_thresh[image_thresh>T]=255 # This goes pixel by pixel if the pixel value of the thresh is greater than the optimal value then the color is white
    image_thresh[image_thresh
github Sardhendu / License-Plate-Detection / Licenceplate_identification / Logistic_regression / c_pre_processing.py View on Github external
def perform_HOG(image_orig):
    hog= a_HOG_computation.HOG(orientations=9, pixelsPerCell=(6,6), cellsPerBlock=(1,1), visualise=True, normalize=True) 
    #print file
    

    # Convert the coloured image into grayscale image
    image_resized=imutils.resize(image_orig, width=300)
    image_gray=cv2.cvtColor(image_resized, cv2.COLOR_BGR2GRAY)

    # Do thresholding
    image_thresh=image_gray
    T=mahotas.thresholding.otsu(image_gray) # will find an optimal value of T from the image
    image_thresh[image_thresh>T]=255 # This goes pixel by pixel if the pixel value of the thresh is greater than the optimal value then the color is white
    image_thresh[image_thresh
github jameschen00 / PracticalPythonAndOpenCV_Book / Chapter09 / otsu_and_riddler.py View on Github external
import mahotas
import cv2


# Load the image, convert it to greyscale, and blur it slightly
image = cv2.imread('C:/PythonProjects/PracticalPythonAndOpenCV_Book/images/coins.png')
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(image, (5, 5), 0)
cv2.imshow("Image", image)

# Otsu Thresholding (assumes that are two 'peaks' in the greyscale histogram and uses them to compute a threshold
t = mahotas.thresholding.otsu(blurred)
print("Otsu's threshold: {}".format(t))

# Otsu Thresholding (using NumPy)
thresh = image.copy()
thresh[thresh > t] = 255
thresh[thresh < 255] = 0
thresh = cv2.bitwise_not(thresh)
cv2.imshow("Otsu", thresh)

# Riddler-Calvard Thresholding
t = mahotas.thresholding.rc(blurred)
print("Riddler-Calvard: {}".format(t))
thresh = image.copy()
thresh[thresh > t] = 255
thresh[thresh < 255] = 0
thresh = cv2.bitwise_not(thresh)
github VAUTPL / Number_Detection / detect_numbers_images.py View on Github external
# loop over the contours
for (c, _) in cnts:
	# compute the bounding box for the rectangle
	(x, y, w, h) = cv2.boundingRect(c)

	# if the width is at least 7 pixels and the height
	# is at least 20 pixels, the contour is likely a digit
	if w >= 7 and h >= 28:
        
		# crop the ROI and then threshold the grayscale
		# ROI to reveal the digit
        # apply filer
		roi = gray[y:y + h, x:x + w]
		thresh = roi.copy()
		T = mahotas.thresholding.otsu(roi)
		thresh[thresh > T] = 255
		thresh = cv2.bitwise_not(thresh)

		# deskew the image center its extent
		thresh = dataset.deskew(thresh, 20)
		thresh = dataset.center_extent(thresh, (20, 20))

		cv2.imshow("thresh", thresh)

		# extract features from the image and classify it
		hist = hog.describe(thresh)
		digit = model.predict(hist)[0]
		print "Creo que el numero es: %d" % (digit)
    
		# draw a rectangle around the digit, the show what the
		# digit was classified as
github Sardhendu / License-Plate-Detection / Plate-Detection / hist_features_HOG.py View on Github external
def create_histogram_for_image(image):
    hog= HOG_computation.HOG(orientations=18, pixelsPerCell=(10,10), cellsPerBlock=(3,3), normalize=True)

    # Convert the coloured image into grayscale image
    image_resized=imutils.resize(image, width=300)
    image_gray=cv2.cvtColor(image_resized, cv2.COLOR_BGR2GRAY)

    # Do thresholding
    image_thresh=image_gray
    T=mahotas.thresholding.otsu(image_gray) # will find an optimal value of T from the image
    image_thresh[image_thresh>T]=255 # This goes pixel by pixel if the pixel value of the thresh is greater than the optimal value then the color is white
    image_thresh[image_thresh
github VAUTPL / Number_Detection / detect_numbers_images.py View on Github external
cnts = sorted([(c, cv2.boundingRect(c)[0]) for c in cnts], key = lambda x: x[1])

# loop over the contours
for (c, _) in cnts:
    # compute the bounding box for the rectangle
    (x, y, w, h) = cv2.boundingRect(c)
        
        # if the width is at least 7 pixels and the height
        # is at least 20 pixels, the contour is likely a digit
    if w >= 7 and h >= 28:
        
            # crop the ROI and then threshold the grayscale
            # ROI to reveal the digit
            roi = gray[y:y + h, x:x + w]
            thresh = roi.copy()
            T = mahotas.thresholding.otsu(roi)
            thresh[thresh > T] = 255
            thresh = cv2.bitwise_not(thresh)
                
                # deskew the image center its extent
            thresh = dataset.deskew(thresh, 20)
            thresh = dataset.center_extent(thresh, (20, 20))
                
            cv2.imshow("thresh", thresh)
            #grayROI = msk.applymask(roi, RoadMSK)
            # extract features from the image and classify it
            hist = hog.describe(thresh)
            digit = model.predict(hist)[0]
            print "Creo que el numero es: %d" % (digit)
            
                # draw a rectangle around the digit, the show what the
                # digit was classified as
github hsSam / PracticalPythonAndOpenCV_CaseStudies / Chapter06 / classify.py View on Github external
(_, contours, _) = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

# Sort the contours by their x-axis position, ensuring that we read the numbers from left to right
contours = sorted([(c, cv2.boundingRect(c)[0]) for c in contours], key=lambda x: x[1])

# Loop over the contours
for (contour, _) in contours:
	# Compute the bounding box for the rectangle
	(x, y, w, h) = cv2.boundingRect(contour)

	# If the width is at least 7 pixels and the height is at least 20 pixels, the contour is likely a digit
	if w >= 7 and h >= 20:
		# Crop the ROI and then threshold the greyscale ROI to reveal the digit
		roi = gray[y:y + h, x:x + w]
		thresh = roi.copy()
		t = mahotas.thresholding.otsu(roi)
		thresh[thresh > t] = 255
		thresh = cv2.bitwise_not(thresh)

		# De-skew the image center its extent
		thresh = dataset.de_skew(thresh, 20)
		thresh = dataset.center_extent(thresh, (20, 20))

		cv2.imshow("thresh", thresh)

		# Extract features from the image and classify it
		hist = hog.describe(thresh)
		digit = model.predict([hist])[0]
		print("Prediction: {}".format(digit))

		# Draw a rectangle around the digit, the show what the digit was classified as
		cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 1)
github VAUTPL / Number_Detection / detect_numbers_webcam.py View on Github external
# loop over the contours
for (c, _) in cnts:
    # compute the bounding box for the rectangle
    (x, y, w, h) = cv2.boundingRect(c)

    # if the width is at least 7 pixels and the height
    # is at least 20 pixels, the contour is likely a digit
    if w >= 7 and h >= 28:
        
        # crop the ROI and then threshold the grayscale
        # ROI to reveal the digit
        # apply filer
        roi = gray[y:y + h, x:x + w]
        thresh = roi.copy()
        T = mahotas.thresholding.otsu(roi)
        thresh[thresh > T] = 255
        thresh = cv2.bitwise_not(thresh)
        
        # deskew the image center its extent
        thresh = dataset.deskew(thresh, 20)
        thresh = dataset.center_extent(thresh, (20, 20))
                
        cv2.imshow("thresh", thresh)
        
        # extract features from the image and classify it
        hist = hog.describe(thresh)
        digit = model.predict(hist)[0]
        print "Creo que el numero es: %d" % (digit)
        numeros.append(digit)
        
        # draw a rectangle around the digit, the show what the
github jameschen00 / PracticalPythonAndOpenCV_Book / Chapter09 / otsu_and_riddler.py View on Github external
blurred = cv2.GaussianBlur(image, (5, 5), 0)
cv2.imshow("Image", image)

# Otsu Thresholding (assumes that are two 'peaks' in the greyscale histogram and uses them to compute a threshold
t = mahotas.thresholding.otsu(blurred)
print("Otsu's threshold: {}".format(t))

# Otsu Thresholding (using NumPy)
thresh = image.copy()
thresh[thresh > t] = 255
thresh[thresh < 255] = 0
thresh = cv2.bitwise_not(thresh)
cv2.imshow("Otsu", thresh)

# Riddler-Calvard Thresholding
t = mahotas.thresholding.rc(blurred)
print("Riddler-Calvard: {}".format(t))
thresh = image.copy()
thresh[thresh > t] = 255
thresh[thresh < 255] = 0
thresh = cv2.bitwise_not(thresh)
cv2.imshow("Riddler-Calvard", thresh)
cv2.waitKey(0)