基于卷积神经网络的图像去噪(基础篇)基于基础理论知识深度学习的图像去噪区别于传统去噪,但有一定的发展过程。 从浅层模型到深度模型,从含噪图像到去噪图像,也就是残差学习,通过学习发展过程,可以更好地把握现在流行的算法。 我个人建议本文的深度学习在图像去噪方面取得了什么进展卷积神经网络区别于其他神经网络。 如果不知道神经网络的工作原理,请查看此深度学习的神经网络细节,了解包含去噪图像映射的去噪图像(浅层网络模型),了解令人担忧的姐姐噪声图像(这里为40x40x1的灰色图像块大小可变),通过神经网络提取特征,计算原始无噪图像和损耗函数最简单的方法是1~3层网络。 这里使用9层楼的网络进行实验。 直接进入网络模型: defget _ CNN _9conv (model _ path=None ) :input_img=input ) shape=() ) None、none、 1 ) ) adaptthisifusing ` channels _ first ` imagedataformatx=conv 2d (56,(5,5 ),activation='relu ',padding 1) padding='same ' ) (x ) x=conv2d ) 12,(3,3 ),activation='relu ',padding='same ' ) (x ) x=conv2d ) 12,12 padding='same ' ) x ) x=Conv2D(28,padding='same ' ) (x ) decoded=Conv2D(1) 1,(5,5 ),activation=' ' padding='same ' ) x ) autoencoder=decoded ) auto encoder.com pile (optimizer=' SGD ',loss=' mean _ squ eared _ ed ) “mean_squared_error'](#print ) (autoencoder.summary ) ) # return autoencoder训练集使用200张图像并扩展数据集测试集使用Set12,加入标准偏差为25的加性高斯白噪声AWGN,客观评价标准使用峰值信噪比PSNR,比简单的三层网络效果好得多。
去除噪声后的psnr为29.10,噪声图像的psnr为20.56。 两张GPU大约需要一个小时左右。 (cpu不要想。 ) ) ) ) ) ) )。
第二,将去噪图像映射到包含噪声的图像(稀疏网络模型)同样,网络输入输出不变,共有12层,但只是网络层间的参数相互影响,效果并没有怎么提高,所以我也不太清楚直接上传代码:
defget _ gated _ connections (gatepercentagefactor, 输入层(: gate factor=input (tensor=k.variable ) [gatepercentagefactor] ) fractiong=lambda ) lambdax 3: x gax (complement=lambda ) lambdax:x[0]-x[1] ) [inputLayer,fractionG] )返回门因子, fractionG ) ) ),fractiongatefac complementdefget _ CNN _ architecture (weights _ path=none ) 3360 input _ img=1 ) adaptthisifusing ` channels _ first ` imagedataformatx1=conv 2d (64,(3,3 ),activation='relu ',padding=fg1
c2 = get_gated_connections(0.2, x2) x = MaxPooling2D((2, 2), padding='same')(fg2) #45 45 64 x3 = Conv2D(128, (3, 3), activation='relu', padding='same')(x)#45 45 128 gf3, fg3, c3 = get_gated_connections(0.3, x3) x = MaxPooling2D((2, 2), padding='same')(x3)#22.5 22.5 128 x4 = Conv2D(256, (3, 3), activation='relu', padding='same')(x)#22.5 22.5 256 gf4, fg4, c4 = get_gated_connections(0.4, x4) x = MaxPooling2D((2, 2), padding='same')(x4) x5 = Conv2D(512, (3, 3), activation='relu', padding='same')(x) gf5, fg5, c5 = get_gated_connections(0.5, x5) x = MaxPooling2D((2, 2), padding='same')(x5) x6 = Conv2D(1024, (3, 3), activation='relu', padding='same')(x) x = UpSampling2D((2, 2))(x6) y1 = Conv2DTranspose(512, (3, 3), activation='relu', padding='same')(x) jt4 = Add()([y1, c5]) x = UpSampling2D((2, 2))(jt4) y2 = Conv2DTranspose(256, (3, 3), activation='relu', padding='same')(x) jt3 = Add()([y2, c4]) x = UpSampling2D((2, 2))(jt3) y3 = Conv2DTranspose(128, (3, 3), activation='relu', padding='same')(x) jt2 = Add()([y3, c3]) x = UpSampling2D((2, 2))(jt2)#90 90 128 y4 = Conv2DTranspose(64, (3, 3), activation='relu', padding='same')(x)#90 90 64 jt1 = Add()([y4, c2]) x = UpSampling2D((2, 2))(jt1)#180 180 64 jt0 = Add()([x, c1]) y5 = Conv2DTranspose(64, (3, 3), activation='relu', padding='same')(jt0)#180 180 64 y6 = Conv2DTranspose(1, (3, 3), activation='relu', padding='same')(y5)#180 180 3 layers = y6 model = Model([input_img, gf1, gf2, gf3, gf4, gf5], layers) model.compile(optimizer='sgd', loss='mean_squared_error', metrics=['accuracy'])#编译 #model.summary() return model测试结果如下:
主观效果上就不是很好,这张图psnr为24.38 ,12张图平均psnr为25.13,噪声图像的psnr为20.56,可能是我代码跑的有问题。
这个网络模型借用的残差块的概念,将整个网络看成一个残差块,输入不变,输出的是噪声图像,将含噪图像减去噪声图像,从而得到去噪图像,效果超过传统方法,前面两个模型可以学学,DnCNNs需要深入研究。
模型代码如下,一共17层:
整个残差思想就体现在这一行代码上
x = Subtract(name='subtract' + str(layer_count))([inpt, x]) # input - noise效果如下:
最左边是原始图像,中间是加入噪声强度为25的含噪图像(也就是输入图像),最右边是去噪图像(也就是输出图像)。这张图psnr为29.82 ,12张图平均psnr为29.74,噪声图像的psnr为20.56。数值是用python代码测的,用MATLAB测会更高(懂得都懂)。如果是彩色图像的话,输入输出的通道数改为3就行。
因为代码都是从github上东拼西凑的,所以我把完整代码都上传到csdn上免费下载,代码下载链接在这,里面包括数据集,代码,还有训练好的模型参数(对应部分不同噪声强度,没有全部),可以直接用(代码运行环境要对),当然我也建议大家直接去github上找代码。
总的来说,初学者还是要循序渐进,一定要把网络的输入输出搞懂,要先明白网络要干什么,再去弄懂网络是怎么做到的,会更好学习一点。
`