程序是关于去除渐变背景色的 目前,尺寸为420X560的单个图像大约需要20秒 代码是
from colormath.color_objects import sRGBColor, LabColor
from colormath.color_conversions import convert_color
from colormath.color_diff import delta_e_cie2000
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
import numpy as np
import os
import cv2
def backgroundRemovel(url):
img = cv2.imread(url)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
plt.imshow(img)
plt.title('original Image')
plt.show()
color=img[0,0]
firstPixelRGB = sRGBColor(color[0], color[1], color[2], is_upscaled=True);
firstPixelLab = convert_color(firstPixelRGB, LabColor);
t=img.shape
x_dim=t[0]
y_dim=t[1]
for i in range(x_dim):
for j in range(y_dim):
rgbCurPixel=img[i,j]
curPixelRGB=sRGBColor(rgbCurPixel[0], rgbCurPixel[1], rgbCurPixel[2], is_upscaled=True);
curPixelLab=convert_color(curPixelRGB, LabColor);
delta_e = delta_e_cie2000(firstPixelLab, curPixelLab);
#print("difference is "+str(delta_e))
if delta_e<15:
img[i, j] = (0, 0, 0)
return img
fnmae="image.jpeg"
open_cv_image = backgroundRemovel(fname)
plt.imshow(open_cv_image)
plt.title('Background Removed Image')
plt.show()
如果有更好的方法来去除图像的渐变背景,请共享