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代码问题可私信交流。

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

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

  1. 【钟表识别】基于计算机视觉实现钟表时间识别含Matlab源码

    1 简介 基于计算机视觉实现钟表时间识别含Matlab源码​ 2 部分代码 function [time_clock]= read(filepath) I = imread(filepath); [e ...

  2. 【细胞分割】中值滤波+分水岭法细胞计数【含Matlab源码 640期】

    ⛄一.图像分割简介 理论知识参考:[基础教程]基于matlab图像处理图像分割[含Matlab源码 191期] ⛄二.部分源代码 clear; close all; %---------------- ...

  3. 【图像去噪】基于matlab快速跨尺度小波降噪泊松损坏图像去噪【含Matlab源码 1893期】

    ⛄一.图像去噪及滤波简介 1 图像去噪 1.1 图像噪声定义 噪声是干扰图像视觉效果的重要因素,图像去噪是指减少图像中噪声的过程.噪声分类有三种:加性噪声,乘性噪声和量化噪声.我们用f(x,y)表示图 ...

  4. 【图像计数】基于计算机视觉实现蚊香片计数含Matlab源码

    1 简介 基于计算机视觉实现蚊香片计数​ 2 部分代码 clc;%清除命令窗口中的内容close all;%关闭所有的figure窗口clear all;%清楚工作空间所有的变量.函数等I=imrea ...

  5. 【图像检测】基于计算机视觉实现米粒个数检测含Matlab源码

    1 简介 2 部分代码 function varargout = mygui(varargin)​​% Begin initialization code - DO NOT EDITgui_Singl ...

  6. 【瑕疵检测】基于matlab GUI Gabor滤波布匹瑕疵检测【含Matlab源码 407期】

    ⛄一.Gabor滤波布匹瑕疵检测简介 1 Gabor滤波器 2 Gabor函数结合代码分析: ⛄二.部分源代码 function varargout = bupi(varargin) % BUPI M ...

  7. 【目标定位】基于matlab粒子滤波的定位算法【含Matlab源码 2161期】

    一.基于粒子滤波污染源定位简介 粒子滤波定位算法是目前最精准定位可移动物体的位置,由于水域的流动,工业固体废物污染源很可能随着水流移动位置,基于粒子滤波算法将污染物定位分为预测.测量以及重新采样可大大 ...

  8. 【雷达图像】SAR合成孔径雷达成像及处理含Matlab源码

    1 简介 该文介绍了自己在硕士研究生期间围绕SAR(合成孔径雷达)展开的研究工作.除了背景介绍外,具体包括了高分辨率雷达图像的模拟,植被生物量与雷达后向散射系数的反演曲线,SAR图像地表分数维信息和分 ...

  9. 【心电信号】基于多种滤波去除心电信号基线漂移含Matlab源码

    1 简介 心电信号可以用来检测和诊断心脏疾病,心电信号在采集时经常受到呼吸活动.身体运动和皮肤与电极接触不良等影响,因此会产生基线漂移,基线漂移的存在会降低心电信号的质量.所以,在大多数心电信号处理中 ...

  10. 【信号检测】基于matlab自适应滤波法微弱信号检测【含Matlab源码 2308期】

    ⛄一.自适应滤波法微弱信号检测 1 NLMS自适应滤波 1.1 NLMS自适应滤波基本原理 最小均方 (LMS) 误差自适应滤波器[4]是将输入信号x (t) 通过系数可调的加权滤波器后, 与期望的参 ...

最新文章

  1. input type=file /,美化自定义上传按钮
  2. 为什么会需要HTTPS?
  3. android判断和创建快捷方式(4.03测试通过)
  4. 计算机应用技术一级考试成绩,《计算机应用基础》课程与等级考试成绩的关系...
  5. 华为鸿蒙系统智能手机_余承东再度确认:鸿蒙系统将适配到华为手机上
  6. python创建excel_python自动生成excel(xlwt库)
  7. PHP云尚发卡,云尚发卡1.5.7添加(极客支付)
  8. python的常量_如何给python中设定常量
  9. python tkinter获取屏幕大小_用 Python 制作关不掉的端午安康弹窗
  10. 《设计模式之禅》--设计模式大PK
  11. js 在线压缩混淆工具
  12. 获取当前节点之后的同级节点_04面试常问:分库分表之后,id 主键如何处理?...
  13. 【模电】0007 有源滤波器2(二阶有源滤低通波器)
  14. ensp官方停止下载
  15. 学习 FPGA 经验与书籍
  16. linux命令get命令使用,Linux apt-get命令使用方法
  17. phpmyadmin java_phpMyAdmin的配置
  18. 非常不错的垃圾删除批处理代码,用了10年不用安装清理软件
  19. 20届最难毕业的前端程序员的一年前端工作经验总结
  20. 差分输入ADC的前端抗混叠RC滤波器设计及作用

热门文章

  1. vue FullCalendar使用案例及详解
  2. c语言 文件读取z整行操作,C语言文件操作函数之ferror feof clearerr
  3. 分享下最近的Nvidia GPU 3060 laptop GPU、linzhi、Tesla算力曲线
  4. 网站域名空间服务器,网站 域名 空间 服务器
  5. 2017年计算机二级考试的word的答案,2017年3月全国计算机考试等级考试二级《MS Office高级应用》真题及答案...
  6. python录音功能,python实现录音功能可随时停止录音代码
  7. 对Spring IOC的理解
  8. 计算机中guest用户是灰的,来宾帐户状态不适用呈灰色状
  9. JavaScript实现效果——考试倒计时
  10. python文件怎么另存为,python文件怎么保存