【图像修复】基于GUI中值+均值+维纳+最小平方图像恢复【Matlab 772期】

一、简介

图像修复问题就是还原图像中缺失的部分。基于图像中已有信息,去还原图像中的缺失部分。

二、源代码

function varargout = hx1(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @hx1_OpeningFcn, ...
                   'gui_OutputFcn',  @hx1_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end

function hx1_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);

function varargout = hx1_OutputFcn(hObject, eventdata, handles) 
varargout{1} = handles.output;

function edit1_Callback(hObject, eventdata, handles)
function edit1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function file_Callback(hObject, eventdata, handles)

function recover_Callback(hObject, eventdata, handles)

function distortion_Callback(hObject, eventdata, handles)

% 关于
function about_Callback(hObject, eventdata, handles)
H=['本程序在MATLAB R2013b上编写,目的是减轻干扰和噪声对图像的影响,进行图像恢复。']
helpdlg(H,'相关信息');

% 中值滤波恢复
function medfilter_Callback(hObject, eventdata, handles)
file=get(handles.edit1,'string');
x=imread(file);
f=imnoise(x,'gaussian',0,0.01);               %给原图加入高斯噪声
axes(handles.axes2);             
imshow(f); title('加高斯噪声后的图像');
g1=medfilt2(f(:,:,1));%R
g2=medfilt2(f(:,:,2));%G
g3=medfilt2(f(:,:,3));%B
g(:,:,1)=g1;
g(:,:,2)=g2;
g(:,:,3)=g3;
axes(handles.axes3);                              %输出图像
imshow(g);  title('中值滤波后的图像');  

%均值滤波恢复
function averagefilter_Callback(hObject, eventdata, handles)
file=get(handles.edit1,'string');
x=imread(file);
f=imnoise(x,'gaussian',0,0.01);               %给原图加入高斯噪声
axes(handles.axes2);             
imshow(f); title('加高斯噪声后的图像');
f1=(f(:,:,1));%R
f2=(f(:,:,2));%G
f3=(f(:,:,3));%B
y0=fspecial('average',5);                     %进行均值滤波
y1=filter2(y0,f1)/255;
y2=filter2(y0,f2)/255;
y3=filter2(y0,f3)/255;
y(:,:,1)=y1;
y(:,:,2)=y2;
y(:,:,3)=y3;
axes(handles.axes3);          %输出图像
imshow(y); title('均值滤波后的图像');

% L-R恢复
function LR_Callback(hObject, eventdata, handles)
file=get(handles.edit1,'string');
h=fspecial('motion',41,11);
x=imread(file);
x1=im2double(x);
z=imfilter(x1,h,'conv','circular');
z1=imnoise(z,'gaussian',0,0.001);
axes(handles.axes2);          %输出图像
imshow(z1); title('退化后的图像'); 
DAMPAR=0.01;
LIM=ceil(size(h,1)/2);
WEIGHT=zeros(size(z1));
WEIGHT(LIM+1:end-LIM,LIM+1:end-LIM)=1;
NUMIT=17;
%迭代15次的复原,迭代次数越多,去模糊的效果越好,可通过具体情况调整
z2=deconvlucy(z1,h,NUMIT,DAMPAR,WEIGHT);
axes(handles.axes3);          %输出图像
imshow(z2); title('L-R算法恢复后的图像'); 

% 盲去卷积恢复,由于有迭代次数,显示图像速度较慢
function mangqujuanji_Callback(hObject, eventdata, handles)
file=get(handles.edit1,'string');
h=fspecial('motion',40,10);
x=imread(file);
x1=im2double(x);
z=imfilter(x1,h,'conv','circular');
z1=imnoise(z,'gaussian',0,0.001);
axes(handles.axes2);          %输出图像
imshow(z1); title('退化后的图像'); 
DAMPAR=0.01;
LIM=ceil(size(h,1)/2);
INITPSF=ones(size(h));
WEIGHT=zeros(size(z1));
WEIGHT(LIM+1:end-LIM,LIM+1:end-LIM)=1;
NUMIT=15;%盲去卷积迭代的次数,需要依具体情况调试到适当的值
[z2,PSF]=deconvblind(z1,INITPSF,NUMIT,DAMPAR,WEIGHT);
axes(handles.axes3);          %输出图像
imshow(z2); title('盲去卷积恢复后的图像'); 

%旋转 
function xuanzhuan_Callback(hObject, eventdata, handles)
file=get(handles.edit1,'string');
x=imread(file);
%x=rgb2gray(x);
a1=[cos(pi/4) sin(pi/4) 0;-sin(pi/4) cos(pi/4) 0;0 0 1];
a2=[cos(pi/4) -sin(pi/4) 0;sin(pi/4) cos(pi/4) 0;0 0 1];
b1=maketform('affine',a1);
b2=maketform('affine',a2);
c1=imtransform(x,b1);
c2=imtransform(x,b2);
axes(handles.axes2);          %输出图像
imshow(c1); title('顺时针旋转45度的图像'); 
axes(handles.axes3); 
imshow(c2); title('逆时针旋转45度的图像'); 

% 剪切
function jianqie_Callback(hObject, eventdata, handles)
file=get(handles.edit1,'string');
x=imread(file);
a1=[1 0 0;0.5 1 0;0 0 1];
a2=[1 0.5 0;0 1 0;0 0 1];
b1=maketform('affine',a1);
b2=maketform('affine',a2);
c1=imtransform(x,b1);
c2=imtransform(x,b2);
axes(handles.axes2);          %输出图像
imshow(c1); title('水平剪切的图像'); 
axes(handles.axes3); 
imshow(c2); title('垂直剪切的图像'); 

%镜像
function jingxiang_Callback(hObject, eventdata, handles)
file=get(handles.edit1,'string');
x=imread(file);
a1=[-1 0 0;0 1 0;1 0 1];
a2=[1 0 0;0 -1 0;0 1 1];
b1=maketform('affine',a1);
b2=maketform('affine',a2);
c1=imtransform(x,b1);
c2=imtransform(x,b2);
axes(handles.axes2);          %输出图像
imshow(c1); title('水平镜像的图像'); 
axes(handles.axes3); 
imshow(c2); title('垂直镜像的图像'); 

% 打开
function open_Callback(hObject, eventdata, handles)
[filename,pathname]=uigetfile('*.jpg')
set(handles.edit1,'string',[pathname,filename])  %设置edit1的 字符内容
file=get(handles.edit1,'string');
x=imread(file);
axes(handles.axes1);
 imshow(x);title('原始图像'); 

%保存
function save_Callback(hObject, eventdata, handles)
[filename,pathname]=uiputfile('*.jpg');
set(handles.edit1,'string',[pathname,filename]);
A=getimage(handles.axes1);
imwrite(A,filename,'jpg');

function zuixiaopingfang_Callback(hObject, eventdata, handles)
file=get(handles.edit1,'string');
x=imread(file);
PSF=fspecial('gaussian',10,2);  
f=imfilter(x,PSF,'conv');   

三、运行结果

【图像修复】基于GUI中值+均值+维纳+最小平方图像恢复【Matlab 772期】

四、备注

完整代码或者代写添加QQ 912100926

上一篇:移动端MescrollVue上下刷新


下一篇:【布局优化】基于粒子群算法求解传感器覆盖问题matlab源码含 GUI