This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Pages

Selasa, 25 Juli 2017

Pengolahan Citra Digital


 
Ada tiga jenis citra yang umum yang digunakan dalam pemrosesan citra yaitu
ü  citra berwarna
ü  citra berskala keabuan
ü   citra biner.
citra berwarna atau dinamakan citra RGB, merupakan jenis citra yang menyajikan warna dalam bentuk komponen R(merah), G(hijau), B(biru). Setiap komponen warna menggunakan 8bit nilainya berkisar 0 sampai 255. sehingga kemungkinan warna yang dapat disajikan 255 x 255 x 255 = 16.581.375 warna.
y=imread('c:\image\warna.jpg');
x=imread('c:\image\warna.jpg');
x(:,:,1)=2 * x(:,:,1);
subplot(1,2,1);imshow(y)
subplot(1,2,2);imshow(x)

y=imread('c:\image\warna.jpg');
x=imread('c:\image\warna.jpg');
x(:,:,2)=2 * x(:,:,2);
subplot(1,2,1);imshow(y)
subplot(1,2,2);imshow(x)

y=imread('c:\image\warna.jpg');
x=imread('c:\image\warna.jpg');
x(:,:,3)=2 * x(:,:,3);
subplot(1,2,1);imshow(y)
subplot(1,2,2);imshow(x)

Hasilnya,,,


Program Citra Berwarna
a=imread('c:\image\bola.png');
 red=a(:,:,1);
 green=a(:,:,2);
 blue=a(:,:,3);
 subplot(2,2,1);imshow(a),title('tiga bola')
 subplot(2,2,2);imshow(red),title('tiga bola ungu')
 subplot(2,2,3);imshow(green),title('tiga bola merah')
 subplot(2,2,4);imshow(blue),title('tiga bola hijau')

UPB>> x=imread('c:\image\bola.png');
UPB>> z=x + 80 ;
UPB>> subplot(1,2,1);imshow(x)
UPB>> subplot(1,2,2);imshow(z)
UPB>> y=2.5 * x;
UPB>> subplot(2,2,1);imshow(x)
UPB>> subplot(2,2,1);imshow(x)
UPB>> subplot(2,2,2);imshow(z)
UPB>> subplot(2,2,3);imshow(y)

UPB>> figure(1);imshow(x)
UPB>> figure(1);imshow(x)
UPB>> figure(2);imshow(z)
UPB>> figure(3);imshow(y)


Hasilnya,,,


Mengkonversi citra berwarna ke abu abu dan biner

Dalam praktik citra berwarna seringkali harus dikonversi kedalam bentuk citra berskala keabuan mengingat banyak pemrosesan citra yang bekerja pada skala keabuan.namun citra keabuan juga perlu dikonversi kecitra bine, karena operasi dalam pemrosesan citra berjalan pada citra biner.
            I=a x R+ b xG + c x B, a+b+c=1
            misalkan R=50, G=70 dan B=61 maka diiperoleh hasil sbb I=(50 +70+ 60)/3 =60

RGB=imread('C:\Image\warna.jpg');
YCBCR = rgb2ntsc(RGB);
Y=YCBCR(:,:,1); %Ekstraksi matriks Y
Cb=YCBCR(:,:,2); %Ekstraksi matriks Bc
Cr=YCBCR(:,:,3); %Ekstraksi matriks Br
subplot(2,2,1); imshow(RGB);
subplot(2,2,2); imshow(Y);

subplot(2,2,3); imshow(Cb);
subplot(2,2,4); imshow(Cr);


Hasilnya,,,,

 
Program histogram citra keabuan

Histogram citra merupakan diagram yang menggambarkan frekuensi setiap nilai intensitas yang
muncul diseluruh piksel citra. Nilai besar menyatakan bahwa piksel-piksel yang mempunyai
intensitas tersebut sangat banyak.
            Pada citra berskala keabuan, jumlah aras keabuan (biasa disimbolkan dengan L) sebanyak 256. Nilai aras dimulai dari 0 hingga 255. Adapun histogram untuk suatu aras dinyatakan dengan hist(k+1) dengan k menyatakan nilai aras (0 sampai dengan L-1). Jadi,hist(k+1) menyatakan jumlah piksel yang bernilai k. Penggunaan k+1 pada hist diperlukan mengingat dalam Octave dan MATLAB tidak ada indeks nol atau hist(0).

img=imread('c:\image\warna.jpg');
[jum_baris,jum_kolom]=size(img);
histogram=zeros(256,1);
for baris=1 : jum_baris
for kolom=1 : jum_kolom
 histogram(img(baris,kolom) + 1) = ...
 histogram(img(baris,kolom) + 1) + 1;
end
end
horijontal=(0:255) ;
bar(horijontal,histogram);
subplot(1,2,1);imshow(img)
subplot(1,2,2);bar(horijontal,histogram)


Hasilnya,,,
,
  

Program pemotongan aras keabuan (menghilangkan derau)

function [img] = potong(citra,f1,f2)
img=imread(citra);  
[jum_baris,jum_kolom]=size(img);
for baris=1 : jum_baris
for kolom=1 : jum_kolom
 if img(baris, kolom ) <=f1
 img(baris,kolom)=0;
 end
  if img(baris,kolom) >=f2
  img(baris,kolom)=255;
  end
end
end
end   %akhir fungsi
h=potong('c:\image\oman.jpg',30,140);
imshow(h)
p=imread('c:\image\oman.jpg');
subplot(1,2,1);imshow(p)
subplot(1,2,2);imshow(h)


Hasilnya,,,
 

Program filter median

Filter median sangat populer dalam pengolahan citra. Filter ini dapat dipakai untuk menghilangkan derau bintik-bintik. Nilai yang lebih baik digunakan untuk suatu piksel ditentukan oleh nilai median dari setiap piksel dan kedelapan piksel tetangga pada 8-ketetanggaan. Secara matematis,

f = imread('c:\image\warna.jpg');
[jum_baris, jum_kolom] = size(f);
for baris=2 : jum_baris - 1
      for kolom=2 : jum_kolom - 1
data= [f(baris-1, kolom-1) ...
f(baris-1, kolom) ...
f(baris-1, kolom+1) ...
f(baris, kolom-1) ...
f(baris, kolom) ...
f(baris, kolom+1) ...
f(baris+1, kolom-1) ...
f(baris+1, kolom) ...
f(baris+1, kolom-1)];                                            
%urutkan
for i=1 : 8
   for j=i+1 : 9
      if data(i) > data(j)
temp =data(i);
data(i)=data(j);
data(j)=temp;
     end
  end
end
%ambil nilai median
g(baris,kolom)=data(5);
end
end
subplot(1,2,1);imshow(f)
subplot(1,2,2);imshow(g)

Hasilnya,,,
 
program penggeseran citra

Penggeseran citra ke arah mendatar atau vertikal dapat dilaksanakan dengan mudah. Rumus yang digunakan sebagai berikut:
x_baru=x_lama + s_x  .............................(5.1)                                                           
y_baru=y_lama + s_y  .............................(5.2)                       
Penggunaan dalam bentuk program
xlama=x_baru - sx;
ylama=y_baru - sy;                             
Untuk penyederhanaan pembahasan, sx dan sy dianggap bertipe bilangan bulat.

f=imread('c:\image\warna.jpg');
[jum_baris,jum_kolom]=size(f);
sx=20;   %penggeseran arah horizontal
sy=60;  %penggeseran arah vertikal
f2=double(f);
g=zeros(size(f2));
for baris=1 : jum_baris
  for kolom=1: jum_kolom
xlama=baris - sx;
ylama=kolom - sy;
  if (xlama >=1) && (xlama<=jum_baris) && ...
  (ylama >=1) && (ylama<=jum_kolom)
  g(baris,kolom)=f2(xlama, ylama);
  else
  g(baris,kolom)=0;
  end
 end
end
h=uint8(g);
subplot(1,2,1);imshow(f)
subplot(1,2,2);imshow(h)

Hasilnya,,,




program memutar citra

f=imread('c:\image\warna.jpg');
 [jum_baris, jum_kolom]=size(f);
sudut=10;  %sudut pemutaran
rad=pi * sudut/180;
cosa=cos(rad);
sina=sin(rad);
f2=f;
for y=1 : jum_baris
  for x=1 :jum_kolom
 x2=round(x * cosa + y * sina);
 y2=round(y * cosa - x * sina);

   if (x2>= 1) && (x2<=jum_kolom) && ...
   (y2 >=1)    && (y2<=jum_baris)
   g(y,x)=f2(y2,x2);
   else
   g(y,x)=0;
   end
 end
end
subplot(1,2,1);imshow(f)
subplot(1,2,2);imshow(g)



Hasilnya,,


Program memperbesar Citra

Suatu citra dapat diperbesar dengan membuat setiap piksel menjadi beberapa piksel.


function g = perbesar(citra, sy, sx)
f = imread(citra);
[baris, kolom] = size(f);
baris_baru    = baris * sy;
kolom_baru = kolom * sx;

f2 = double(f);
for y=1 : baris_baru
    y2 = ((y-1) / sy) + 1;
    for x=1 : kolom_baru
        x2 = ((x-1) / sx) + 1;
        g(y, x) = f(floor(y2), floor(x2));
    end
end

h = uint8(g);
end  %akhir fungsi
u=imread('c:\image\warna.jpg');
z=perbesar('c:\image\warna.jpg', 0.25, 0.25);
subplot(1,2,1);imshow(u),title('citra masukan')
subplot(1,2,2);imshow(z),title('citra perbesar')


Hasilnya,,,


Program pencerminan citra secara horizontal dengan fungsi

Pencerminan yang umum dilakukan berupa pencerminan secara vertikal dan pencerminan secara horizontal. Pencerminan secara horizontal dilakukan dengan menukarkan dua piksel yang berseberangan kir-kanan,

function g = cerminh(f)
[tinggi, lebar] = size(f);
for y=1 : tinggi
    for x=1 : lebar
        x2 = lebar - x + 1;
        y2 = y;
        g(y, x) = f(y2, x2);
    end
end
h = uint8(g);
end   %akhir fungsi
f=imread('c:\image\warna.jpg');
h=cerminh(f);
subplot(1,2,1);imshow(f),title('citra masukan')
subplot(1,2,2);imshow(h),title('citra cermin horizontal')


Hasilnya,,


Program pencerminan citra secara Vertikal dengan fungsi

function g = cerminv(f)
%     Masukan: f = Citra berskala keabuan
[tinggi, lebar] = size(f);
for y=1 : tinggi
    for x=1 : lebar
        x2 = x;
        y2 = tinggi - y + 1;
       
        g(y, x) = f(y2, x2);
    end
end

h = uint8(g);
end    %akhir fungsi
f=imread('c:\image\warna.jpg');
h=cerminv(f);
subplot(1,2,1);imshow(f),title('citra masukan')
subplot(1,2,2);imshow(h),title('citra cermin vertikal')


Hasilnya,,,


Program efek ripple dengan fungsi


Efek ripple (riak) adalah aplikasi transformasi citra yang membuat gambar terlihat bergelombang. Efek riak dapaat dibuat baik pada arah x maupun y.

=====================
function g=ripple(f,ax,ay,tx,ty)
[tinggi,lebar]=size(f);
for y=1 : tinggi
  for x=1 : lebar
x2=x + ax * sin(2 * pi * y / tx);
y2=y + ay * sin(2 * pi * x / ty );
   if (x2>=1) && (x2<=lebar) && ...
   (y2 >=1) && (y2<=tinggi)
  %Lakukan interpolasi Bilinier
  p=floor(y2);
  q=floor(x2);
  a=y2- p;
  b=x2-q;
   if (floor(x2) ==lebar) || ...
   (floor (y2) == tinggi)
   g(y,x)=f(floor(y2), floor(x2));
   else
   intensitas= (1 -a ) * ((1-b) * f(p,q) + ...
   b * f(p, q + 1)) + ...
   a * ((1 - b) * f(p +1, q) + ...
   b * f(p+1, q + 1));
   g(y,x)= intensitas;
   end
    else
    g(y,x)=0;
 end
end
end
g=uint8(g);
end   %akhir fungsi
f=imread('c:\image\warna.jpg');
 g=ripple(f,10,15,120,250);
 subplot(1,2,1);imshow(f)
 subplot(1,2,2);imshow(g)





Hasilnya,,
Program efek Twirl tanpa fungsi

f=imread('c:\image\warna.jpg');
[baris,kolom]   =size(f);

xc=round(kolom / 2);
yc=round(baris / 2);
alpha= 60 * pi /180;
rmaks= 0.5 *sqrt (xc^2 + yc^2);  % 1/2 diagonal citra

for y=1  : baris
   for x= 1 : kolom
r=sqrt((x - xc)^2 + (y -yc)^2);
beta=atan2(y- yc, x-xc) + ...
        alpha * (rmaks - r ) / rmaks;

x2=xc + r * cos(beta);
y2=yc + r * sin(beta);

if (x2 >= 1) && (x2 <=kolom) && ...
    (y2 >=1) && (y2 <=baris)

%lakukan interpolasi bilinear
p=floor(y2);
q=floor(x2);
a=y2 - p;
b=x2 - q;

  if (floor (x2) == kolom) ||  ...
    (floor (y2) == baris)
  g(y,x)=f(floor(y2), floor(x2));
  else
  intensitas = (1-a) * ((1-b) * f (p,q) + ...
  b * f(p, q+1)) + ...
  a * ((1 - b) * f(p +1, q) + ...
  b * f(p + 1,  q+1));

  g(y,x)=intensitas;
  end
else
g(y,x)=0;
end  
end
end
g=uint8(g);
subplot(1,2,1);imshow(f)
subplot(1,2,2);imshow(g)

Hasilnya,,