【python】去除图片高光

该博客介绍了一种基于像素聚类的实时高光去除方法,并提供了使用OpenCV进行图像修复的Python实现。通过查找并修复图片中的高光部分,可以改善图像质量,适用于图像处理和计算机视觉领域。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考:

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"))

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

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值