Ask Your Question
0

How can I increase contrast in binary picture?(python)

asked 2020-04-12 06:11:23 -0600

nesse98 gravatar image

updated 2020-04-12 07:14:13 -0600

I'm really new to opencv. This is my picture and as you can see the lines in the bottom left corner are faded. I tried threshholding and dilation but it deformed the lines. image description (edited) original pic:

image description

edit retag flag offensive close merge delete

Comments

Can you post original print circuit board?

supra56 gravatar imagesupra56 ( 2020-04-12 07:05:59 -0600 )edit
1

updated it

nesse98 gravatar imagenesse98 ( 2020-04-12 07:14:20 -0600 )edit
1

I got the green channel then reversed it

nesse98 gravatar imagenesse98 ( 2020-04-12 07:15:14 -0600 )edit

You took picture?

supra56 gravatar imagesupra56 ( 2020-04-12 07:26:15 -0600 )edit
1

No, its from the internet

nesse98 gravatar imagenesse98 ( 2020-04-12 07:38:18 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-04-12 08:54:45 -0600

supra56 gravatar image

Here is code:

#!/usr/bin/python37
#OpenCV 4.3.0, Raspberry pi 3B+/4B, Buster v10.
#Date: 12th April, 2020

import cv2 as cv
import numpy as np


img = cv.imread('printed_circuit4_.jpg')
gray= cv.cvtColor(img, cv.COLOR_BGR2GRAY)
blurred = cv.GaussianBlur(gray, (3, 3), 3)

adapt_thresh = cv.adaptiveThreshold(blurred, 255,
                                    cv.ADAPTIVE_THRESH_MEAN_C,
                                    cv.THRESH_BINARY_INV, 7, -2)


cv.imshow('Image', adapt_thresh)
cv.imwrite('contrast_board.jpg', adapt_thresh)
cv.waitKey(0)
cv.destroyAllWindows()

Output:

image description

Another one for printed circuit board:

#!/usr/bin/python37
#OpenCV 4.3.0, Raspberry pi 3B+/4B, Buster v10.
#Date: 12th April, 2020

import cv2

image = cv2.imread('printed_circuit4_.jpg')

alpha = 3.9 # Contrast control (1.0-3.0)
beta = 0 # Brightness control (0-100)

adjusted = cv2.convertScaleAbs(image, alpha=alpha, beta=beta)

cv2.imwrite('Contrast_board.jpg', adjusted)
cv2.imshow('Contrast Printed Circuit', adjusted)
cv2.waitKey(0)

Output:

image description

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-04-12 06:11:23 -0600

Seen: 2,673 times

Last updated: Apr 12 '20