Reputation: 55
As the title says I'm trying to turn all the white parts in my grayscaled photo to black. I tried using this code right here
img_file = os.path.join(img_dir, os.listdir(img_dir)[1])
img = Image.open(img_file).convert('L')
npImage = np.array(img)
LUT = np.zeros(256, dtype=np.uint8)
LUT[255] = 0
img = Image.fromarray(LUT[npImage])
img.show()
but my output is a purely black image.
Upvotes: 1
Views: 43
Reputation: 480
LUT is an array of all 0s and 0's will display as black. What you want to do is create a for loop to access all of the values in npImage, and if necessary change to black.
LUT = np.zeros(256, dtype=np.uint8)
creates an array of 0's of length 256
LUT[255] = 0
sets the 256th element in LUT to 0
Upvotes: 1