skip to Main Content

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.

enter image description here

2

Answers


  1. Chosen as BEST ANSWER
    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```
    

  2. You can use histogram equalisation:

    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)
    

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search