当前位置:网站首页>Image denoising using nlmeas
Image denoising using nlmeas
2022-07-18 12:07:00 【Yingtai night snow】
Use nlmeas Denoise the image
Effect display

Code implementation
# Use nlmeans Methods the image was denoised
import cv2
import numpy as np
import matplotlib.pyplot as plt
import skimage
from skimage import data,img_as_float
from skimage.restoration import denoise_nl_means,estimate_sigma
from skimage.metrics import peak_signal_noise_ratio
from skimage.util import random_noise
# Use skimage It's from Ku nlmeans The algorithm operates
def nlmeansSkimage(src):
# Load the picture first
img=skimage.io.imread(src)
img=skimage.img_as_float(img)
# Artificially add noise to the picture , You can delete
sigma=0.08
noisy=random_noise(img,var=sigma**2)
# Estimate the standard deviation of the noise in the current input picture
sigma_est=np.mean(estimate_sigma(noisy,channel_axis=-1))
print(f'the estimate Image noise is{
sigma_est}')
# take pathch Some attributes of the block are fixed
patch_kw=dict(
patch_size=5,
patch_distance=6,
channel_axis=-1
)
#denoise_nl_means(image, patch_size=7, patch_distance=11, h=0.1, multichannel=False, fast_mode=True, sigma=0.0,, preserve_range=False, channel_axis=None)
#image= The denoised image to be input , It can be a grayscale image , Can also make rgb chart
#patch_size: For denoising patch Size
#patch_distance: Search for patch Maximum pixel distance
#h: Cut off distance ,h The higher the value , Accept patch The higher the degree of freedom , At the same time, the smoother the image , But the boundary will also become blurred . For standard deviation sigma Gaussian noise of , Experience is better than sigma Less valuable
#multichannel/channel_axis: Specifies whether the input image is multichannel , If not specified, it defaults to grayscale
#fastmode: Specify whether to use nlmeans Fast version of
#sigma: Standard deviation of Gaussian noise , If provided, calculate pach The weight will take into account the expected noise variance
#preserve_range: Whether to keep the range of original values , otherwise , It's like Korean dramas img_as_float Rule transformation input u Image
denoiseNlmeans=denoise_nl_means(noisy,h=1.15*sigma_est,fast_mode=False,**patch_kw)
# Provide predictions sigma Estimated value
denoiseNlmeansSigma=denoise_nl_means(noisy,h=0.8*sigma_est,sigma=sigma_est,
fast_mode=False,**patch_kw)
# Use fast nlmeans Method
denoiseNlmeansFast=denoise_nl_means(noisy,h=0.8*sigma_est,
fast_mode=True,**patch_kw)
# Use fast nlmeans And combine sigma_est
denoiseNlmeansFastSigma=denoise_nl_means(noisy,h=0.8*sigma_est,sigma=sigma_est,
fast_mode=True,**patch_kw)
# Of the calculated image PSNR
psnr_noisy=peak_signal_noise_ratio(img,noisy)
psnr_denoiseNlmeans=peak_signal_noise_ratio(img,denoiseNlmeans)
psnr_denoiseNlmeansSigma=peak_signal_noise_ratio(img,denoiseNlmeansSigma)
psnr_denoiseNlmeansFast=peak_signal_noise_ratio(img,denoiseNlmeansFast)
psnr_denoiseNlmeansFastSigma=peak_signal_noise_ratio(img,denoiseNlmeansFastSigma)
# Draw the output image
fig,ax=plt.subplots(nrows=2, ncols=3, figsize=(8,6),
sharex=True,sharey=True)
ax[0,0].imshow(noisy)
ax[0,0].axis('off')
ax[0,0].set_title(f'noisy Image\nPSNR={
psnr_noisy}')
ax[0, 1].imshow(denoiseNlmeans)
ax[0, 1].axis('off')
ax[0, 1].set_title(f'non-local means\n(slow,PSNR={
psnr_denoiseNlmeans})')
ax[0, 2].imshow(denoiseNlmeansSigma)
ax[0, 2].axis('off')
ax[0, 2].set_title('non-local means\n(slow,using $\\sigma_{est}$)'+f'PSNR={
psnr_denoiseNlmeansSigma}')
ax[1, 0].imshow(img)
ax[1, 0].axis('off')
ax[1, 0].set_title('Original Image')
ax[1, 1].imshow(denoiseNlmeansFast)
ax[1, 1].axis('off')
ax[1, 1].set_title(f'non-local means\n(fast)PSNR={
psnr_denoiseNlmeansFast}')
ax[1, 2].imshow(denoiseNlmeansFastSigma)
ax[1, 2].axis('off')
ax[1, 2].set_title('non-local means\n(fast,using $\\sigma_{est}$)'+f'PSNR={
psnr_denoiseNlmeansFastSigma}')
fig.tight_layout()
plt.show()
边栏推荐
猜你喜欢

Redis五种常用数据类型有哪些?对应的数据存储空间又是怎样的?带你从零开始学习

解决 : ReferenceError: PubSub is not defined

Power BI----到底什么是度量值?

. Miniapi of net7 (special article):preview6 caching and stream limiting

限制ASML给中国供应光刻机?其实它已经离不开中国市场了

UE4_ Ue5 play audio (play, stop function) (attached project)

【LSTM回归预测】基于matlab TPA-LSTM时间注意力机制长短期记忆神经网络回归预测(多输入单输出)【含Matlab源码 1984期】

Database system probability -- relational database

How to use jedis to operate redis database?

MySQL JSON field query
随机推荐
The sandbox alpha Season 3 first Trailer
JVM简介
传统健身房困于规模化,乐刻运动“S2B2C”模式成参考答案?
screenWidth、clientWidth、offsetWidth、 scrollWidth的区别
包含数字的字符串剔除字母根据步长递增
UE5简单的角色碰撞检测功能
Surpass traditional giants and take the top place in the list of senior engineers! What does this local enterprise rely on?
Power BI----DAX讲解
Typescript learning summary
openEuler 知:日志查找技巧
Résolution du format d'image
Analysis of websocket hijacking
Overview of database system -- overview of data model
[Yolo] v5s version 6.1 loadstreams class source code interpretation
. Miniapi of net7 (special article):preview6 caching and stream limiting
社区峰会|Pulsar Summit 旧金山峰会议题亮点曝光!
TMUX usage
【转载】LaTeX中的空格汇总
【鸡汤】天下事有难易乎
Bank case | ZABBIX cross version upgrade guide, isn't 4.2-6.0 popular?