MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / grayscale

Function grayscale

computer_vision/haralick_descriptors.py:74–85  ·  view source on GitHub ↗

Uses luminance weights to transform RGB channel to greyscale, by taking the dot product between the channel and the weights. Example: >>> grayscale(np.array([[[108, 201, 72], [255, 11, 127]], ... [[56, 56, 56], [128, 255, 107]]])) array([[

(image: np.ndarray)

Source from the content-addressed store, hash-verified

72
73
74def grayscale(image: np.ndarray) -> np.ndarray:
75 """
76 Uses luminance weights to transform RGB channel to greyscale, by
77 taking the dot product between the channel and the weights.
78
79 Example:
80 >>> grayscale(np.array([[[108, 201, 72], [255, 11, 127]],
81 ... [[56, 56, 56], [128, 255, 107]]]))
82 array([[158, 97],
83 [ 56, 200]], dtype=uint8)
84 """
85 return np.dot(image[:, :, 0:3], [0.299, 0.587, 0.114]).astype(np.uint8)
86
87
88def binarize(image: np.ndarray, threshold: float = 127.0) -> np.ndarray:

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected