I am new to computer version, I am trying to remove the background of the image given and make it white background. I have tried most of the codes shared here but non is working on my image.
input:
desired output:
I am new to computer version, I am trying to remove the background of the image given and make it white background. I have tried most of the codes shared here but non is working on my image.
input:
desired output:
Chanda Steven wrote:
I am new to computer version, I am trying to remove the background of the image given and make it white background.
If that is all you want to do, then the following is a simple way to do that in Python/OpenCV/Numpy.
(But your desired result looks like an inverted result. So I am not sure what you want.)
If making the background white is all you want. Then convert the input to gray. Copy the input and use Numpy to change the background to white where gray is close to black.
Input:
import cv2
import numpy as np
# read image
img = cv2.imread("a_blob.jpg")
# convert img to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# change black to white
result = img.copy()
result[gray<=2] = (255,255,255)
# write results to disk
cv2.imwrite("a_blob_white.jpg", result)
# show results
cv2.imshow("RESULT", result)
cv2.waitKey(0)
Result:
If you remove background you not have your desider output.
The object in the image have a different processing, similar negative, but isn't negative.
If it was negative you got this result :
From output image it's very difficult understand what operations have been carried out.