Showing posts with label Pengolahan Citra. Show all posts
Showing posts with label Pengolahan Citra. Show all posts

Manipulasi Citra

 Tampilan figure dengan 4 subplot:

Subplot 1: Citra asli.
Subplot 2: Citra threshold 100.
Subplot 3: Citra threshold 150, lalu lakukan flip vertikal.
Subplot 4: Flip horizontal dari citra asli, lalu lakukan brightness + 80.

mancit

clear;
citra_asli=imread('gambar.jpg');
citra_gray=rgb2gray(citra_asli);
citra_gray=double(citra_gray);
[b k]=size(citra_gray);
for x=1:b
for y=1:k
if citra_gray(x,y)=100
citra_threshold_100(x,y)=1;
end
if citra_gray(x,y)=150
citra_threshold_150(x,y)=1;
end

end
end
[b k c]=size(citra_gray);
for x=1:1:b
for y=1:1:k
for z=1:1:c
citra_flip_vertikal_150(x,y,z)=citra_threshold_150((b-x)+1,y,z);

end
end
end
temp=citra_asli;
[b k c]=size(citra_asli);
for x=1:1:b
for y=1:1:k
for z=1:1:c
citra_flip_horizontal(x,y,z)=temp(x,(k-y)+1,z);

end
end
end

citra_brightness= citra_flip_horizontal+80;
citra_brightness=uint8(citra_brightness);

subplot(2,2,1);
imshow(citra_asli),title('Citra Asli');
subplot(2,2,2);
imshow(citra_threshold_100),title('Citra Threshold 100');
subplot(2,2,3);
imshow(citra_flip_vertikal_150),title('Citra Threshold 150 Flip Vertikal');
subplot(2,2,4);
imshow(citra_brightness),title('Citra Flip Horizontal dengan Brightness+80');

Read More..

Citra RGB

 rgb


clear;
citra(:,:,1)=[ 125 0 200 0 100 0 255 255;
255 0 100 0 0 0 0 255;
255 0 0 0 0 0 0 0;
0 120 0 0 0 0 0 0;
125 0 0 0 0 0 0 0;
0 200 0 0 0 0 0 0;
125 0 255 0 0 125 0 0;
0 0 120 0 0 253 0 0;
]
citra(:,:,2)=[ 0 255 0 255 0 255 0 255 ;
255 200 0 200 255 125 255 0 ;
0 120 0 0 0 0 0 0 ;
255 0 0 200 255 125 0 0 ;
0 255 240 0 200 255 0 0 ;
200 0 125 0 0 0 0 0 ;
0 0 0 200 255 125 125 255 ;
100 200 0 0 255 0 0 129 ;
]
citra(:,:,3)=[ 0 0 0 0 200 0 0 0;
0 0 0 0 255 0 0 255;
255 0 255 0 0 0 0 0;
255 0 200 0 0 125 0 0;
0 0 240 255 0 0 0 0;
0 120 255 0 0 0 0 0;
0 200 0 200 255 0 0 255;
125 0 0 200 120 0 120 120;]
citra=uint8(citra);
disp(citra);
subplot(2,1,1);
imshow(citra), title('Citra Huruf E dimensi 8x8x3 ');

Read More..

Citra Negatif

 Tampilan Figure dengan 4 subplot:

• Subplot 1: Citra Asli
• Subplot 2: Negatif dari citra asli.
• Subplot 3: Negatif dari citra asli hanya pada sisi setengah atas citra.(lihat contoh program terakhir).
• Subplot 4: Histogram dari citra pada subplot ke 3.

nega


citra_asli=double(imread('gambar.jpg'));
citra_negatif=255-citra_asli;
[b k c]=size(citra_asli);
half_width=round(k/2);
for x=1:b
for y=1:k
for z=1:c
if x=half_width
citra_half_negatif(x,y,z)=citra_asli(x,y,z);
end
end
end
end
citra_asli=uint8(citra_asli);
citra_negatif=uint8(citra_negatif);
citra_half_negatif=uint8(citra_half_negatif);
subplot(2,2,1);
imshow(citra_asli),title('Citra Asli');
subplot(2,2,2);
imshow(citra_negatif),title('Citra Negatif');
subplot(2,2,3);
imshow(citra_half_negatif),title('Citra Setengah Negatif');
subplot(2,2,4);
imhist(citra_half_negatif(:,:,1));
imhist(citra_half_negatif(:,:,2));
imhist(citra_half_negatif(:,:,3));
title('Histogram Citra Setengah Negatif');
Read More..

Citra GUI

Mengubah kode program pada contoh axes,dengan menambahkan dua buah tombol, untuk Citra Negatif dan Citra Grayscale. Jika tombol ini diklik, maka citra yang tampil dalam axes akan berubah menjadi grayslace atau negatif. Sehingga program mempunyai 3 tombol: untuk brightness, negatif dan grayscale

Berikut caranya:
1. Buka GUIDE matlab, lalu rancang tampilan GUIDE Matlab seperti gambar di bawah ini:

gui


2. Untuk Property Inspector, Ubah menjadi:
 
No.Objek Type Property Value
1. Axes Tag axes_citra
    XTick [] (dikosongkan)
    YTick [] (dikosongkan)
2. Static Text String Input Nilai
3. Edit Text Tag input_nilai
    String [] (dikosongkan)
4. Push Button Tag brightness
    String Brightness
5. Push Button Tag negatif
    String Negatif
6. Push Button Tag grayscale
    String Grayscale

 lalu save GUI

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

% Last Modified by GUIDE v2.5 09-Jan-2013 12:39:25

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

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

% Update handles structure
guidata(hObject, handles);

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

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

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

% Hints: get(hObject,'String') returns contents of input_nilai as text
% str2double(get(hObject,'String')) returns contents of input_nilai as a double

% --- Executes during object creation, after setting all properties.
function input_nilai_CreateFcn(hObject, eventdata, handles)
% hObject handle to input_nilai (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit 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 brightness.
function brightness_Callback(hObject, eventdata, handles)
varargout{1} = handles.output;
citra_asli=imread('bunga1.jpg');
citra_hasil=double(citra_asli);
nilai_brightness=str2num(get(handles.input_nilai,'String'));
citra_hasil=citra_hasil+nilai_brightness;
citra_hasil=uint8(citra_hasil);
axes(handles.axes_citra);
imshow(citra_hasil);

% 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)

% --- Executes on button press in negatif.
function negatif_Callback(hObject, eventdata, handles)
varargout{1} = handles.output;
citra_asli=imread('bunga1.jpg');
citra_hasil=double(citra_asli);
citra_hasil=255-citra_asli;
citra_hasil=uint8(citra_hasil);
axes(handles.axes_citra);
imshow(citra_hasil);

% hObject handle to negatif (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 grayscale.
function grayscale_Callback(hObject, eventdata, handles)
varargout{1} = handles.output;
citra_asli=imread('bunga1.jpg');
citra_hasil=double(citra_asli);
citra_hasil=rgb2gray(citra_asli);
axes(handles.axes_citra);
imshow(citra_hasil);

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



Output:

Gambar Brightness:

gui1

Gambar Negatif

gui2

Gambar Grayscale:

gui3

Read More..

Citra Brightness

Tampilan Figure dengan 4 subplot:
• Subplot 1: Citra Asli 
• Subplot 2: Representasi Yellow (Red+Blue) + Brightness 150 
• Subplot 3: Representasi Cyan (Red+Green) + Brightness 50 
• Subplot 4: Representasi Magenta ( Blue+Green) + Brightness -80
citra_asli=imread('water.jpg'); 
subplot(2,2,1); 
imshow(citra_asli),title('Citra Asli'); 
red(:,:,1)=[0]; 
green(:,:,2)=[0]; 
blue=citra_asli; 
yellow=double(1-blue);
yellow=citra_asli+150;
subplot(2,2,2); 
imshow(yellow),title('Representasi Yellow (R+B)+Brightness 150'); 
red=citra_asli; 
green(:,:,1)=[0]; 
blue(:,:,3)=[0]; 
cyan=double(1-red); 
cyan=citra_asli+50; 
subplot(2,2,3);
imshow(cyan),title('Representasi Cyan(R+G)+Brightness 50'); 
subplot(2,2,4);
red(:,:,1)=[0];
green=citra_asli; 
blue(:,:,1)=[0];
magenta=double(1-green);
magenta=citra_asli-80; 
imshow(magenta),title(' Representasi Magenta(B+G)+Brightness -80');
Read More..