I would like to decrease brightness, contrast, and offset of the image in Python like photoshop. I enhance the bar code in that image. I want to make that barcode visible by editing that image.
import colorsys
def colorize(im, h, s, l_adjust):
h /= 360.0
s /= 100.0
l_adjust /= 100.0
if im.mode != 'L':
im = im.convert('L')
result = Image.new('RGB', im.size)
pixin = im.load()
pixout = result.load()
for y in range(im.size[1]):
for x in range(im.size[0]):
l = pixin[x, y] / 255.99
l += l_adjust
l = min(max(l, 0.0), 1.0)
r, g, b = colorsys.hls_to_rgb(h, l, s)
r, g, b = int(r * 255.99), int(g * 255.99), int(b * 255.99)
pixout[x, y] = (r, g, b)
return result```
import cv2
# Load image as greyscale
im = cv2.imread('XD04u.png', cv2.IMREAD_GRAYSCALE)
# Equalise and save
res = cv2.equalizeHist(im)
cv2.imwrite('result.png', res)
2
Answers
You can use histogram equalisation: