参考:

1.https://github.com/MarcioCerqueira/RealTimeSpecularHighlightRemoval

论文:Real-Time High-Quality Specular Highlight Removal using Efficient Pixel Clustering

2.图像增强:opencv去除图片的高光

import  cv2
import os,shutil
#找亮光位置
def create_mask(imgpath):
    image = cv2.imread(imgpath, cv2.IMREAD_GRAYSCALE)
    _, mask = cv2.threshold(image, 200, 255, cv2.THRESH_BINARY)
    return mask
#修复图片
def xiufu(imgpath,maskpath):
    src_ = cv2.imread(imgpath)
    mask = cv2.imread(maskpath, cv2.IMREAD_GRAYSCALE)
    #缩放因子(fx,fy)
    res_ = cv2.resize(src_,None,fx=0.6, fy=0.6, interpolation = cv2.INTER_CUBIC)
    mask = cv2.resize(mask,None,fx=0.6, fy=0.6, interpolation = cv2.INTER_CUBIC)
    dst = cv2.inpaint(res_, mask, 10, cv2.INPAINT_TELEA)
    return dst

if __name__=='__main__':
    rootpath = r"E:\data_set\img"
    masksavepath=r"E:\data_set\mask"
    savepath = r"E:\data_set\wcp\result"
    imgfiles = os.listdir(rootpath)
    for i in range(0, len(imgfiles)):
        path = os.path.join(rootpath, imgfiles[i])
        print(imgfiles[i])
        if os.path.isfile(path):
            if (imgfiles[i].endswith("jpg") or imgfiles[i].endswith("JPG")):
                maskpath =os.path.join(masksavepath, "mask_"+imgfiles[i])
                cv2.imwrite(maskpath, create_mask(path))
                dst=xiufu(path,maskpath)
                newname = 'xiufu_' + imgfiles[i].split(".")[0]
                cv2.imwrite(os.path.join(savepath, newname + ".jpg"), dst)
                shutil.copyfile(os.path.join(rootpath, imgfiles[i].split(".")[0] + ".xml"),
                                os.path.join(savepath, newname + ".xml"))

结果:
原图
在这里插入图片描述
处理后:
在这里插入图片描述

Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐