7
   A 8, 2012 @. , ECEE EA CA EC , . B , . : : D , . :    −  −    ≤      ≤   , AAB. B .

Piecewise Linear Contrast Stretching

Embed Size (px)

Citation preview

Page 1: Piecewise Linear Contrast Stretching

5/16/2018 Piecewise Linear Contrast Stretching - slidepdf.com

http://slidepdf.com/reader/full/piecewise-linear-contrast-stretching 1/7

 

[digital image processing]  April 8, 2012 

[email protected]{ee ugm, indonesia}

PIECEWISE LINEAR CONTRAST STRETCHING

Pada dasarnya metode ini memiliki tujuan yang sama dengan metode contrast stretching

lainnya, yakni untuk memperlebar dynamic range. Bedanya dalam metode ini, sudah ada kurva

tertentu yang diikuti dalam pengaturan kontrasnya. Perhatikan gambar di bawah ini:

Sumber: Digital Image Processing, Gonzalez.

Kita menurunkan rumus berdasarkan kurva di atas:

1 → =

0 ≤ ≤  

2 → = −

. + ≤ ≤  

3 → =255 −

255 −

. + ≤ ≤ 255 Untuk mengaplikasikan metode di atas, saya membuat GUI dengan menggunakan MATLAB.

Berikut ini tampilan dari GUInya.

Page 2: Piecewise Linear Contrast Stretching

5/16/2018 Piecewise Linear Contrast Stretching - slidepdf.com

http://slidepdf.com/reader/full/piecewise-linear-contrast-stretching 2/7

 

[digital image processing]  April 8, 2012 

[email protected]{ee ugm, indonesia}

Program Matlabnya untuk proses sesuai rumus di atas adalah

function [myhist,PWl,newI]=PieceWiseStretch() global r1 global r2 

global s1 global s2 global I 

%% we use x1 and x2 as value to find y % operasi bisa untuk nilai double 

% ini diskret rr1=0:r1; rr2=r1:r2; rr3=r2:255; 

% segment garis 

L1=s1/r1; L2=(s2-s1)/(r2-r1); L3=(255-s2)/(255-r2); 

K1=floor(L1*rr1); K2=floor(s1+(L2*(rr2-r1))); K3=floor(s2+(L3*(rr3-r2))); 

% piecewise line (transformation) PWl=[K1 K2 K3]; I=double(I); 

I1=I<=r1; I2=(I>r1)&(I<r2); I3=I>=r2; 

I1=I1.*floor(L1*I); I2=I2.*floor(s1+(L2*(I-r1))); I3=I3.*floor(s2+(L3*(I-r2))); 

newI=I1+I2+I3; newI=uint8(newI); myhist=imhist(newI); %%

Page 3: Piecewise Linear Contrast Stretching

5/16/2018 Piecewise Linear Contrast Stretching - slidepdf.com

http://slidepdf.com/reader/full/piecewise-linear-contrast-stretching 3/7

 

[digital image processing]  April 8, 2012 

[email protected]{ee ugm, indonesia}

Program untuk GUInya adalah

% --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) global hist1 

global I global plotbar global r1 global r2 global s1 global s2 

try % membaca data dari gui open file [filename, pathname] = uigetfile('*.jpg','Pilih Citra'); I = imread([pathname filename]); 

% ubah ke grayscale 

[x,y,z]=size(I); if z>1 

I=rgb2gray(I); end % 

% menampilkan di axes4 imshow(I,'Parent',handles.axes4); % menampilkan di axes 5 imshow(I,'Parent',handles.axes5); % 

% histogram hist1=imhist(I); % 

% aktifkan kembali pilihan bar dan plot set(handles.radiobutton3,'Enable','On'); set(handles.radiobutton4,'Enable','On'); % 

% Memilih apakah histogram ditampilkan dalam bentu bar atau plot % set(handles.radiobutton4,'Value',1); plotbar=get(handles.radiobutton4,'Value'); 

plot(hist1,'Parent',handles.axes7); % 

% ambli nilai dari slider r1=round(get(handles.slider1,'Value')); r2=round(get(handles.slider3,'Value')); s1=round(get(handles.slider4,'Value')); s2=round(get(handles.slider5,'Value')); % 

% menampilkan transformasi awal % [myhist,PWl,newI]=PieceWiseStretch(); axes(handles.axes6); 

awal(); % plot(PWl,'Parent');

% penampil(); 

Page 4: Piecewise Linear Contrast Stretching

5/16/2018 Piecewise Linear Contrast Stretching - slidepdf.com

http://slidepdf.com/reader/full/piecewise-linear-contrast-stretching 4/7

 

[digital image processing]  April 8, 2012 

[email protected]{ee ugm, indonesia}

catch end 

% --- Executes on button press in pushbutton2. 

function pushbutton2_Callback(hObject, eventdata, handles) % hObject handle to pushbutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) [myhist,PWl,newI]=PieceWiseStretch();  [filename, pathname] = uiputfile('*.jpg', 'Simpan Citra'); if filename ~= 0 

imwrite(newI,[pathname filename]) end 

% --- Executes on slider movement. function slider1_Callback(hObject, eventdata, handles) global r1 global plotbar 

r1=round(get(hObject,'Value')); set(hObject,'TooltipString',num2str(r1)); set(handles.edit1,'String',r1); [myhist,PWl,newI]=PieceWiseStretch();  

imshow(newI,'Parent',handles.axes5); plot(PWl,'Parent',handles.axes6); penampil(); 

if plotbar==1 plot(myhist,'b','Parent',handles.axes7); 

else bar(myhist,'b','Parent',handles.axes7); 

end 

% --- Executes on slider movement. function slider3_Callback(hObject, eventdata, handles) global r2 global plotbar 

r2=round(get(hObject,'Value')); set(hObject,'TooltipString',num2str(r2)); set(handles.edit2,'String',r2); [myhist,PWl,newI]=PieceWiseStretch();  

imshow(newI,'Parent',handles.axes5); plot(PWl,'Parent',handles.axes6);

penampil(); if plotbar==1 

plot(myhist,'b','Parent',handles.axes7); else 

bar(myhist,'b','Parent',handles.axes7); end

Page 5: Piecewise Linear Contrast Stretching

5/16/2018 Piecewise Linear Contrast Stretching - slidepdf.com

http://slidepdf.com/reader/full/piecewise-linear-contrast-stretching 5/7

 

[digital image processing]  April 8, 2012 

[email protected]{ee ugm, indonesia}

% --- Executes on slider movement. function slider4_Callback(hObject, eventdata, handles) global s1 global plotbar 

s1=round(get(hObject,'Value')); 

set(hObject,'TooltipString',num2str(s1)); set(handles.edit3,'String',s1); [myhist,PWl,newI]=PieceWiseStretch();  

imshow(newI,'Parent',handles.axes5); plot(PWl,'Parent',handles.axes6); penampil(); if plotbar==1 

plot(myhist,'b','Parent',handles.axes7); else 

bar(myhist,'b','Parent',handles.axes7); end 

% --- Executes on slider movement. function slider5_Callback(hObject, eventdata, handles) global s2; global plotbar; 

s2=round(get(hObject,'Value')); set(hObject,'TooltipString',num2str(s2)); set(handles.edit4,'String',s2); [myhist,PWl,newI]=PieceWiseStretch();  

imshow(newI,'Parent',handles.axes5); 

plot(PWl,'Parent',handles.axes6); penampil(); if plotbar==1 

plot(myhist,'b','Parent',handles.axes7); else 

bar(myhist,'b','Parent',handles.axes7); end 

function [myhist,PWl,newI]=PieceWiseStretch() global r1 global r2 

global s1 global s2 global I 

%% we use x1 and x2 as value to find y % operasi bisa untuk nilai double 

% ini diskret rr1=0:r1; rr2=r1:r2; rr3=r2:255; 

% segment garis L1=s1/r1; L2=(s2-s1)/(r2-r1); 

Page 6: Piecewise Linear Contrast Stretching

5/16/2018 Piecewise Linear Contrast Stretching - slidepdf.com

http://slidepdf.com/reader/full/piecewise-linear-contrast-stretching 6/7

 

[digital image processing]  April 8, 2012 

[email protected]{ee ugm, indonesia}

L3=(255-s2)/(255-r2); 

K1=floor(L1*rr1); K2=floor(s1+(L2*(rr2-r1))); K3=floor(s2+(L3*(rr3-r2))); 

% piecewise line (transformation) PWl=[K1 K2 K3]; I=double(I); 

I1=I<=r1; I2=(I>r1)&(I<r2); I3=I>=r2; 

I1=I1.*floor(L1*I); I2=I2.*floor(s1+(L2*(I-r1))); I3=I3.*floor(s2+(L3*(I-r2))); 

newI=I1+I2+I3; newI=uint8(newI); myhist=imhist(newI); 

Hasil eksekusi dari program di atas adalah

Page 7: Piecewise Linear Contrast Stretching

5/16/2018 Piecewise Linear Contrast Stretching - slidepdf.com

http://slidepdf.com/reader/full/piecewise-linear-contrast-stretching 7/7

 

[digital image processing]  April 8, 2012 

[email protected]{ee ugm, indonesia}

Hasil kontras stretching nya adalah

Ketentuan dalam piecewise adalah

  Lokasi dari (r1,s1) dan (r2,s2) menentukan bentuk dari fungsi transformasinya.

  Jika r1=s1 dan r2=s2 transformasinya merupakan fungsi linier dan tidak 

menghasilkan perubahan apa-apa pada citra output.

  Jika r1=r2, s1=0 dan s2=L-1, transformasinya menjadi fungsi pengambangan

(thresholding) yang menghasilkan citra biner(hitam-putih) pada output.

  Nilai Intermediate dari (r1,s1) dan (r2,s2) menghasilkan tingkat persebaran yang

beragam dalam level abu-abu pada citra output, sehingga mempengaruhi ke-

kontras-annya.

  Biasanya nilai diasumsikan seperti r1≤r2 and s1≤s2.

Sumber:

http://www.codeproject.com/Articles/34678/Linear-Contrast-Stretch-of-Grayscale-Images

http://shivasoft.in/nikhilesh/?p=129 

Before After