Você está na página 1de 11

function varargout = vf(varargin)

% VIDFIL MATLAB code for VidFil.fig


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

% Last Modified by GUIDE v2.5 15-Aug-2017 21:44:42

% Begin initialization code - DO NOT EDIT


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


function VidFil_OpeningFcn(hObject, eventdata, handles, varargin)
global filter thermal gaussian order crystal invert entropy brightness edgedetect map convert playpause
count verticaldilate circulardilate brightval erode motion stopval

%buttons background
stopbutton=imread('stop.png');
set(handles.stop,'CData',stopbutton);
playbutton=imread('play.jpg');
set(handles.play,'CData',playbutton);
load=imread('load.jpg');
set(handles.load,'CData',load);

playpause = 0;
count = 0;
map = gray;
filter = 1;
thermal = 0;
gaussian = 0;
order = 0;
crystal = 0;
invert = 0;
entropy = 0;
brightness = 0;
edgedetect = 0;
verticaldilate = 0;
circulardilate = 0;
brightval = 0;
erode = 0;
motion = 0;
convert = 0;
stopval = 0;
set(handles.play,'Enable','off')
set(handles.stop,'Enable','off')
set(handles.colormenu,'Enable','off')
set(handles.convert2gray,'Enable','off')
set(handles.thermal,'Enable','off')
set(handles.gaussian,'Enable','off')
set(handles.order,'Enable','off')
set(handles.crystallize,'Enable','off')
set(handles.invert,'Enable','off')
set(handles.edge,'Enable','off')
set(handles.circular,'Enable','off')
set(handles.vertical,'Enable','off')
set(handles.brightness,'Enable','off')
set(handles.erode,'Enable','off')
set(handles.motion,'Enable','off')
axes(handles.original);
rectangle();
axes(handles.filtered);
rectangle();
% 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 VidFil (see VARARGIN)

% Choose default command line output for VidFil


handles.output = hObject;
% create an axes that spans the whole gui
ah = axes('unit', 'normalized', 'position', [0 0 1 1]);
% import the background image and show it on the axes
background = imread('paint5.jpg'); imagesc(background);
% prevent plotting over the background and turn the axis off
set(ah,'handlevisibility','off','visible','off')
% making sure the background is behind all the other uicontrols
uistack(ah, 'bottom');

% Update handles structure


guidata(hObject, handles);

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


% uiwait(handles.figure1);

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


function gaussian_Callback(hObject, eventdata, handles)
global gaussian filter
if gaussian == 0
gaussian = 1;
filter = 0;
elseif gaussian == 1
gaussian = 0;
filter = 1;
end

% --- Executes on button press in load.


function load_Callback(hObject, eventdata, handles)
global videoFReader player audio Fs totalTime
[FileName,PathName] = uigetfile({'*.avi';'*.mp4';'*.mov'},'Select the MATLAB code file');
display = sprintf('%s %s', 'File:', PathName, FileName);
set(handles.file, 'String', strcat(display));
videoFReader = VideoReader(strcat(PathName,FileName));
[y, Fs] = audioread(strcat(PathName,FileName));
audiowrite('audio.wav', y, Fs);
audio = audioread('audio.wav');
totalTime = round(size(audio,1)/Fs);
player = audioplayer(audio, Fs);
set(handles.play,'Enable','on')

% --- Executes on button press in save.


function save_Callback(hObject, eventdata, handles)
% hObject handle to save (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in play.


function play_Callback(hObject, eventdata, handles)
global videoFReader thermal filter gaussian order crystal invert brightness edgedetect map convert
playpause count time verticaldilate circulardilate brightval erode motion player stopval Fs
if playpause == 0
playpause = 1;
resume(player);
elseif playpause == 1
playpause = 0;
pause(player);
end
count = count + 1;
if count == 1
time = videoFReader.CurrentTime;
end
set(handles.gaussian,'Enable','off')
set(handles.crystallize,'Enable','off')
set(handles.invert,'Enable','off')
set(handles.circular,'Enable','off')
set(handles.vertical,'Enable','off')
set(handles.brightness,'Enable','off')
set(handles.erode,'Enable','off')
set(handles.stop,'Enable','off')
set(handles.convert2gray,'Enable','off')
set(handles.motion,'Enable','off')

stopval = 0;
%videoFReader = vision.VideoFileReader(strcat(PathName,FileName));
while hasFrame(videoFReader) && playpause == 1 && stopval == 0
set(handles.gaussian,'Enable','on')
set(handles.crystallize,'Enable','on')
set(handles.invert,'Enable','on')
set(handles.circular,'Enable','on')
set(handles.vertical,'Enable','on')
set(handles.brightness,'Enable','on')
set(handles.erode,'Enable','on')
set(handles.motion,'Enable','on')
set(handles.stop,'Enable','on')
%img=read(obj,k);
%img = step(videoFReader);
videoFReader.CurrentTime = (player.CurrentSample/Fs);
img = readFrame(videoFReader);
imagesc(img, 'Parent', handles.original);
set(handles.original,'Visible','off');
if size(img,3) == 3 && playpause == 1
set(handles.convert2gray,'Enable','on')

if convert == 1
img = rgb2gray(img);
set(handles.colormenu,'Enable','on')
set(handles.thermal,'Enable','on')
set(handles.order,'Enable','on')
set(handles.edge,'Enable','on')
if thermal == 1
set(handles.thermal,'Enable','on')
set(handles.order,'Enable','off')
set(handles.edge,'Enable','off')
end
if order == 1
set(handles.thermal,'Enable','off')
set(handles.order,'Enable','on')
set(handles.edge,'Enable','on')
end
if edgedetect == 1
set(handles.thermal,'Enable','off')
set(handles.order,'Enable','on')
set(handles.edge,'Enable','on')
end
else
set(handles.colormenu,'Enable','off')
set(handles.thermal,'Enable','off')
set(handles.order,'Enable','off')
set(handles.edge,'Enable','off')
end
else
set(handles.convert2gray,'Enable','off')
end
colormap(map);
if filter == 1
imagesc(img, 'Parent', handles.filtered);
set(handles.filtered,'Visible','off');
end
if thermal == 1
img = label2rgb(gray2ind(img,255),jet(255));
imagesc(img, 'Parent', handles.filtered);
set(handles.filtered,'Visible','off');
end
if gaussian == 1
img = imgaussfilt(img, 5);
imagesc(img, 'Parent', handles.filtered);
set(handles.filtered,'Visible','off');
end
if order == 1
img = ordfilt2(img,25,true(5));
imagesc(img, 'Parent', handles.filtered);
set(handles.filtered,'Visible','off');
end
if crystal == 1
img = imopen(img,strel('disk',15));
imagesc(img, 'Parent', handles.filtered);
set(handles.filtered,'Visible','off');
end
if invert == 1
img = imcomplement(img);
imagesc(img, 'Parent', handles.filtered);
set(handles.filtered,'Visible','off');
end
if brightness == 1
img = imadjust(img, [0; 1-brightval], [0; 1],1);
imagesc(img, 'Parent', handles.filtered);
set(handles.filtered,'Visible','off');
end
if edgedetect == 1
img = edge(img,'Canny');
imagesc(img, 'Parent', handles.filtered);
set(handles.filtered,'Visible','off');
end
if verticaldilate == 1
se1 = strel('line', 11, 90);
img = imdilate(img,se1);
imagesc(img, 'Parent', handles.filtered);
set(handles.filtered,'Visible','off');
end
if circulardilate == 1
se2 = offsetstrel('ball', 5, 5);
img = imdilate(img, se2);
imagesc(img, 'Parent', handles.filtered);
set(handles.filtered,'Visible','off');
end
if erode == 1
se3 = offsetstrel('ball', 5, 5);
img = imerode(img, se3);
imagesc(img, 'Parent', handles.filtered);
set(handles.filtered,'Visible','off');
end
if motion == 1
img = imfilter(img, fspecial('motion', 50, 45));
imagesc(img, 'Parent', handles.filtered);
set(handles.filtered,'Visible','off');
end
pause(1/videoFReader.FrameRate);

end

% --- Executes on button press in thermal.


function thermal_Callback(hObject, eventdata, handles)
global thermal filter order edgedetect
if thermal == 0
order = 0;
edgedetect = 0;
set(handles.order,'Enable','off');
set(handles.edge,'Enable','off');
thermal = 1;
filter = 0;
elseif thermal == 1
set(handles.order,'Enable','on');
set(handles.edge,'Enable','on');
thermal = 0;
filter = 1;
end
% hObject handle to thermal (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 thermal

% --- Executes on button press in order.


function order_Callback(hObject, eventdata, handles)
global order filter thermal
if order == 0
thermal = 0;
set(handles.thermal,'value', 0);
set(handles.thermal,'Enable','off');
order = 1;
filter = 0;
elseif order == 1
set(handles.thermal,'Enable','on');
order = 0;
filter = 1;
end

% --- Executes on button press in crystallize.


function crystallize_Callback(hObject, eventdata, handles)
global crystal filter
if crystal == 0
crystal = 1;
filter = 0;
elseif crystal == 1
crystal = 0;
filter = 1;
end

% --- Executes on button press in invert.


function invert_Callback(hObject, eventdata, handles)
global invert filter
if invert == 0
invert = 1;
filter = 0;
elseif invert == 1
invert = 0;
filter = 1;
end

% --- Executes on button press in edge.


function edge_Callback(hObject, eventdata, handles)
global edgedetect filter thermal
if edgedetect == 0
thermal = 0;
set(handles.thermal,'value', 0);
set(handles.thermal,'Enable','off');
edgedetect = 1;
filter = 0;
elseif edgedetect == 1
set(handles.thermal,'Enable','on');
edgedetect = 0;
filter = 1;
end

% --- Executes on selection change in colormenu.


function colormenu_Callback(hObject, eventdata, handles)
global map
colorvalue = get(handles.colormenu, 'Value');

if colorvalue == 1
map = gray;
elseif colorvalue == 2
map = parula;
elseif colorvalue == 3
map = hsv;
elseif colorvalue == 4
map = hot;
elseif colorvalue == 5
map = cool;
elseif colorvalue == 6
map = spring;
elseif colorvalue == 7
map = summer;
elseif colorvalue == 8
map = autumn;
elseif colorvalue == 9
map = winter;
elseif colorvalue == 10
map = bone;
elseif colorvalue == 11
map = copper;
elseif colorvalue == 12
map = pink;
elseif colorvalue == 13
map = lines;
elseif colorvalue == 14
map = colorcube;
elseif colorvalue == 15
map = prism;
elseif colorvalue == 16
map = flag;
elseif colorvalue == 17
map = white;
end

% --- Executes during object creation, after setting all properties.


function colormenu_CreateFcn(hObject, eventdata, handles)
% hObject handle to colormenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in convert2gray.


function convert2gray_Callback(hObject, eventdata, handles)
global convert thermal order edge
if convert == 0
convert = 1;
elseif convert == 1
convert = 0;
thermal = 0;
order = 0;
edge = 0;
set(handles.thermal,'value', 0)
set(handles.order,'value', 0)
set(handles.edge,'value', 0)
end

% --- Executes on button press in stop.


function stop_Callback(hObject, eventdata, handles)
global videoFReader convert playpause player count time thermal motion order circulardilate edgedetect
gaussian invert verticaldilate erode crystal filter imgcount stopval
stopval = 1;
imgcount = 0;
playpause = 0;
videoFReader.CurrentTime = time;
count = 0;
thermal = 0;
motion = 0;
order = 0;
circulardilate = 0;
edgedetect = 0;
gaussian = 0;
crystal = 0;
invert = 0;
verticaldilate = 0;
erode = 0;
filter = 1;
convert = 0;
stop(player);
stop(player);
set(handles.thermal,'Enable','off')
set(handles.gaussian,'Enable','off')
set(handles.crystallize,'Enable','off')
set(handles.invert,'Enable','off')
set(handles.circular,'Enable','off')
set(handles.vertical,'Enable','off')
set(handles.brightness,'Enable','off')
set(handles.erode,'Enable','off')
set(handles.convert2gray,'Enable','off')
set(handles.colormenu,'Enable','off')
set(handles.motion,'Enable','off')
set(handles.stop,'Enable','off')
set(handles.thermal,'value', 0)
set(handles.motion,'value', 0)
set(handles.order,'value', 0)
set(handles.circular,'value', 0)
set(handles.edge,'value', 0)
set(handles.gaussian,'value', 0)
set(handles.crystallize,'value', 0)
set(handles.invert,'value', 0)
set(handles.vertical,'value', 0)
set(handles.erode,'value', 0)
set(handles.convert2gray,'value', 0)

% --- Executes on slider movement.


function brightness_Callback(hObject, eventdata, handles)
global brightval brightness
brightness = 1;
bright = get(handles.brightness, 'Value');
if bright == 1
brightval = bright - 0.1;
else
brightval = bright;
end

% --- Executes during object creation, after setting all properties.


function brightness_CreateFcn(hObject, eventdata, handles)
% hObject handle to brightness (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.


if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end

% --- Executes on button press in vertical.


function vertical_Callback(hObject, eventdata, handles)
global verticaldilate filter
if verticaldilate == 0
verticaldilate = 1;
filter = 0;
elseif verticaldilate == 1
verticaldilate = 0;
filter = 1;
end

% --- Executes on button press in circular.


function circular_Callback(hObject, eventdata, handles)
global circulardilate filter
if circulardilate == 0
circulardilate = 1;
filter = 0;
elseif circulardilate == 1
circulardilate = 0;
filter = 1;
end

% --- Executes on button press in erode.


function erode_Callback(hObject, eventdata, handles)
global erode filter
if erode == 0
erode = 1;
filter = 0;
elseif erode == 1
erode = 0;
filter = 1;
end

% --- Executes on button press in motion.


function motion_Callback(hObject, eventdata, handles)
global motion filter
if motion == 0
motion = 1;
filter = 0;
elseif motion == 1
motion = 0;
filter = 1;
end

function VidFil_CloseRequestFcn(hObject, eventdata, handles)


global play
play = 0;

% --- If Enable == 'on', executes on mouse press in 5 pixel border.


% --- Otherwise, executes on mouse press in 5 pixel border or over brightness.
function brightness_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to brightness (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

Você também pode gostar