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)
| 72 | |
| 73 | |
| 74 | def 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 | |
| 88 | def binarize(image: np.ndarray, threshold: float = 127.0) -> np.ndarray: |
no outgoing calls
no test coverage detected