The code snippet in Python should convert the rgb image to black and white, but only a black image output. I do not know where the problem is (input and output image should be bmp)
from PIL import Image
import numpy as np
raw_img = Image.open(r"image adress")
img = raw_img.load()
x,y = raw_img.size
threshold = 300
bw_img = [[0]*y]*x # blank image
for i in range(x):
for j in range(y):
if img[i,j] < threshold:
bw_img[i][j] = 0
else:
bw_img[i][j] = 1
Image.fromarray(np.asarray(bw_img),mode="P").save("your_nwe_image.bmp")