Selasa, 25 Juni 2013
Pengecilan Citra Gambar (MATLAB)
% program kompresi citra ukuran 512X512 menjadi 256x256 piksel
function kompresi_512_256
clc
citra=imread('d:\data\gajah2.jpg');
area=uint8(zeros(256,256));
% menduplikasikan data citra asli
d=zeros(512,512);
for i=1:512;
for j=1:512;
d(i,j)=citra(i,j);
end
end
%kompresi dari 512x512 ke 256x256 piksel
for b_asli=1:256
for k_asli=1:256
temp=0; dummy=0;
for b_baru=1:2
for k_baru=1:2
dummyb=((b_asli-1)*2 + b_baru);
dummyk= ((k_asli-1)*2 + k_baru);
dummy=d(dummyb,dummyk);
temp=temp+dummy;
end
end
temp=round(temp/4);
area(b_asli,k_asli)=temp;
end
end
imwrite(area,'d:\data\kompresi_256_256.jpg');
citra_kompresi=imread('d:\data\kompresi_256_256.jpg');
figure
imshow(citra);
title('Citra dimensi 512x512 piksel');
figure
imshow(citra_kompresi);
title('Citra dimensi 256x256 piksel');
Perbesaran Citra Gambar (MATLAB)
% program memperbesar citra ukuran 256x256 menjadi 512X512 piksel
function perbesar_256_512
clc %bersihkan jendela command window
close all %tutup semua jendela figure yang lama
citra=imread('d:\data\kura2.jpg');
%pesan variabel d untuk simpan citra baru
d=uint8(zeros(512,512));
%memperbesar citra dari 256x256 menjadi 512x512 piksel
for b_asli=1:256
for k_asli=1:256
temp=citra(b_asli,k_asli);
for b_baru=1:2
for k_baru=1:2
dummyb=((b_asli-1)*2 + b_baru);
dummyk= ((k_asli-1)*2 + k_baru);
d(dummyb,dummyk)=temp;
end
end
d(dummyb,dummyk);
end
end
imwrite(d,'d:\data\perbesar_512_512.jpg');
citra_kompresi=imread('d:\data\perbesar_512_512.jpg');
figure
imshow(citra); title('Citra dimensi 256x256 piksel');
figure
imshow(citra_kompresi); title('Citra dimensi 512x512 piksel');
Rabu, 05 Juni 2013
Thread Utama (JAVA)
class MyThread implements Runnable
{
private Thread t;
private int n;
MyThread(String nama,int n)
{
t= new Thread(this,nama);
this.n = n;
}
public void run()
{
try
{
for (int i=0; i<n; i++)
{
System.out.println("Thread"+t.getName()+":detik ke-"+(i+1));
Thread.sleep(1000);
}
System.out.println("Thread"+t.getName()+"selesai...");
}
catch (InterruptedException ie)
{
System.out.println(ie.getMessage());
}
}
public void start()
{
t.start();
}
public Thread getThread()
{
return t;
}
}
class DemoIsAliveJoin
{
public static void main(String[]args)
throws InterruptedException
{
System.out.println("Thread utama dijalankan\n");
MyThread t1=new MyThread("pertama",2);
MyThread t2=new MyThread("kedua",3);
MyThread t3=new MyThread("ketiga",4);
t1.start();
t2.start();
t3.start();
//pada saat thread t1.t2.t3 aktif
System.out.println("t1.getThread().isAlive():" + t1.getThread().isAlive());
System.out.println("t2.getThread().isAlive():" + t2.getThread().isAlive());
System.out.println("t3.getThread().isAlive():" + t3.getThread().isAlive());
System.out.println();
//menunggu smapai thread t1,t2,t3 selesai diexekusi
t1.getThread().join();
t2.getThread().join();
t3.getThread().join();
//setelah thread t1,t2,t3 selesai
System.out.println();
System.out.println("t1.getThread().isAlive():" + t1.getThread().isAlive());
System.out.println("t2.getThread().isAlive():" + t2.getThread().isAlive());
System.out.println("t3.getThread().isAlive():" + t3.getThread().isAlive());
System.out.println("\nThread utama selesai");
}
}
Selasa, 04 Juni 2013
Pelembutan Citra (MATLAB)
function pelembutan_citra
%menggunakan filter lolos rendah
%syarat: semua koefisien filter harus positif
%syarat: jumlah semua koefisien harus sama dengan 1
A=imread('cameraman.tif');
m=[1/9 1/9 1/9;1/9 1/9 1/9;1/9 1/9 1/9];
%m=[1/10 1/10 1/10; 1/10 1/5 1/10;1/10 1/10 1/10];
%m=[1/16 1/8 1/16; 1/8 1/4 1/8; 1/16 1/8 1/16];
d=A
[baris kolom]=size(A);
for i=2:baris-1;
for j=2:kolom-1;
d(i,j)=A(i-1,j-1)*m(1,1)+A(i-1,j)*m(1,2)+A(i-1,j+1)*m(1,3)+A(i,j-1)*m(2,1)+A(i,j)*m(2,2)+A(i,j+1)*m(2,3)+A(i+1,j-1)*m(3,1)+A(i+1,j)*m(3,2)+A(i+1,j+1)*m(3,3);
if d(i,j)>255
d(i,j)=255;
else if d(i,j)<0
d(i,j)=0;
end
end
end
end
subplot(2,2,1), imshow(A);
subplot(2,2,2), imhist(A);
subplot(2,2,3), imshow(d);
subplot(2,2,4), imhist(d);
%menggunakan filter lolos rendah
%syarat: semua koefisien filter harus positif
%syarat: jumlah semua koefisien harus sama dengan 1
A=imread('cameraman.tif');
m=[1/9 1/9 1/9;1/9 1/9 1/9;1/9 1/9 1/9];
%m=[1/10 1/10 1/10; 1/10 1/5 1/10;1/10 1/10 1/10];
%m=[1/16 1/8 1/16; 1/8 1/4 1/8; 1/16 1/8 1/16];
d=A
[baris kolom]=size(A);
for i=2:baris-1;
for j=2:kolom-1;
d(i,j)=A(i-1,j-1)*m(1,1)+A(i-1,j)*m(1,2)+A(i-1,j+1)*m(1,3)+A(i,j-1)*m(2,1)+A(i,j)*m(2,2)+A(i,j+1)*m(2,3)+A(i+1,j-1)*m(3,1)+A(i+1,j)*m(3,2)+A(i+1,j+1)*m(3,3);
if d(i,j)>255
d(i,j)=255;
else if d(i,j)<0
d(i,j)=0;
end
end
end
end
subplot(2,2,1), imshow(A);
subplot(2,2,2), imhist(A);
subplot(2,2,3), imshow(d);
subplot(2,2,4), imhist(d);
Langganan:
Postingan (Atom)