Hi, I have a RGBA image which I need to convert to Grayscale and then to binary with a threshold to get binary histogram but I have 2D Grayscale image in my code which I don't understand how to convert to binary.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# Import libraries from PIL import Image import matplotlib.pyplot as plt import numpy as np import cv2 # Reading an Image image = Image. open ( 'Board1_1.png' ) # Properties of an Image print (image.size) print (image. format ) print (image.mode) # Grayscale conversion image_gray = image.convert( 'LA' ) image_gray_array = 255 - np.asarray(image_gray) image_gray_array_1 = image_gray_array[:,:, 0 ] image_gray_array_2 = image_gray_array[:,:, 1 ] image_gray.show() |