python - 使用图像的局部平均颜色来减少闪电差异

标签 python opencv computer-vision

我是 opencv 的新手,目前正在研究“糖尿病视网膜病变检测”(kaggle 竞赛于 3 年前发起;更多详细信息请参见: https://www.kaggle.com/c/diabetic-retinopathy-detection/data )。目前,我正在尝试在图像处理上实现类似的结果,如下图所示(来源: http://blog.kaggle.com/2015/09/09/diabetic-retinopathy-winners-interview-1st-place-ben-graham/ ): enter image description here

现在我尝试了不同的方法,包括直方图均衡和对比度有限自适应直方图均衡(CLAHE)。 CLAHE 给出了迄今为止最好的结果,但与上面的图像相比没有任何结果。我从这里得到了一些想法:(How to remove the local average color from an image with OpenCV)但无法重现结果。如果有人可以指导我如何使用 opencv 或任何其他 python 视觉库来完成它,那就太好了。示例图像可以从 kaggle 网站(上面提到的链接)下载。谢谢。

这是迄今为止我的代码:

def equalize_hist(input_path):
    img = cv.imread(input_path)
    for c in range(0, 2):
        img[:,:,c] = cv.equalizeHist(img[:,:,c])

    cv.imshow('Histogram equalized', img)
    cv.waitKey(0)
    cv.destroyAllWindows()

def clahe_rgb(input_path):
    bgr = cv.imread(input_path)
    lab = cv.cvtColor(bgr, cv.COLOR_BGR2LAB)
    lab_planes = cv.split(lab)
    gridsize = 5
    clahe = cv.createCLAHE(clipLimit=2.0,tileGridSize=(gridsize,gridsize))
    lab_planes[0] = clahe.apply(lab_planes[0])
    lab = cv.merge(lab_planes)
    bgr2 = cv.cvtColor(lab, cv.COLOR_LAB2BGR)
    cv.imshow('CLAHE RGB', bgr2)
    cv.waitKey(0)
    cv.destroyAllWindows()


def clahe_greyscale(input_path):
    img = cv.imread(input_path)
    gray_image = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
    clahe = cv.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
    cl1 = clahe.apply(gray_image)    
    cv.imshow('CLAHE Grayscale', cl1)
    cv.waitKey(0)
    cv.destroyAllWindows()

最佳答案

您显示的代码正在执行局部直方图均衡,而您发布的突出显示的文本讨论的是从每个像素中删除平均颜色。

删除平均颜色可以这样完成:

# Blur the image
blurred = cv2.blur(img, ksize=(15, 15))

# Take the difference with the original image
# Weight with a factor of 4x to increase contrast
dst = cv2.addWeighted(img, 4, blurred, -4, 128)

您可以调整模糊代码的内核大小(大于 15)以找到适合您的用例的内容。

在执行此操作之前,您可能需要将图像缩小到常见尺寸,以获得可比较的结果(也如您引用的博客文章中所述)。

关于python - 使用图像的局部平均颜色来减少闪电差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53417926/

相关文章:

python - python中skimage的rgb2gray : AttributeError: Nonetype object has no attribute ndim

computer-vision - 什么是计算机视觉中的射影几何和交比?

c++ - 姿势优化的高斯牛顿实现错误

python - 如何写入另一个Python进程的STDIN?

python - int.__mul__ ,执行速度比 operator.mul 慢 2 倍

python - 我如何获得由 Pandas 数据框中的值表示的两个连接代码的聚合百分比

opencv - 如何分割书架图像中的单本书

给定分箱数据的python绘制简单直方图

python - 在 Pandas 库中转换Image数组以用于PCA

c++ - 使用opencv进行高斯平滑