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

Saturday, June 30, 2018

Perataan Histogram Citra Dengan Matlab

function ratahistogram1
% program perataan histogram
% diketahui citra awal ukuran 4 X 5, dengan jangkauan keabuan 1-10

baris=4; kolom=5; derajatkeabuan=10;
awal=zeros(baris,kolom);
akhir=zeros(baris,kolom);
kemunculan=zeros(1,derajatkeabuan);
probkemunculan=zeros(1,derajatkeabuan);
sumprobkemunculan=zeros(1,derajatkeabuan);

% mengisi data citra awal
awal = [3 5 5 5 4; 5 4 5 4 4; 5 3 4 4 4; 4 5 6 6 3]

% hitung kemunculan dan cari probabilitasnya
for i=1:baris;
    for j=1:kolom;
        switch awal(i,j)
        case 1
            kemunculan(1)=kemunculan(1)+1;
            probkemunculan(1)=kemunculan(1)/(baris*kolom);
        case 2
            kemunculan(2)=kemunculan(2)+1;
            probkemunculan(2)=kemunculan(2)/(baris*kolom);
        case 3
            kemunculan(3)=kemunculan(3)+1;
            probkemunculan(3)=kemunculan(3)/(baris*kolom);
        case 4
            kemunculan(4)=kemunculan(4)+1;
            probkemunculan(4)=kemunculan(4)/(baris*kolom);
        case 5
            kemunculan(5)=kemunculan(5)+1;
            probkemunculan(5)=kemunculan(5)/(baris*kolom);
        case 6
            kemunculan(6)=kemunculan(6)+1;
            probkemunculan(6)=kemunculan(6)/(baris*kolom);
        case 7
            kemunculan(7)=kemunculan(7)+1;
            probkemunculan(7)=kemunculan(7)/(baris*kolom);
        case 8
            kemunculan(8)=kemunculan(8)+1;
            probkemunculan(8)=kemunculan(8)/(baris*kolom);
        case 9
            kemunculan(9)=kemunculan(9)+1;
            probkemunculan(9)=kemunculan(9)/(baris*kolom);
        otherwise
            kemunculan(10)=kemunculan(10)+1;
            probkemunculan(10)=kemunculan(10)/(baris*kolom);
        end
    end;
end;

% hitung jumlah probabilitas (SK)
for i=1:derajatkeabuan
    if i==1
        sumprobkemunculan(i)=probkemunculan(i);
    else
        sumprobkemunculan(i)=sumprobkemunculan(i-1)+probkemunculan(i);
    end
end
sumprobkemunculan

% hitung jumlah probabilitas (SK) * derajatkeabuan
for i=1:derajatkeabuan
    sumprobkemunculan(i)=sumprobkemunculan(i)*derajatkeabuan;
end
sumprobkemunculan

% citra akhir perataan histogram
for i=1:baris
    for j=1:kolom;
        switch awal(i,j)
        case 1; akhir(i,j)=floor(sumprobkemunculan(1));
        case 2; akhir(i,j)=floor(sumprobkemunculan(2));
        case 3; akhir(i,j)=floor(sumprobkemunculan(3));
        case 4; akhir(i,j)=floor(sumprobkemunculan(4));
        case 5; akhir(i,j)=floor(sumprobkemunculan(5));
        case 6; akhir(i,j)=floor(sumprobkemunculan(6));
        case 7; akhir(i,j)=floor(sumprobkemunculan(7));
        case 8; akhir(i,j)=floor(sumprobkemunculan(8));
        case 9; akhir(i,j)=floor(sumprobkemunculan(9));
        otherwise akhir(i,j)=floor(sumprobkemunculan(10));
        end;
    end
end;
akhir

Friday, June 29, 2018

Konvolusi Tepi Citra Dengan Matlab

function konvolusicitra
%titik pusat di tengah
a=imread('cameraman.tif');
g=[0 -1 0;-1 4 -1;0 -1 0];
x=a;
a=double(a);
[baris kolom]=size(a);
for i=2:baris-1
    for j=2:kolom-1
        y(i,j)=(a(i-1,j-1)*g(1,1)+a(i-1,j)*g(1,2)+a(i-1,j+1)*g(1,3)+a(i,j-1)*g(2,1)+a(i,j)*g(2,2)+a(i,j+1)*g(2,3)+a(i+1,j-1)*g(3,1)+a(i+1,j)*g(3,2)+a(i+1,j+1)*g(3,3));
        if y(i,j)>255
            y(i,j)=255;
        else
           if y(i,j)<0
             y(i,j)=0;
         end
     end
 end
end
out=uint8(y);
subplot(2,2,1),imshow(x);
subplot(2,2,2),imhist(x);
subplot(2,2,3),imshow(out);
subplot(2,2,4),imhist(out);

Monday, March 21, 2011

Perataan Histogram Citra Dengan Matlab

function ratahistogram1
% program perataan histogram
% diketahui citra awal ukuran 4 X 5, dengan jangkauan keabuan 1-10

baris=4; kolom=5; derajatkeabuan=10;
awal=zeros(baris,kolom);
akhir=zeros(baris,kolom);
kemunculan=zeros(1,derajatkeabuan);
probkemunculan=zeros(1,derajatkeabuan);
sumprobkemunculan=zeros(1,derajatkeabuan);

% mengisi data citra awal
awal = [3 5 5 5 4; 5 4 5 4 4; 5 3 4 4 4; 4 5 6 6 3]

% hitung kemunculan dan cari probabilitasnya
for i=1:baris;
    for j=1:kolom;
        switch awal(i,j)
        case 1
            kemunculan(1)=kemunculan(1)+1;
            probkemunculan(1)=kemunculan(1)/(baris*kolom);
        case 2
            kemunculan(2)=kemunculan(2)+1;
            probkemunculan(2)=kemunculan(2)/(baris*kolom);
        case 3
            kemunculan(3)=kemunculan(3)+1;
            probkemunculan(3)=kemunculan(3)/(baris*kolom);
        case 4
            kemunculan(4)=kemunculan(4)+1;
            probkemunculan(4)=kemunculan(4)/(baris*kolom);
        case 5
            kemunculan(5)=kemunculan(5)+1;
            probkemunculan(5)=kemunculan(5)/(baris*kolom);
        case 6
            kemunculan(6)=kemunculan(6)+1;
            probkemunculan(6)=kemunculan(6)/(baris*kolom);
        case 7
            kemunculan(7)=kemunculan(7)+1;
            probkemunculan(7)=kemunculan(7)/(baris*kolom);
        case 8
            kemunculan(8)=kemunculan(8)+1;
            probkemunculan(8)=kemunculan(8)/(baris*kolom);
        case 9
            kemunculan(9)=kemunculan(9)+1;
            probkemunculan(9)=kemunculan(9)/(baris*kolom);
        otherwise
            kemunculan(10)=kemunculan(10)+1;
            probkemunculan(10)=kemunculan(10)/(baris*kolom);
        end
    end;
end;

% hitung jumlah probabilitas (SK)
for i=1:derajatkeabuan
    if i==1
        sumprobkemunculan(i)=probkemunculan(i);
    else
        sumprobkemunculan(i)=sumprobkemunculan(i-1)+probkemunculan(i);
    end
end
sumprobkemunculan

% hitung jumlah probabilitas (SK) * derajatkeabuan
for i=1:derajatkeabuan
    sumprobkemunculan(i)=sumprobkemunculan(i)*derajatkeabuan;
end
sumprobkemunculan

% citra akhir perataan histogram
for i=1:baris
    for j=1:kolom;
        switch awal(i,j)
        case 1; akhir(i,j)=floor(sumprobkemunculan(1));
        case 2; akhir(i,j)=floor(sumprobkemunculan(2));
        case 3; akhir(i,j)=floor(sumprobkemunculan(3));
        case 4; akhir(i,j)=floor(sumprobkemunculan(4));
        case 5; akhir(i,j)=floor(sumprobkemunculan(5));
        case 6; akhir(i,j)=floor(sumprobkemunculan(6));
        case 7; akhir(i,j)=floor(sumprobkemunculan(7));
        case 8; akhir(i,j)=floor(sumprobkemunculan(8));
        case 9; akhir(i,j)=floor(sumprobkemunculan(9));
        otherwise akhir(i,j)=floor(sumprobkemunculan(10));
        end;
    end
end;
akhir

Kernel 2x2 pusat 2,1 Citra Dengan Matlab

function kernel2
f=[4 4 8 8 4;8 12 4 12 8;8 4 12 4 8;4 12 4 12 8;4 8 4 8 4];
g=[0.25 0.25;0.25 0.25];
d=f;
[baris kolom]=size(f);
for i=2:baris
    for j=1:kolom-1
        d(i,j)=(f(i-1,j)*g(1,1)+f(i,j)*g(1,2)+f(i-1,j+1)*g(2,1)+f(i,j+1)*g(2,2));
    end
end
f
d

Kernel 2x2 pusat 1,2 Citra Dengan Matlab

function kernel3
f=[4 4 8 8 4;8 12 4 12 8;8 4 12 4 8;4 12 4 12 8;4 8 4 8 4];
g=[0.25 0.25;0.25 0.25];
d=f;
[baris kolom]=size(f);
for i=1:baris-1 %menunjukkan letak titik pusat baris pada kernel
    for j=2:kolom %menunjukkan letak titik pusat kolom pada kernel
        d(i,j)=(f(i+1,j)*g(1,1)+f(i,j)*g(1,2)+f(i+1,j-1)*g(2,1)+f(i,j-1)*g(2,2));
    end
end
f
d

Kernel 2x2 pusat 1,1 Citra Dengan Matlab

function kernel
f=[4 4 8 8 4;8 12 4 12 8;8 4 12 4 8;4 12 4 12 8;4 8 4 8 4];
g=[0.25 0.25;0.25 0.25];
d=f;
[baris kolom]=size(f);
for i=1:baris-1
    for j=1:kolom-1
        d(i,j)=(f(i,j)*g(1,1)+f(i,j+1)*g(1,2)+f(i+1,j)*g(2,1)+f(i+1,j+1)*g(2,2));
    end
end
f
d

Konvolusi Tepi Citra Dengan Matlab

function konvolusicitra
%titik pusat di tengah
a=imread('cameraman.tif');
g=[0 -1 0;-1 4 -1;0 -1 0];
x=a;
a=double(a);
[baris kolom]=size(a);
for i=2:baris-1
    for j=2:kolom-1
        y(i,j)=(a(i-1,j-1)*g(1,1)+a(i-1,j)*g(1,2)+a(i-1,j+1)*g(1,3)+a(i,j-1)*g(2,1)+a(i,j)*g(2,2)+a(i,j+1)*g(2,3)+a(i+1,j-1)*g(3,1)+a(i+1,j)*g(3,2)+a(i+1,j+1)*g(3,3));
        if y(i,j)>255
            y(i,j)=255;
        else
           if y(i,j)<0
             y(i,j)=0;
         end
     end
 end
end
out=uint8(y);
subplot(2,2,1),imshow(x);
subplot(2,2,2),imhist(x);
subplot(2,2,3),imshow(out);
subplot(2,2,4),imhist(out);

Rotasi Citra Dengan Matlab

function rotation
A=imread('cameraman.tif');
[baris kolom]=size(A);
for i=1:baris,
    for j=1:kolom,
        d(i,j)=A(i,j);
    end
end
for i=1:baris,
    for j=1:kolom,
        out(j,baris+1-i)=d(i,j);%inti dari rotasi
    end
end
subplot(1,2,1),imshow(A);
subplot(1,2,2),imshow(out);


Tambahan :        listing
90 derajat  :        (j,baris+1-i)
180 derajat :        (baris+1-i,kolom+1-j)
270 derajat :        (kolom+1-j,i)

Saturday, August 7, 2010