【图像修复】基于滤波实现损坏图像修复含Matlab源码

1 简介

图像在获取,传输和存储的过程中由于各种原因引起图像质量的下降,需要对图像进行复原.本文对图像复原技术,高斯噪声,椒盐噪声进行介绍,探讨二维中值滤波算法和MATLAB下算法的仿真实验,同时分析实验结果,最后得出结论.

2 完整代码

clc; clear all;%First part%reading img1, saving as im1 variableim1 = imread('img1.jpg');%for boundary it's a must to convert to grayim1 = rgb2gray(im1);subplot(331), imshow(im1), title('Img1 convert to gray');% as a mask all colors will be white or blackmask = im1 < 255;subplot(332), imshow(mask), title('Apply a mask');%invert colors, otherwise the boundary sees nearly%the whole image, need to swap colorsmask = imcomplement(mask);subplot(333), imshow(mask), title('Invert colors');%gives location x y coordinates where is the first area, %it starts there too%if don't have ; at the end, it shows the dimensions of %the imagedim = size(mask)col = round(dim(2)/2)-90;row = min(find(mask(:,col)))%an interesting drawback, if I would fill the "holes"%with erode function which is better then imfill, the%program can't see any of the boundaries, hence in the%for loop I had to use 180 rounds, otherwise can't see%the big parts.%erode image% se = strel('line',10, 90);% boundaries = imerode(mask,se);% imshow(boundaries);%use bwtraceboundary function to find the boundary from%the above declared point.%it needs a binary image, row and col coordinates for start%and direction, W for west so left.boundary = bwtraceboundary(mask,[row, col],'W');subplot(334), imshow(im1), title('Boundaries');hold on;plot(boundary(:,2),boundary(:,2),'g','LineWidth',4);%the imfill fills the smaller objects. However, as I %mentioned above the erode function does better job.%Unfortunately, with that result the for loop cannot%find any boundaries, despite the imshow(mask)black&white%image looks better.BW_filled = imfill(mask,'holes');boundaries = bwboundaries(BW_filled);%shows the border of all white part, with the imfill%function the for loop must iterate 180 times, hilarious.%Under 180 it doesn't find the last top right big white%object.for k=1:180   b = boundaries{k};   plot(b(:,2),b(:,1),'g','LineWidth',4);end%Second part%denoise test; averaging or median filterim2 = imread('Penguins.jpg');im2 = imresize(im2, [768, 1024]);rgbImage = im2;subplot(335), imshow(rgbImage), title('Resized but noisy Img2');%averaging filtermat = ones(5,5)/25;averagingFilter_im2 = imfilter(rgbImage, mat);subplot(336), imshow(averagingFilter_im2), title('Img2 averaging filter');%median filterfor k=1:3medianFilter_im2(:,:,k)=medfilt2(rgbImage(:,:,k),[3,3]);endsubplot(337), imshow(medianFilter_im2), title('Img2 median filter');%Third partim1 = imread('img1.jpg');recoveredImage = im1;recoveredImageMedianFilter = im1;zero = recoveredImage == 255;recoveredImage(zero) = averagingFilter_im2(zero);zero1 = recoveredImageMedianFilter == 255;recoveredImage(zero1) = averagingFilter_im2(zero1);recoveredImageMedianFilter(zero1) = medianFilter_im2(zero);subplot(338), imshow(recoveredImage), title('Recovered image with averaging filter');subplot(339), imshow(recoveredImageMedianFilter), title('Recovered image with median filter');%Compare recoveredImage and originalImageoriginalImage = imread('Penguins.jpg');%Writes out in command windowmeanRecoveredIm = mean(recoveredImage(:))meanOriginalIm = mean(originalImage(:))%It coutns the Structural Similarity Index (SSIM) value%for original and recovered image.ssimValue = ssim(originalImage, recoveredImage)%It counts the Peak Signal to Noise Ratio value%for original and recovered image. They must be the same%class and size as well.peaks2NoiseRatio = psnr(originalImage, recoveredImage)%It counts the Mean Squared Error (MSE) between arrays%of the 2 declared variable, currently the original and the recovered image.meanSquaredErr = immse(originalImage, recoveredImage)%write out image as a fileimwrite(recoveredImage, 'recoveverdImage.jpg');

3 仿真结果

4 参考文献

[1]肖锦龙. 基于MATLAB二维中值滤波的图像复原[J]. 现代计算机, 2021.

博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。

部分理论引用网络文献,若有侵权联系博主删除。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

matlab科研助手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值