Model Ruang Warna Pengolahan Citra


Dalam bidang pengolahan citra digital dikenal berbagai macam ruang warna (color space) citra.

Yang paling umum adalah ruang warna RGB (Red, Green, Blue).

Ruang warna RGB mendefinisikan suatu warna berdasarkan tiga kanal (channel) warna yaitu merah, hijau, dan biru.

Ruang warna RGB untuk citra truecolor 24 bit diilustrasikan oleh gambar berikut:
CK_color_cube
Ruang warna yang kedua yaitu ruang warna HSV (Hue, Saturation, Value).

Hue merupakan suatu nilai yang merepresentasikan spektrum warna dari cahaya tampak (merah, jingga, kuning, hijau, biru, dan ungu).

Saturation merupakan nilai yang menunjukkan tingkat kejenuhan atau kemurnian dari suatu warna. Semakin besar nilai saturasi maka semakin murni warna yang dihasilkan.

Sedangkan value dapat didefinisikan sebagai nilai yang menunjukkan tingkat kecerahan warna.

Ruang warna HSV diperoleh dari ruang warna RGB melalui persamaan berikut:
hsv2Ruang warna HSV diilustrasikan pada gambar di bawah ini:
imagesRuang warna yang ketiga yaitu ruang warna NSTC atau YIQ terdiri dari luminance (Y) dan chrominance (I dan Q).

Persamaan yang digunakan untuk mengkonversi ruang warna RGB menjadi NTSC adalah:
ntsc

Ruang warna NTSC diilustrasikan pada gambar berikut:

yiqdemo
Ruang warna yang keempat adalah ruang warna YCbCr  yang terdiri dari luminance (Y) dan chrominance (Cb dan Cr).

Persamaan yang digunakan untuk mengkonversi ruang warna RGB menjadi ruang warna YCbCr adalah:
ycbcr
Sedangkan ilustrasi ruang warna YCbCr ditunjukkan pada gambar berikut:

YCbCrColorSpace_Perspective2

Berikut ini merupakan contoh pemrograman GUI Matlab untuk mengkonversi ruang warna citra RGB menjadi ruang warna yang lain.

Tahapan-tahapannya antara lain:

1. Baca Citra RGB
1

2. Menampilkan citra RGB beserta masing-masing kanal dan histogramnya
2

3. Menampilkan citra HSV beserta masing-masing kanal dan histogramnya
3

4. Menampilkan citra NTSC beserta masing-masing kanal dan histogramnya
4

5. Menampilkan citra YCbCr beserta masing-masing kanal dan histogramnya
5

Source code dan citra untuk mengkonversi ruang warna citra dapat diunduh pada link berikut: link

Sedangkan tampilan koding matlab nya yaitu:

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

% Last Modified by GUIDE v2.5 08-Jun-2016 13:51:22

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
'gui_Singleton',  gui_Singleton, ...
'gui_OpeningFcn', @Color_Conversion_OpeningFcn, ...
'gui_OutputFcn',  @Color_Conversion_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 Color_Conversion is made visible.
function Color_Conversion_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 Color_Conversion (see VARARGIN)

% Choose default command line output for Color_Conversion
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);
movegui(hObject,'center');

% UIWAIT makes Color_Conversion wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = Color_Conversion_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)
[filename, pathname] = uigetfile({'*.*'});

if ~isequal(filename,0)
Img = imread(fullfile(pathname,filename));
info = imfinfo(fullfile(pathname,filename));
bitdepth = info.BitDepth;
if bitdepth ==24
axes(handles.axes1)
imshow(Img)
set(handles.popupmenu1,'enable','on')
set(handles.popupmenu1,'Value',1)
else
errordlg('Image must be RGB','File Error');
end
else
return
end

handles.Img = Img;
guidata(hObject, handles);


% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu1
Img = handles.Img;
val = get(hObject,'Value');

switch val
case 1
axes(handles.axes1)
imshow(Img)
R = Img(:,:,1);
axes(handles.axes2)
imshow(R)
axes(handles.axes5)
imhist(R)
G = Img(:,:,2);
axes(handles.axes3)
imshow(G)
axes(handles.axes6)
imhist(G)
B = Img(:,:,3);
axes(handles.axes4)
imshow(B)
axes(handles.axes7)
imhist(B)
case 2
HSV = rgb2hsv(Img);
axes(handles.axes1)
imshow(HSV)
H = HSV(:,:,1);
axes(handles.axes2)
imshow(H)
axes(handles.axes5)
imhist(H)
S = HSV(:,:,2);
axes(handles.axes3)
imshow(S)
axes(handles.axes6)
imhist(S)
V = HSV(:,:,3);
axes(handles.axes4)
imshow(V)
axes(handles.axes7)
imhist(V)
case 3
NTSC = rgb2ntsc(Img);
axes(handles.axes1)
imshow(NTSC)
Y = NTSC(:,:,1);
axes(handles.axes2)
imshow(Y)
axes(handles.axes5)
imhist(Y)
I = NTSC(:,:,2);
axes(handles.axes3)
imshow(I)
axes(handles.axes6)
imhist(I)
Q = NTSC(:,:,3);
axes(handles.axes4)
imshow(Q)
axes(handles.axes7)
imhist(Q)
case 4
YCbCr = rgb2ycbcr(Img);
axes(handles.axes1)
imshow(YCbCr)
Y = YCbCr(:,:,1);
axes(handles.axes2)
imshow(Y)
axes(handles.axes5)
imhist(Y)
Cb = YCbCr(:,:,2);
axes(handles.axes3)
imshow(Cb)
axes(handles.axes6)
imhist(Cb)
Cr = YCbCr(:,:,3);
axes(handles.axes4)
imshow(Cr)
axes(handles.axes7)
imhist(Cr)
end

% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (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

Save

Save

Save

Save

Save

Posted on June 8, 2016, in Pengolahan Citra and tagged , , , , , , , , , , , , , , , , , , , , , , , , , , , , , . Bookmark the permalink. 3 Comments.

  1. kang, maksud di line 176, 179, 181 dan 186 itu apa ya ?
    itu matriks kah ?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: