Converting RGBA image to Gray scale and then binary

I have used the argument ‘LA’ and get the gray scale image which I plotted. I don’t know why only ‘L’ does not work as I get dark image.

image_gray = image.convert('LA')

The gray scale image has two dimension i.e., two matrix (row x col x 2). I can plot it, it looks like a gray scale image. Now I need to binarize it with threshold and plot a histogram. I know the theory but could not find the which function in python can convert gray scale image to binary and then make its histogram.

I have tried this function
'(thresh, im_bw) = cv2.threshold(image_gray, 128, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)

I get this error

cv2.error: OpenCV(4.5.3) :-1: error: (-5:Bad argument) in function ‘threshold’
Overload resolution failed:

  • src is not a numpy array, neither a scalar
  • Expected Ptrcv::UMat for argument ‘src’