function varargout = ColorClassification(varargin)
% COLORCLASSIFICATION M-file for ColorClassification.fig
% COLORCLASSIFICATION, by itself, creates a new COLORCLASSIFICATION or raises the existing
% singleton*.
%
% H = COLORCLASSIFICATION returns the handle to a new COLORCLASSIFICATION or the handle to
% the existing singleton*.
%
% COLORCLASSIFICATION('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in COLORCLASSIFICATION.M with the given input arguments.
%
% COLORCLASSIFICATION('Property','Value',...) creates a new COLORCLASSIFICATION or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before ColorClassification_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to ColorClassification_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 ColorClassification
% Last Modified by GUIDE v2.5 21-Feb-2013 20:24:59
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ColorClassification_OpeningFcn, ...
'gui_OutputFcn', @ColorClassification_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
function ShowRGB(hObject, eventdata, handles)
R = get(handles.s_R,'Value');
G = get(handles.s_G,'Value');
B = get(handles.s_B,'Value');
handles.im(:,:,1) = R/255.0;
handles.im(:,:,2) = G/255.0;
handles.im(:,:,3) = B/255.0;
gray = floor(0.299*R + 0.587 * G + 0.114 * B);
set(handles.s_Gray,'Value',gray);
set(handles.t_Gray,'string',num2str(gray));
x = (rgb2hsv([R G B]));
set(handles.s_H,'Value',x(1));
set(handles.s_S,'Value',x(2));
set(handles.s_V,'Value',x(3));
set(handles.t_H,'string',num2str(x(1)));
set(handles.t_S,'string',num2str(x(2)));
set(handles.t_V,'string',num2str(x(3)));
imshow(handles.im);
function ShowHSV(hObject, eventdata, handles)
H = get(handles.s_H,'Value');
S = get(handles.s_S,'Value');
V = get(handles.s_V,'Value');
[R G B] = hsv2rgb([H S V]);
handles.im(:,:,1) = R/255.0;
handles.im(:,:,2) = G/255.0;
handles.im(:,:,3) = B/255.0;
gray = floor(0.299*R + 0.587 * G + 0.114 * B);
set(handles.s_Gray,'Value',gray);
set(handles.t_Gray,'string',num2str(gray));
set(handles.s_R,'Value',R);
set(handles.s_G,'Value',G);
set(handles.s_B,'Value',B);
set(handles.t_R,'string',num2str(R));
set(handles.t_G,'string',num2str(G));
set(handles.t_B,'string',num2str(B));
imshow(handles.im);
% --- Executes just before ColorClassification is made visible.
function ColorClassification_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 ColorClassification (see VARARGIN)
x = zeros(300,300,3);
handles.im = x;
imshow(handles.im);
% Choose default command line output for ColorClassification
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes ColorClassification wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = ColorClassification_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 slider movement.
function s_R_Callback(hObject, eventdata, handles)
% hObject handle to s_R (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.t_R, 'string', num2str(floor(get(hObject,'Value'))));
ShowRGB(hObject, eventdata, handles)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% --- Executes during object creation, after setting all properties.
function s_R_CreateFcn(hObject, eventdata, handles)
% hObject handle to s_R (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 slider movement.
function s_G_Callback(hObject, eventdata, handles)
% hObject handle to s_G (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.t_G, 'string', num2str(floor(get(hObject,'Value'))));
ShowRGB(hObject, eventdata, handles)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% --- Executes during object creation, after setting all properties.
function s_G_CreateFcn(hObject, eventdata, handles)
% hObject handle to s_G (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 slider movement.
function s_B_Callback(hObject, eventdata, handles)
% hObject handle to s_B (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.t_B, 'string', num2str(floor(get(hObject,'Value'))));
ShowRGB(hObject, eventdata, handles)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% --- Executes during object creation, after setting all properties.
function s_B_CreateFcn(hObject, eventdata, handles)
% hObject handle to s_B (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 slider movement.
function s_H_Callback(hObject, eventdata, handles)
% hObject handle to s_H (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.t_H, 'string', num2str((get(hObject,'Value'))));
ShowHSV(hObject, eventdata, handles);
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% --- Executes during object creation, after setting all proper