A list,
Image denoising based on MATLAB GUI median + mean + Wiener + wavelet filtering
Ii. Source code
function varargout = main(varargin)
% MAIN MATLAB code for main.fig
% MAIN, by itself, creates a new MAIN or raises the existing
% singleton*.
%
% H = MAIN returns the handle to a new MAIN or the handle to
% the existing singleton*.
%
% MAIN('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MAIN.M with the given input arguments.
%
% MAIN('Property'.'Value',...). creates anew MAIN or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before main_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to main_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 main
% Last Modified by GUIDE v2. 5 20-Apr- 2021. 22:48:39
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @main_OpeningFcn, ...
'gui_OutputFcn', @main_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 main is made visible.
function main_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 main (see VARARGIN)
% Choose default command line output for main
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes main wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = main_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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)%% read image [filename, pathname]= uigetfile(...
{'*.bmp; *.jpg; *.png; *.jpeg; '.'Image Files(*.bmp,*.jpg,*.png,*.jpeg)'; .'*. *'.'All Files(*.*)'}... .'Pick an image'); % Open the file to select the imageif isequal(filename,0) || isequal(pathname,0)
return; % if the fruit is clicked "cancel"end
axes(handles.axes1); Fpath = [pathName filename]; % path name and file name img1 = imread(fpath); % read imshow(img1); % show image handles. Img1 =img1; title('original')
guidata(hObject, handles);
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)%% Gaussian noise img1=handles.img1;
img2 = imnoise(img1,'gaussian'); Axes (handles. Axes2); imshow(img2); handles.img2=img2; title('Gaussian noise diagram')
guidata(hObject, handles);
function [zipped, info] = huffencode(vector) % uint8 format % info returns the structure information needed for decoding % info.pad is the number of added bits % info.huffMan codes % info.rows is the number of original image lines % info.cols % info.length % info.maxCodelen % info.maxCodelen % info.lengthif ~isa(vector.'uint8')
error('input argument must be a uint8 vector');
end
[m, n] = size(vector);
vector = vector(:)'; % f = frequency(vector); % Calculate the probability of each symbol = find(f~=0); f = f(symbols); [f, sortindex] = sort(f); % Rank symbols by probability = symbols(sortindex); len = length(symbols); symbols_index = num2cell(1:len); codeword_tmp = cell(len, 1); While length(f)>1 index1 = symbols_index{1}; index2 = symbols_index{2}; codeword_tmp(index1) = addnode(codeword_tmp(index1), uint8(0)); codeword_tmp(index2) = addnode(codeword_tmp(index2), uint8(1)); f = [sum(f(1:2)),f(3:end)]; symbols_index = [{[index1, index2]},symbols_index(3:end)]; [f, sortindex] = sort(f); symbols_index = symbols_index(sortindex); end codeword = cell(256, 1); codeword(symbols) = codeword_tmp; len = 0; For index = 1:length(vector) % Len = len + length(codeWord {double(vector(index))+1}); end string = repmat(uint8(0), 1, len); pointer = 1; For index = 1:length(vector) % code = codeWord {double(vector(index))+1}; len = length(code); string(pointer + (0:len-1))=code; pointer = pointer + len; end len = length(string); pad = 8-mod(len, 8); if pad > 0 string = [string uint8(zeros(1, pad))]; end codeword = codeword(symbols); codelen = zeros(size(codeword)); weights = 2.^(0:23); maxcodelen = 0; for index = 1:length(codeword) len = length(codeword{index}); if len > maxcodelen; maxcodelen = len; end if len > 0 code = sum(weights(codeword{index} == 1)); code = bitset(code, len + 1); codeword{index} = code; codelen(index) = len; end end codeword = [codeword{:}]; Cols = length(string)/8; string = reshape(string, 8, cols); weights = 2.^(0: 7); zipped = uint8(weights * double(string)); % code table stored to a HuffCodes = Sparse (1, 1); for index = 1:nnz(codeword) % length(codeword) %numel(codeword) huffcodes(codeword(index), 1) = symbols(index); End % Fill in the structure information required for decoding info.pad = pad; info.huffcodes = huffcodes; info.ratio = cols./length(vector); info.length = length(vector); info.maxcodelen = maxcodelen; info.rows = m; info.cols = n; Function codeword_new = addNode (codeword_old, item) codeword_new = cell(size(codeword_old)); for index = 1:length(codeword_old) codeword_new{index} = [item codeword_old{index}]; Function f = frequency(vector) if ~isa(vector, 'uint8')
error('input argument must be a uint8 vector');
end
f = repmat(0.1.256);
len = length(vector);
for index = 0:255
f(index+1) = sum(vector== uint8(index)); end f = f./len; Function y = jpegenCode (x, quality) % jpegenCode (x, quality) % error(nargchk)1.2, nargin)); % Checks input parametersif nargin < 2
quality = 1; % The default quality is1
end
x = double(x) - 128; % pixel level move- 128.[xm, xn] = size(x); % get pixel size t = DCTMTX (8); % to get8*8DCT matrix % divides the image into8*8Y = blkproc(x, [8.8].'P1*x*P2', t, t'); % m = [16 11 10 16 24 40 51 61%JPEG quantization step size matrix12 12 14 19 26 58 60 55
14 13 16 24 40 57 69 56
14 17 22 29 51 87 80 62
18 22 37 56 68 109 103 77
24 35 55 64 81 104 113 92
49 64 78 87 103 121 120 101
72 92 95 98 112 110 103 99]*quality; Yy = blkproc(y, [8.8].'round(x./P1)', m);
y = im2col(yy, [8.8].'distinct'); % arrange image blocks into vectors xb = size(y,2); % gets the number of columns, which is the number of subimages order = [1 9 2 3 10 17 25 18 11 4 5 12 19 26 33. % transform coefficient order41 34 27 20 13 6 7 14 21 28 35 42 49 57 50.43 36 29 22 15 8 16 23 30 37 44 51 58 59 52.45 38 31 24 32 39 46 53 60 61 54 47 40 48 55 62 63 56 64]; % rearrange transform coefficients by z-scan y = y(order, :); eob = max(x(:)) +1; Num = numel(y) + size(y, y)2);
r = zeros(num, 1);
count = 0; % rearranges non-zero elements into r,26 -- 3 eob - 25 1 eob
for j = 1: xb % operates on one column at a time I = Max (find(y(:, j)); % finds the last non-zero elementif isempty(i)% has no non-zero element I= 0;
end
p = count + 1;
q = p + i;
r(p: q) = [y(1: i, j); eob]; % truncate zero and add closing sign count = count + I +1;
end
r((count + 1): end) = []; % delete the useless part of r = r +128; Size = uint16([xm, xn]); y.numblocks = uint16(xb); y.quality = uint16(quality*100); % Huffman encoding of r [y.huffman, Y.info] = Huffencode (uint8(r));Copy the code
3. Operation results
Fourth, note
Version: 2014 a