Skip to content Skip to sidebar Skip to footer

Is There A Way To Reduce The White Pixels In An Inverted Image

I'm trying to reduce the number of pixels in an inverted image and I've tried using morphology but it doesn't help much. I'm trying to reduce the number of white in an image, but s

Solution 1:

Here is what I did. Let me know if this helps!

import cv2
from matplotlib import pyplot as plt
import numpy as np


im = cv2.imread('yAgTc.jpg') # read input image
im = cv2.resize(im, (1080 , 480)) # resize the image to 1080x480
height, width, channels = im.shape
gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY) # convert to grayscale

ret,plane = cv2.threshold(gray,5,255,cv2.THRESH_BINARY_INV)
contours, hierarchy =  cv2.findContours(plane,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)

im_contour = np.zeros((height,width))
cv2.drawContours(im_contour,contours,-1,255,3)

im_edge =cv2.Canny(gray,100,200)
im_final = im_contour + im_edge
ret,my_im = cv2.threshold(im_final,5,255,cv2.THRESH_BINARY)

plt.imshow(my_im,cmap=plt.cm.gray)
plt.show()

final image

Post a Comment for "Is There A Way To Reduce The White Pixels In An Inverted Image"