Sie sind auf Seite 1von 4

GUI CREATION:

function varargout = ImageFilter(varargin)


% IMAGEFILTER M-file for ImageFilter.fig
% IMAGEFILTER, by itself, creates a new IMAGEFILTER or raises the
existing
% singleton*.
%
% H = IMAGEFILTER returns the handle to a new IMAGEFILTER or the handle
to
% the existing singleton*.
%
% IMAGEFILTER('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in IMAGEFILTER.M with the given input
arguments.
%
% IMAGEFILTER('Property','Value',...) creates a new IMAGEFILTER or raises
the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before ImageFilter_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to ImageFilter_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 ImageFilter

% Last Modified by GUIDE v2.5 16-Mar-2011 20:34:42

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ImageFilter_OpeningFcn, ...
'gui_OutputFcn', @ImageFilter_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 ImageFilter is made visible.


function ImageFilter_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 ImageFilter (see VARARGIN)

% Choose default command line output for ImageFilter


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes ImageFilter wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = ImageFilter_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.

--- Executes just before ImageFilter is made visible.


function ImageFilter_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 ImageFilter (see VARARGIN)

% Choose default command line output for ImageFilter


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes ImageFilter wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = ImageFilter_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.
SELCTION OF IMAGE :

function pushbutton19_Callback(hObject, eventdata, handles)


% hObject handle to pushbutton19 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%[filename pathname]=uigetfile({'*.pgm','FileType(*.pgm)'},'Select Image');

%-----------------------------------------------------------------
[namefile,pathname]=uigetfile({'*.bmp;*.jpg;*.jpeg','IMAGE Files
(*.bmp,*.jpg,*.jpeg)'},'Select an Image');
if namefile~=0
[img,map]=imread(strcat(pathname,namefile));
handles.img=img;
handles.flag2=1;
guidata(hObject,handles);
axes(handles.axes2);
imshow(img);

warndlg('IMAGE SELECTED','Message');
else
errordlg('Select a image','Error');
end
handles.count=1;
guidata(hObject,handles);
%-------------------------------------------------------------

Close GUI:
--- Executes on button press in pushbutton20.
function pushbutton20_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton20 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close ImageFilter;

ADD THE NOISE TO IMAGE:


% --- Executes on button press in pushbutton33.
function pushbutton33_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton33 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
img=handles.img;
im=imnoise(img,'speckle');
handles.image=im;
handles.flag4=1;
guidata(hObject,handles);
axes(handles.axes4);
imshow(im);
title('Image added with noise')

FILTER SELECTION:
Wiener Filter selection in GUI:

function pushbutton7_Callback(hObject, eventdata, handles)


% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
img1=handles.img;
im=imnoise(img1,'speckle');
j=wiener2(im,[5 5]);
handles.image=j;
handles.flag3=1;
guidata(hObject,handles);
axes(handles.axes3);
imshow(j);
title('WIENER FILTER OUTPUT');

Error Calculations in Image noise reductions:

grayImage = j;
[rows columns] = size(grayImage);
figure,
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grey Scale Image');
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
% Add noise to it.
noisyImage = imnoise(grayImage, 'gaussian', 0, 0.001);
subplot(2, 2, 2);
imshow(noisyImage, []);
title('Noisy Image');
% Calculate mean square error.
mseImage = (double(grayImage) - double(noisyImage)) .^ 2;
subplot(2, 2, 3);
imshow(mseImage, []);
title('MSE Image');
mse = sum(sum(mseImage)) / (rows * columns);
% Calculate PSNR (Peak Signal to noise ratio).
PSNR = 20 * log10( 256^2 / mse^2);

Das könnte Ihnen auch gefallen