IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 人工智能 -> NLM_B-A non-local algorithm for image denoising分享 -> 正文阅读

[人工智能]NLM_B-A non-local algorithm for image denoising分享

论文名称:A non-local algorithm for image denoising

论文下载:https://www.researchgate.net/profile/Bartomeu-Coll/publication/4156453_A_non-local_algorithm_for_image_denoising/links/0f317534c2cac194e4000000/A-non-local-algorithm-for-image-denoising.pdfhttps://www.researchgate.net/profile/Bartomeu-Coll/publication/4156453_A_non-local_algorithm_for_image_denoising/links/0f317534c2cac194e4000000/A-non-local-algorithm-for-image-denoising.pdf

????????05年的论文,比较老的算法,但也比较有代表性。 论文比较好理解,就是认为图像内部有很多相似的块,只要进行块间相似性匹配,如果差异比较小,权重就比较大,差异比较大,权重就比较小,根据相似性进行加权平均,得到滤波后的结果。算法对均值为0的高斯噪声效果较好。由于好理解,就直接贴论文核心部分。

?

????????用欧式距离进行块间匹配,差异越小,权重越大,由于图像是有噪声的,所以即使没有噪声的两个块是完全一样的,由于噪声的存在,导致计算出的欧式距离不为0,其期望大概为2*σ2。所以最后在算权重时,需要多减去2*σ2。

?

参该网站上提供的代码,用Python重写了,运行速度很慢,用分辨率低的图做测试比较好。IPOL Journal · Non-Local Means Denoisinghttps://www.ipol.im/pub/art/2011/bcm_nlm/?

import cv2
import os
import numpy as np


def AddGaussNoise(img, sigma, mean=0):
    # 大概率abs(noise) < 3 * sigma
    noise = np.random.normal(mean, sigma, img.shape)
    img = img.astype(np.float)
    img = img + noise
    img = np.clip(img, 0, 255)
    img = img.astype(np.uint8)
    return img

def AddGaussNoiseGray(img, sigma, mean=0):
    lab = cv2.cvtColor(img, cv2.COLOR_BGR2Lab)
    noise = np.random.normal(mean, sigma, lab[:, :, 0].shape)
    lab = lab.astype(np.float)
    lab[:, :, 0] = lab[:, :, 0] + noise
    lab[:, :, 0] = np.clip(lab[:, :, 0], 0, 255)
    lab = lab.astype(np.uint8)
    img = cv2.cvtColor(lab, cv2.COLOR_Lab2BGR)
    return img

def GetMeandiff(patch1, patch2):
    # patch1 = patch1.astype(float)
    # patch2 = patch2.astype(float)
    diff = patch1 - patch2
    diff = diff.flatten()
    diff = diff * diff
    diffmean = diff.mean()
    return diffmean

def CalculateWeightLut(sigma, h):
    weightLut = np.zeros((256 * 256), np.float)
    sigma2 = sigma * sigma
    h2 = h * h
    for i in range(256 * 256):
        tmp = -max(i - 2 * sigma2, 0.0) / h2
        weightLut[i] = np.exp(tmp)
        if weightLut[i] < 0.0001:
            break
    return weightLut

def NonLocalMeansColor(image, sigma, h, templateWindowSize, searchWindow):
    height, width = image.shape[0], image.shape[1]
    patchWin = templateWindowSize // 2
    searchWin = searchWindow // 2

    # Padding the image
    padLength = patchWin + searchWin
    img = cv2.copyMakeBorder(image, padLength, padLength, padLength, padLength, cv2.BORDER_CONSTANT, value=255)

    img = img.astype(np.float)
    tmpSum = np.zeros((height + 2 * padLength, width + 2 * padLength, 3), np.float)
    count = np.zeros((height + 2 * padLength, width + 2 * padLength, 3), np.int)

    weightLut = CalculateWeightLut(sigma, h)

    for j in range(height):
        for i in range(width):
            padj = j + padLength
            padi = i + padLength
            centerPatch = img[padj - patchWin: padj + patchWin + 1, padi - patchWin: padi + patchWin + 1, :]
            # print(centerPatch.shape)
            sumWeight = 0
            templatePixel = np.zeros((templateWindowSize, templateWindowSize, 3), np.float)
            for r in range(padj - searchWin, padj + searchWin):
                for c in range(padi - searchWin, padi + searchWin):
                    otherPatch = img[r - patchWin: r + patchWin + 1, c - patchWin: c + patchWin + 1, :]
                    diff = GetMeandiff(centerPatch, otherPatch)
                    diff = (int)(diff)
                    curWeight = weightLut[diff]
                    sumWeight += curWeight
                    templatePixel += otherPatch * curWeight

            if sumWeight > 0.0001:
                tmpSum[padj - patchWin: padj + patchWin + 1, padi - patchWin: padi + patchWin + 1, :] += templatePixel / sumWeight
                count[padj - patchWin: padj + patchWin + 1, padi - patchWin: padi + patchWin + 1] += 1

    outImg = tmpSum[padLength:padLength + height, padLength:padLength + width, :]
    outCnt = count[padLength:padLength + height, padLength:padLength + width, :]

    mask = outCnt > 0
    outImg = outImg * mask + image * (1 - mask)

    outCnt = outCnt * mask + 1 - mask

    outImg = outImg / outCnt
    outImg = np.clip(outImg, 0, 255)
    outImg = outImg.astype(np.uint8)

    return outImg

if __name__ == '__main__':
    img = cv2.imread('test3.jpg', 1)

    # img = cv2.resize(img, (600, 750//2), interpolation=cv2.INTER_AREA)
    print(img.shape)
    noiseImg = AddGaussNoise(img, 20, 0)

    denoise = NonLocalMeansColor(noiseImg, 20, 8, 5, 15)

    cv2.imwrite('test_gauss_noise_color.jpg', noiseImg)
    cv2.imwrite('test_gauss_denoise_color.jpg', denoise)

    denoisecv = cv2.fastNlMeansDenoisingColored(noiseImg, None, 10, 10, 5, 15)
    cv2.imwrite('test_gauss_noise_colorcv.jpg', denoisecv)

代码里写的只能处理三通道的彩色图,处理灰度图的话,需要仿造写个函数。运行效果如下,sigma为20的高斯噪声。

噪声图像,sigma=20

去噪效果

fastNlMeansDenoisingColored运行的结果

可以看到,对高斯噪声,已知sigma的情况下,去噪效果还是比较好的,OpenCV自带的部分区域噪声没有去干净,可能和参数有关,他们用的是快速算法,参数也不一样,下次再研究一下。

  人工智能 最新文章
2022吴恩达机器学习课程——第二课(神经网
第十五章 规则学习
FixMatch: Simplifying Semi-Supervised Le
数据挖掘Java——Kmeans算法的实现
大脑皮层的分割方法
【翻译】GPT-3是如何工作的
论文笔记:TEACHTEXT: CrossModal Generaliz
python从零学(六)
详解Python 3.x 导入(import)
【答读者问27】backtrader不支持最新版本的
上一篇文章      下一篇文章      查看所有文章
加:2022-01-29 23:05:20  更:2022-01-29 23:05:59 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/19 8:50:08-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码