数字图像处理之图像修复

article/2025/10/15 15:21:14

目录

 

目标

 实验

主函数:加噪声,扭曲原始图片,使用滤波器修复图片

 子函数1:中心化图片

子函数2:加高斯噪声

子函数3:维纳反卷积滤波器

子函数4:逆滤波器

实验结果

原始图片,退化图片,加噪图片,逆滤波修复图片,维纳反卷积滤波修复图片 

维纳反卷积滤波器对高斯噪声variance的响应探究


目标

本实验使用自定义退化函数,对原始图片进行扭曲退化。然后使用逆滤波器和维纳反卷积滤波器来对退化图像处理,获得原始图片。

逆滤波是从系统的输出中接收输入的过程。一旦已知退化函数,这是恢复原始图像的最简单方法。

维纳反卷积滤波器定义

 实验

主函数:加噪声,扭曲原始图片,使用滤波器修复图片

clc; clear;
%% Read the original image
fig_original = double(imread('data/book_cover.jpg')) / 255;
[Height, Width] =size(fig_original);
% Discrete Fourier Transformation
F = fft2(center_transform(fig_original));%% Blurring Degradation and Restoration
figure('Name', 'Blurring Degradation');
% Display the original image
subplot(2, 3, 1);
imshow(fig_original, []);
title('The original image');% Blur the image using paramaters a=b=0.1 and T = 1
subplot(2, 3, 2);
H = filter_H(Height, Width, 0.1, 0.1, 1);
blurred_image = center_transform(real(ifft2(H .* F)));
imshow(blurred_image, []);
imwrite(blurred_image, 'data/blurred_image.png');
title('Blurred image');% Add Gaussian noise of 0 mean and variance of 650 to the blurred image
subplot(2, 3, 3);
noise = gaussian_noise(Height, Width, sqrt(650), 0) / 255;
blurred_noisy_image = blurred_image + noise;
imshow(blurred_noisy_image, []);
imwrite(blurred_noisy_image, 'data/blurred_noisy_image.png');
title('Add Gaussian noise');% Restore the blurred image using the inverse filter
subplot(2, 3, 5);
F_blurred = fft2(center_transform(blurred_image));
blurred_restored = center_transform(real(ifft2(F_blurred ./ H)));
imshow(blurred_restored, []);
imwrite(blurred_restored, 'data/blurred_restored.png');
title('Blurred image restored with inverse filter');% Restore the blurred noisy image using Wiener deconvolution filter
subplot(2, 3, 6);
F_blurred_noisy = fft2(center_transform(blurred_noisy_image));
blurred_noisy_restored = center_transform(real(ifft2(wiener_filter(noise, F, H) .* F_blurred_noisy)));
imshow(blurred_noisy_restored, []);
imwrite(blurred_noisy_restored, 'data/blurred_noisy_restored.png');
title('Blurred noisy image restored with Wiener deconvolution filter');%% Investigate the performance of the Wiener deconvolution filter using Gaussian noise of 0 and different variances
figure('Name', 'Investigate Wiener deconvolution filter');% Add Gaussian noise of 0 mean and variance of 0.1 to the blurred image
subplot(1, 3, 1);
noise = gaussian_noise(Height, Width, sqrt(0.1), 0) / 255;
F_blurred_noisy = fft2(center_transform(blurred_image + noise));
blurred_noisy_restored = center_transform(real(ifft2(wiener_filter(noise, F, H) .* F_blurred_noisy)));
imshow(blurred_noisy_restored, []);
imwrite(blurred_noisy_restored, 'data/gvar0_1.png');
title('Gaussian variance = 0.1');% Add Gaussian noise of 0 mean and variance of 10 to the blurred image
subplot(1, 3, 2);
noise = gaussian_noise(Height, Width, sqrt(10), 0) / 255;
F_blurred_noisy = fft2(center_transform(blurred_image + noise));
blurred_noisy_restored = center_transform(real(ifft2(wiener_filter(noise, F, H) .* F_blurred_noisy)));
imshow(blurred_noisy_restored, []);
imwrite(blurred_noisy_restored, 'data/gvar10.png');
title('Gaussian variance = 10');% Add Gaussian noise of 0 mean and variance of 1000 to the blurred image
subplot(1, 3, 3);
noise = gaussian_noise(Height, Width, sqrt(1000), 0) / 255;
F_blurred_noisy = fft2(center_transform(blurred_image + noise));
blurred_noisy_restored = center_transform(real(ifft2(wiener_filter(noise, F, H) .* F_blurred_noisy)));
imshow(blurred_noisy_restored, []);
imwrite(blurred_noisy_restored, 'data/gvar1000.png');
title('Gaussian variance = 1000');

 子函数1:中心化图片

function [ output ] = center_transform( input )
% CENTER_TRANSFORM centerize an image by applying
%   f(x, y) = f(x, y) * (-1)^{x+y}[h, w] = size(input);u = 1:h;v = 1:w;[V, U] = meshgrid(v, u);D = V + U;output = input .* power(-1, D);
end

子函数2:加高斯噪声

function [ output ] = gaussian_noise( M, N, sigma, zbar )
%GAUSSIAN_NOISE of size M * N
%   p(z) = 1 / sqrt(2 * pi)sigma * e^(-(z - zbar)^2 / 2sigma^2)output = zbar + randn(M, N) * sigma;
end

子函数3:维纳反卷积滤波器

function [ output ] = wiener_filter( N, F, H)
% WIENER_FILTER generates a typical Wiener filter by definitionH2 = abs(H) .^ 2;Sn = abs(fft2(center_transform(N))) .^ 2;Sf = abs(F) .^ 2;output = (H2 ./ H ./ (H2 + Sn ./ Sf));
end

子函数4:逆滤波器

function [ output ] = filter_H( M, N, a, b, T )
% FILTER_H generates a filter of size h * w
%   where H(u, v) = T / \pi(ua+vb) sin[\pi(ua+vb)] e^{-j\pi(ua+vb)}u = [1:M] - M / 2;v = [1:N] - N / 2;[V, U] = meshgrid(v, u);D = (V .* b + U .* a) .* pi;output = ones(M, N) .* T ./ D .* sin(D) .* exp(-j * D);output(D == 0) = 1;
end

实验结果

原始图片,退化图片,加噪图片,逆滤波修复图片,维纳反卷积滤波修复图片 

维纳反卷积滤波器对高斯噪声variance的响应探究


http://chatgpt.dhexx.cn/article/VDiWs0D1.shtml

相关文章

图像修复模型——TV模型

1. 参考文献 2. TV图像修复模型 2.1 TV模型 % demo_TV.m % Author: HSW % Date: 2015/3/25 % HARBIN INSTITUTE OF TECHNOLOGY % % set matlab close all; clear all; clc;options.null 0; % read image Img imread(Image\butterfly.bmp); % Img imread(Image\peppers.bmp…

图像修复 学习笔记

目录 局部卷积(PConv)图像修复 Pconv torch 实现: 局部卷积(PConv)图像修复 本文提出了局部卷积(PConv)层来处理不规则孔。图1显示了使用建议的PConv的一些修复结果。看样子还不错&#xff0…

基于改进Criminisi算法的图像修复

1、内容简介 略 516-可以交流、咨询、答疑 2、内容说明 摘 要:针对 Criminisi算法难以获得理想的修复效果,且存在修复时间过长等缺陷,提出一种改进 Criminisi算法的 图像修复算法。改进优先权计算方式找到最优待修复块,完善最优…

图像修复简介

点击上方“小白学视觉”,选择加"星标"或“置顶” 重磅干货,第一时间送达推荐阅读 42个pycharm使用技巧,瞬间从黑铁变王者Google C项目编程风格指南 (中文版) 分享在实际应用中,图像经常被噪声腐蚀。这些噪音是镜头上的灰…

Halcon图像修复

1.之前研究OpenCV的图像修复时,知道Opencv提供的inpaint API能够实现这个效果。 void inpaint( InputArray src, 原图 InputArray inpaintMask, 二进制掩模,指示要修复的像素 OutputArray dst, 目标图像 double inpaintRadius, 像素周围的邻域补绘。…

图像修复

转自:https://blog.csdn.net/moxibingdao/article/details/107075598 本文继 去雨去雾去模糊篇 和 图像增强与图像恢复篇 之后,继续盘点CVPR 2020 中低层图像处理技术,本篇聚焦于图像修复(Image Inpainting)。 示例如…

CVPR 2020 论文大盘点-图像修复Inpainting篇

转自:https://mp.weixin.qq.com/s?__bizMzIwMTE1NjQxMQ&mid2247519592&idx2&sn3a0598c9f52e47929678a572ea451d98&chksm96f0ff3ca187762a107b4b9194e862b757d3d943ec399b35cbb7576cd92ee55cc648d7121ac3&scene21#wechat_redirect 本文继 去雨…

图像修复介绍

图像修复是一种利用缺损图像中已知部分的信息预测缺损区域的内容,允许使用替代内容取填充目标区域的技术。其最终目的是保证修复后的图像整体结构连贯统一,修复区域边缘处过渡自然,修复内容细节丰富合理,最好能够使观察者无法分辨…

【OpenCV】- 图像修复

说明:图像修复可以解决类似噪声或者是镜头上的灰尘或水滴或者旧照片上面的划痕等。 文章目录 1、实现图像修补:inpaint()函数2、opencv之鼠标响应函数3、示例程序 1、实现图像修补:inpaint()函数 说明:图像修补技术由inpaint()函数…

图像修复(Image Restoration)算法数据集详细介绍

目录 人脸数据集 1.Helen Face 2.CelebA (Celebrity Attribute) 3.CelebA-HQ 4.FFHQ(Flickr-Faces-HQ) 场景数据集 1.MS COCO (Common Objects in Context) 2.ImageNet 3.Places2 街景数据集 1.Paris StreetView 2.Cityscapes 纹理数据集 …

图像修复 : ICCV 2021 基于条件纹理和结构并行生成的图像修复【翻译】

声明:精简翻译,未完全校对 积压的存稿、好久没更文了、先发一篇这个代码很不错、推荐有兴趣的同学学习博主也写了对应的测评文章待发、点赞越多、发的越快如有同学,学有余力、可以转载这个文章( 附原文地址即可 )、校对…

Linux udhcpc/udhcpd 移植

参考文档: http://blog.chinaunix.net/uid-14704264-id-4272838.html https://www.cnblogs.com/chenfulin5/p/9481249.html 若系统busybox 自带了 udhcpc 和 udhcpd 工具 udhcpc 作为客户端工具,用于动态获取IP; udhcpd 作为服务器工具&…

udhcpc6的default.script

udhcpc6使用中遇到的问题 和udhcpc一样,udhcpc6是busybox中的一个工具,主要用来提供dhcpv6客户端服务。 在使用过程中遇到了一个问题,直接执行udhcpc6 -i eth0,可以看到打印信息中显示正在发送discover包,如果本地有…

UNIX source code-DHCP

文章目录 DHCP基础知识什么是DHCP为什么要使用DHCP IP地址分配机制工作原理报文类型基本步骤中继重用IP租赁期限 代码解析文件作用udhcpd.c结构体代码逻辑(流程) udhcpc.c结构体代码逻辑(流程) file.c结构体(read_conf…

udhcpc 移植和使用

问题描述: busybox udhcpc获取IP,但没有自动将获取到的ip设置到网卡上,并且没有自动设置网关,路由表等。必须手动设置才能连接外网。 解决方案: udhcpc可以通过-s参数指定运行脚本,当获取到ip地址后&…

初始化ArrayList、List的两种方法

说明&#xff1a; 个人偏向第二种方法&#xff0c;适合没有服务器数据的情况下&#xff0c;做个简单的list来开发 方式一&#xff1a; ArrayList<String> list new ArrayList<String>();String str01 String("str01");String str02 String("str0…

Java 中初始化 List 集合的 6 种方式!

List 是 Java 开发中经常会使用的集合&#xff0c;你们知道有哪些方式可以初始化一个 List 吗&#xff1f;这其中不缺乏一些坑&#xff0c;今天栈长我给大家一一普及一下。 1、常规方式 List<String> languages new ArrayList<>(); languages.add("Java&qu…

java创建List时候 初始化赋值

在这之前 可能有的读者&#xff0c; 只知道数组初始化 时候的赋值。 String[] strings new String[]{"one","two","three"};当创建list时候&#xff0c;也许 你还会写过以下代码 正确的写法 List<String> list new ArrayList<>(…

初始化列表

前言 在创建对象时&#xff0c;编译器通过调用构造函数&#xff0c;给对象中各个成员变量一个合适的初始值。 class Date { public:Date(int year, int month, int day){_year year;_month month;_day day;} private:int _year;int _month;int _day; }; 虽然上述构造函数调…

Java 初始化 List 的几种方法

最常见的初始化 List 方法为&#xff1a; List<String> languages new ArrayList<>(); languages.add("Java"); languages.add("PHP"); languages.add("Python"); System.out.println(languages);但是实际上&#xff0c;我们并不会…