Created
August 2, 2019 19:16
-
-
Save acharles7/aaf48ae9a969d20fcd1efb131bd314cc to your computer and use it in GitHub Desktop.
The pixel values falling below or above that threshold can be classified accordingly as an object or the background is known as Threshold Segmentation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from skimage.color import rgb2gray | |
import matplotlib.pyplot as plt | |
img = plt.imread('cat.jpg') | |
gray = rgb2gray(img) | |
gray_r = gray.reshape(gray.shape[0]*gray.shape[1]) | |
global_threshold = gray_r.mean() | |
for i in range(gray_r.shape[0]): | |
if gray_r[i] > global_threshold: | |
gray_r[i] = 1 | |
else: | |
gray_r[i] = 0 | |
gray = gray_r.reshape(gray.shape[0], gray.shape[1]) | |
plt.imshow(gray, cmap='gray') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment