-
-
Save XTechnology-TR/c7f4139b802cfec4e57d9766c3d1a195 to your computer and use it in GitHub Desktop.
Read the car image and convert it to binary
This file contains 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.io import imread | |
from skimage.filters import threshold_otsu | |
import matplotlib.pyplot as plt | |
car_image = imread("car.jpg", as_gray=True) | |
# it should be a 2 dimensional array | |
print(car_image.shape) | |
# the next line is not compulsory however, a grey scale pixel | |
# in skimage ranges between 0 & 1. multiplying it with 255 | |
# will make it range between 0 & 255 (something we can relate better with | |
gray_car_image = car_image * 255 | |
fig, (ax1, ax2) = plt.subplots(1, 2) | |
ax1.imshow(gray_car_image, cmap="gray") | |
threshold_value = threshold_otsu(gray_car_image) | |
binary_car_image = gray_car_image > threshold_value | |
ax2.imshow(binary_car_image, cmap="gray") | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment