【图像处理】基于matlab GUI Hough变换+PDE图像去雨(带面板)【含Matlab源码 811期】
【摘要】
一、图像处理简介
图像处理知识点: 1 数字图像处理及matlab实现知识点总结1-4 2 数字图像处理及matlab实现知识点总结 5-10
二、部分源代码
function varargout ...
一、图像处理简介
图像处理知识点:
1 数字图像处理及matlab实现知识点总结1-4
2 数字图像处理及matlab实现知识点总结 5-10
二、部分源代码
function varargout = GUI_part(varargin)
% GUI_PART MATLAB code for GUI_part.fig
% GUI_PART, by itself, creates a new GUI_PART or raises the existing
% singleton*.
%
% H = GUI_PART returns the handle to a new GUI_PART or the handle to
% the existing singleton*.
%
% GUI_PART('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI_PART.M with the given input arguments.
%
% GUI_PART('Property','Value',...) creates a new GUI_PART or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before GUI_part_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to GUI_part_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help GUI_part
% Last Modified by GUIDE v2.5 16-Apr-2014 18:09:28
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @GUI_part_OpeningFcn, ...
'gui_OutputFcn', @GUI_part_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
% End initialization code - DO NOT EDIT
% --- Executes just before GUI_part is made visible.
function GUI_part_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to GUI_part (see VARARGIN)
% Choose default command line output for GUI_part
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes GUI_part wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = GUI_part_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in UI_Load.
function UI_Load_Callback(hObject, eventdata, handles)
% hObject handle to UI_Load (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clc;
global IMG;
[filename, pathname] = uigetfile({'*.tif'; '*.jpg'; '*.bmp';'*.*'},'File Selector');
if isequal(filename,0)
msgbox(sprintf('Please select image :)'),'No Image Selected','warn');
return;
end
IMG =imread(filename);
axes(handles.UI_origin);
imshow(IMG);
% --- Executes on button press in UI_process.
function UI_process_Callback(hObject, eventdata, handles)
% hObject handle to UI_process (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global IMG;
%generate detected image and tag image
[Img, Img_tag] = GeneratorCore(IMG); %use Hough transform to detect rain and tag area
axes(handles.UI_hough);
imshow(Img);
axes(handles.UI_mask);
imshow(Img_tag);
mu = 20;
[xlen,ylen, ~] =size(Img_tag);
IMG2= imresize(IMG,[max(xlen,ylen),max(xlen,ylen)]);
for i = 1:3
IMGt = IMG2(:,:,i)
Origin_resize = double(imresize(IMGt,[max(size(IMGt)),max(size(IMGt))]));
[x,y] = size(Origin_resize);
Structure_img(:,:,i) = uint8(reshape(SB_ATV(Origin_resize, mu), x, y)); %use PDE to get structure information
Texture_img(:,:,i) = uint8(Origin_resize-double(Structure_img(:,:,i)));
end
% figure;subplot(1,2,1);
axes(handles.UI_PDE_low);
imshow(Structure_img);
% title('Structure Image');
% Texture_img = Origin_resize-Structure_img;
% subplot(1,2,2);
axes(handles.UI_PDE_high);
imshow(Texture_img);
% title('Texture Image');
mask = imresize(Img_tag,[max(xlen,ylen),max(xlen,ylen)]);
%Use texture patch to repair image
for i = 1:3
New_i(:,:,i)= Texture_core(double(Structure_img(:,:,i)),double(mask));
New_i(:,:,i) = medfilt2(New_i(:,:,i),[5,5]);
end
% figure;
axes(handles.UI_final);
imshow(uint8(New_i),[0,255]);
% --- Executes on button press in UI_hough_step.
function UI_hough_step_Callback(hObject, eventdata, handles)
% hObject handle to UI_hough_step (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of UI_hough_step
global IMG;
if( get(hObject,'Value') == 1)
[Img, Img_tag] = GeneratorCore(IMG); %use Hough transform to detect rain and tag area
figure;
subplot(1,2,1);
imshow(Img);
subplot(1,2,2);
imshow(Img_tag);
end
% --- Executes on button press in radiobutton2.
function radiobutton2_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
unction B=inpaint_nans(A,method)
% INPAINT_NANS: in-paints over nans in an array
% usage: B=INPAINT_NANS(A) % default method
% usage: B=INPAINT_NANS(A,method) % specify method used
%
% Solves approximation to one of several pdes to
% interpolate and extrapolate holes in an array
%
% arguments (input):
% A - nxm array with some NaNs to be filled in
%
% method - (OPTIONAL) scalar numeric flag - specifies
% which approach (or physical metaphor to use
% for the interpolation.) All methods are capable
% of extrapolation, some are better than others.
% There are also speed differences, as well as
% accuracy differences for smooth surfaces.
%
% methods {0,1,2} use a simple plate metaphor.
% method 3 uses a better plate equation,
% but may be much slower and uses
% more memory.
% method 4 uses a spring metaphor.
% method 5 is an 8 neighbor average, with no
% rationale behind it compared to the
% other methods. I do not recommend
% its use.
%
% method == 0 --> (DEFAULT) see method 1, but
% this method does not build as large of a
% linear system in the case of only a few
% NaNs in a large array.
% Extrapolation behavior is linear.
%
% method == 1 --> simple approach, applies del^2
% over the entire array, then drops those parts
% of the array which do not have any contact with
% NaNs. Uses a least squares approach, but it
% does not modify known values.
% In the case of small arrays, this method is
% quite fast as it does very little extra work.
% Extrapolation behavior is linear.
%
% method == 2 --> uses del^2, but solving a direct
% linear system of equations for nan elements.
% This method will be the fastest possible for
% large systems since it uses the sparsest
% possible system of equations. Not a least
% squares approach, so it may be least robust
% to noise on the boundaries of any holes.
% This method will also be least able to
% interpolate accurately for smooth surfaces.
% Extrapolation behavior is linear.
%
% Note: method 2 has problems in 1-d, so this
% method is disabled for vector inputs.
%
% method == 3 --+ See method 0, but uses del^4 for
% the interpolating operator. This may result
% in more accurate interpolations, at some cost
% in speed.
%
% method == 4 --+ Uses a spring metaphor. Assumes
% springs (with a nominal length of zero)
% connect each node with every neighbor
% (horizontally, vertically and diagonally)
% Since each node tries to be like its neighbors,
% extrapolation is as a constant function where
% this is consistent with the neighboring nodes.
%
% method == 5 --+ See method 2, but use an average
% of the 8 nearest neighbors to any element.
% This method is NOT recommended for use.
%
%
% arguments (output):
% B - nxm array with NaNs replaced
%
%
% Example:
% [x,y] = meshgrid(0:.01:1);
% z0 = exp(x+y);
% znan = z0;
% znan(20:50,40:70) = NaN;
% znan(30:90,5:10) = NaN;
% znan(70:75,40:90) = NaN;
%
% z = inpaint_nans(znan);
%
%
% See also: griddata, interp1
%
% Author: John D'Errico
% e-mail address: woodchips@rochester.rr.com
% Release: 2
% Release date: 4/15/06
% I always need to know which elements are NaN,
% and what size the array is for any method
[n,m]=size(A);
A=A(:);
nm=n*m;
k=isnan(A(:));
% list the nodes which are known, and which will
% be interpolated
nan_list=find(k);
known_list=find(~k);
% how many nans overall
nan_count=length(nan_list);
% convert NaN indices to (r,c) form
% nan_list==find(k) are the unrolled (linear) indices
% (row,column) form
[nr,nc]=ind2sub([n,m],nan_list);
% both forms of index in one array:
% column 1 == unrolled index
% column 2 == row index
% column 3 == column index
nan_list=[nan_list,nr,nc];
% supply default method
if (nargin<2) || isempty(method)
method = 0;
elseif ~ismember(method,0:5)
error 'If supplied, method must be one of: {0,1,2,3,4,5}.'
end
% for different methods
switch method
case 0
% The same as method == 1, except only work on those
% elements which are NaN, or at least touch a NaN.
% is it 1-d or 2-d?
if (m == 1) || (n == 1)
% really a 1-d case
work_list = nan_list(:,1);
work_list = unique([work_list;work_list - 1;work_list + 1]);
work_list(work_list <= 1) = [];
work_list(work_list >= nm) = [];
nw = numel(work_list);
u = (1:nw)';
fda = sparse(repmat(u,1,3),bsxfun(@plus,work_list,-1:1), ...
repmat([1 -2 1],nw,1),nw,nm);
else
% a 2-d case
% horizontal and vertical neighbors only
talks_to = [-1 0;0 -1;1 0;0 1];
neighbors_list=identify_neighbors(n,m,nan_list,talks_to);
% list of all nodes we have identified
all_list=[nan_list;neighbors_list];
% generate sparse array with second partials on row
% variable for each element in either list, but only
% for those nodes which have a row index > 1 or < n
L = find((all_list(:,2) > 1) & (all_list(:,2) < n));
nl=length(L);
if nl>0
fda=sparse(repmat(all_list(L,1),1,3), ...
repmat(all_list(L,1),1,3)+repmat([-1 0 1],nl,1), ...
repmat([1 -2 1],nl,1),nm,nm);
else
fda=spalloc(n*m,n*m,size(all_list,1)*5);
end
三、运行结果
四、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1] 蔡利梅.MATLAB图像处理——理论、算法与实例分析[M].清华大学出版社,2020.
[2]杨丹,赵海滨,龙哲.MATLAB图像处理实例详解[M].清华大学出版社,2013.
[3]周品.MATLAB图像处理与图形用户界面设计[M].清华大学出版社,2013.
[4]刘成龙.精通MATLAB图像处理[M].清华大学出版社,2015.
[5]陈浩,方勇,朱大洲,王成,陈子龙.基于蚁群算法的玉米植株热红外图像边缘检测[J].农机化研究. 2015,37(06)
文章来源: qq912100926.blog.csdn.net,作者:海神之光,版权归原作者所有,如需转载,请联系作者。
原文链接:qq912100926.blog.csdn.net/article/details/116009941
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)