uas.java
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Image;
import java.awt.image.PixelGrabber;
import java.lang.*;
public class uas extends Applet
{
Image img;
int lebar, tinggi;
int warna, red, green, blue, abuabu, alpha, tempwarna;
String tampil;
int m,n;
double kernelF[][];
public void init()
{
img=this.getImage(this.getDocumentBase(),"UAS.png");
lebar=img.getWidth(this);
m=3;
n=3;
kernelF = new double [m+1][n+1];
kernelF[1][1]=-3; kernelF[1][2]=-3; kernelF[1][3]=-3;
kernelF[2][1]=-3; kernelF[2][2]=0; kernelF[2][3]=5;
kernelF[3][1]=-3; kernelF[3][2]=5; kernelF[3][3]=5;
}
public double konvolusi (int x, int y, int m, int n, int tempBitmap[][], double kernel[][])
{
double hasil;
hasil=0;
//rumus konvolusi
for(int i=-1;i<2;i++)
{
for(int j=-1;j<2;j++)
{
hasil = hasil + (tempBitmap[x+i][y+j] * kernel[m-1+i][n-1+j]);
}
}
//tresholding atau ada yang menyebutnya cliping
if(hasil <0) hasil = 0;
if (hasil > 255) hasil = 255;
//return hasil
return hasil;
}
public void setNilaiTepi (int processedBitmap[][], int nilai)
{
//nilai tepi
for(int y=0;y<=tinggi;y++)
{
processedBitmap[0][y] = nilai;
processedBitmap[lebar+1][y] = nilai;
}
for(int x=0;x<=lebar;x++)
{
processedBitmap[x][0] = nilai;
processedBitmap[x][tinggi+1] = nilai;
}
}
public void paint (Graphics g)
{
g.setColor(Color.lightGray);
g.fillRect(0,0,2800,800);
lebar=img.getWidth(this);
tinggi=img.getHeight(this);
g.setColor(Color.black);
tampil=String.valueOf(lebar);
g.drawString("lebar : "+tampil,10,20);
tampil=String.valueOf(tinggi);
g.drawString("tinggi : "+tampil,10,40);
g.drawImage(img,10,50,this);
int[] pixels = new int [lebar*tinggi];
int[][] bitmapR = new int[lebar+2][tinggi+2];
int[][] bitmapG = new int[lebar+2][tinggi+2];
int[][] bitmapB = new int[lebar+2][tinggi+2];
int[][] bitmapA = new int[lebar+2][tinggi+2];
int[][] bitmapM = new int[lebar+2][tinggi+2];
int[][] repbitmapR = new int[lebar*2][tinggi*2];
int[][] repbitmapG = new int[lebar*2][tinggi*2];
int[][] repbitmapB = new int[lebar*2][tinggi*2];
int[][] hasilFR = new int[lebar+1][tinggi+1];
int[][] hasilFG = new int[lebar+1][tinggi+1];
int[][] hasilFB = new int[lebar+1][tinggi+1];
PixelGrabber pg = new PixelGrabber(img,0,0,lebar,tinggi,pixels,0,lebar);
try
{
pg.grabPixels();
}
catch (InterruptedException ie)
{
System.out.println("terjadi kesalahan saat ambil data pixels");
ie.printStackTrace();
return;
}
g.drawString("hasil pengolahan",lebar+100,20);
g.drawString("normal",lebar+100,40);
g.drawString("grayscale",lebar+100+lebar+50,40);
g.drawString("monokrom channel red",lebar+100+2*lebar+2*50,40);
g.drawString("grayscale channel red",lebar+100+3*lebar+3*50,40);
g.drawString("replikasi skala 1,5",lebar+100,280);
g.drawString("filtering warna",lebar+100+lebar+150,280);
g.drawString("normal red",lebar+100+2*lebar+2*100,280);
g.setColor(Color.black);
for(int j=0;j<tinggi;j++)
{
for(int i=0;i<lebar;i++)
{
warna=pixels[j*lebar+i];
alpha=(warna>>24)&0xff;
red=(warna>>16)&0xff;
bitmapR[i][j]=red;
green=(warna>>8)&0xff;
bitmapG[i][j]=green;
blue=(warna)&0xff;
bitmapB[i][j]=blue;
abuabu=(red+green+blue)/3;
bitmapA[i][j]=abuabu;
}
}
for(int j=0;j<tinggi;j++)
{
for(int i=0;i<lebar;i++)
{
//replikasi
double tempsx=i*1.5;
double tempsy;
repbitmapR[(int)(Math.floor(i*1.5))][(int)(Math.floor(j*1.5))] = bitmapR[i][j];
repbitmapG[(int)(Math.floor(i*1.5))][(int)(Math.floor(j*1.5))] = bitmapG[i][j];
repbitmapB[(int)(Math.floor(i*1.5))][(int)(Math.floor(j*1.5))] = bitmapB[i][j];
tempsx=(int)(Math.floor(i*1.5));
while(tempsx<(i+1)*1.5)
{
tempsy=(int)(Math.floor(j*1.5));
while(tempsy<(j+1)*1.5)
{
repbitmapR[(int)tempsx][(int)tempsy] = bitmapR[i][j];
repbitmapG[(int)tempsx][(int)tempsy] = bitmapG[i][j];
repbitmapB[(int)tempsx][(int)tempsy] = bitmapB[i][j];
tempsy++;
}
tempsx++;
}
}
}
for(int j=0;j<(tinggi*1.5);j++)
{
for(int i=0;i<(lebar*1.5);i++)
{
//replikasi
g.setColor(new Color(repbitmapR[i][j],repbitmapG[i][j],repbitmapB[i][j]));
g.drawLine(i+lebar+100,j+290,i+lebar+100,j+290);
}
}
setNilaiTepi(bitmapA, 128);
for(int y=1;y<=tinggi;y++)
{
for(int x=1;x<=lebar;x++)
{
hasilFR[x][y] = (int) konvolusi(x, y, m, n, bitmapR, kernelF);
hasilFG[x][y] = (int) konvolusi(x, y, m, n, bitmapG, kernelF);
hasilFB[x][y] = (int) konvolusi(x, y, m, n, bitmapB, kernelF);
}
}
for(int y=1;y<=tinggi;y++)
{
for(int x=1;x<=lebar;x++)
{
//filtering
g.setColor(new Color(hasilFR[x][y], hasilFG[x][y], hasilFB[x][y]));
g.drawLine(x+lebar+100+lebar+150,y+290,x+lebar+100+lebar+150,y+290);
}
}
for(int j=0;j<tinggi;j++)
{
for(int i=0;i<lebar;i++)
{
//normal
g.setColor(new Color(bitmapR[i][j],bitmapG[i][j],bitmapB[i][j]));
g.drawLine(i+lebar+100,j+50,i+lebar+100,j+50);
//abuabu
g.setColor(new Color(bitmapA[i][j],bitmapA[i][j],bitmapA[i][j]));
g.drawLine(i+lebar+100+lebar+50,j+50,i+lebar+100+lebar+50,j+50);
//monokrom red
if(bitmapA[i][j]<128) bitmapM[i][j]=0;
if(bitmapA[i][j]>127) bitmapM[i][j]=255;
g.setColor(new Color(bitmapM[i][j],0,0));
g.drawLine(i+lebar+100+2*lebar+2*50,j+50,i+lebar+100+2*lebar+2*50,j+50);
//grayscale red
g.setColor(new Color(bitmapA[i][j],0,0));
g.drawLine(i+lebar+100+3*lebar+3*50,j+50,i+lebar+100+3*lebar+3*50,j+50);
//normal red
g.setColor(new Color(bitmapR[i][j], 0, 0));
g.drawLine(i+lebar+100+2*lebar+2*100,j+290,i+lebar+100+2*lebar+2*100,j+290);
}
}
}
public void repaint (Graphics g)
{
//kosongkan
}
}
uas.html
<html>
<head>
<title> UAS <title>
</head>
<body>
<applet code=uas.class width=1000 height=800></applet>
</body>
</html>
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Image;
import java.awt.image.PixelGrabber;
import java.lang.*;
public class uas extends Applet
{
Image img;
int lebar, tinggi;
int warna, red, green, blue, abuabu, alpha, tempwarna;
String tampil;
int m,n;
double kernelF[][];
public void init()
{
img=this.getImage(this.getDocumentBase(),"UAS.png");
lebar=img.getWidth(this);
m=3;
n=3;
kernelF = new double [m+1][n+1];
kernelF[1][1]=-3; kernelF[1][2]=-3; kernelF[1][3]=-3;
kernelF[2][1]=-3; kernelF[2][2]=0; kernelF[2][3]=5;
kernelF[3][1]=-3; kernelF[3][2]=5; kernelF[3][3]=5;
}
public double konvolusi (int x, int y, int m, int n, int tempBitmap[][], double kernel[][])
{
double hasil;
hasil=0;
//rumus konvolusi
for(int i=-1;i<2;i++)
{
for(int j=-1;j<2;j++)
{
hasil = hasil + (tempBitmap[x+i][y+j] * kernel[m-1+i][n-1+j]);
}
}
//tresholding atau ada yang menyebutnya cliping
if(hasil <0) hasil = 0;
if (hasil > 255) hasil = 255;
//return hasil
return hasil;
}
public void setNilaiTepi (int processedBitmap[][], int nilai)
{
//nilai tepi
for(int y=0;y<=tinggi;y++)
{
processedBitmap[0][y] = nilai;
processedBitmap[lebar+1][y] = nilai;
}
for(int x=0;x<=lebar;x++)
{
processedBitmap[x][0] = nilai;
processedBitmap[x][tinggi+1] = nilai;
}
}
public void paint (Graphics g)
{
g.setColor(Color.lightGray);
g.fillRect(0,0,2800,800);
lebar=img.getWidth(this);
tinggi=img.getHeight(this);
g.setColor(Color.black);
tampil=String.valueOf(lebar);
g.drawString("lebar : "+tampil,10,20);
tampil=String.valueOf(tinggi);
g.drawString("tinggi : "+tampil,10,40);
g.drawImage(img,10,50,this);
int[] pixels = new int [lebar*tinggi];
int[][] bitmapR = new int[lebar+2][tinggi+2];
int[][] bitmapG = new int[lebar+2][tinggi+2];
int[][] bitmapB = new int[lebar+2][tinggi+2];
int[][] bitmapA = new int[lebar+2][tinggi+2];
int[][] bitmapM = new int[lebar+2][tinggi+2];
int[][] repbitmapR = new int[lebar*2][tinggi*2];
int[][] repbitmapG = new int[lebar*2][tinggi*2];
int[][] repbitmapB = new int[lebar*2][tinggi*2];
int[][] hasilFR = new int[lebar+1][tinggi+1];
int[][] hasilFG = new int[lebar+1][tinggi+1];
int[][] hasilFB = new int[lebar+1][tinggi+1];
PixelGrabber pg = new PixelGrabber(img,0,0,lebar,tinggi,pixels,0,lebar);
try
{
pg.grabPixels();
}
catch (InterruptedException ie)
{
System.out.println("terjadi kesalahan saat ambil data pixels");
ie.printStackTrace();
return;
}
g.drawString("hasil pengolahan",lebar+100,20);
g.drawString("normal",lebar+100,40);
g.drawString("grayscale",lebar+100+lebar+50,40);
g.drawString("monokrom channel red",lebar+100+2*lebar+2*50,40);
g.drawString("grayscale channel red",lebar+100+3*lebar+3*50,40);
g.drawString("replikasi skala 1,5",lebar+100,280);
g.drawString("filtering warna",lebar+100+lebar+150,280);
g.drawString("normal red",lebar+100+2*lebar+2*100,280);
g.setColor(Color.black);
for(int j=0;j<tinggi;j++)
{
for(int i=0;i<lebar;i++)
{
warna=pixels[j*lebar+i];
alpha=(warna>>24)&0xff;
red=(warna>>16)&0xff;
bitmapR[i][j]=red;
green=(warna>>8)&0xff;
bitmapG[i][j]=green;
blue=(warna)&0xff;
bitmapB[i][j]=blue;
abuabu=(red+green+blue)/3;
bitmapA[i][j]=abuabu;
}
}
for(int j=0;j<tinggi;j++)
{
for(int i=0;i<lebar;i++)
{
//replikasi
double tempsx=i*1.5;
double tempsy;
repbitmapR[(int)(Math.floor(i*1.5))][(int)(Math.floor(j*1.5))] = bitmapR[i][j];
repbitmapG[(int)(Math.floor(i*1.5))][(int)(Math.floor(j*1.5))] = bitmapG[i][j];
repbitmapB[(int)(Math.floor(i*1.5))][(int)(Math.floor(j*1.5))] = bitmapB[i][j];
tempsx=(int)(Math.floor(i*1.5));
while(tempsx<(i+1)*1.5)
{
tempsy=(int)(Math.floor(j*1.5));
while(tempsy<(j+1)*1.5)
{
repbitmapR[(int)tempsx][(int)tempsy] = bitmapR[i][j];
repbitmapG[(int)tempsx][(int)tempsy] = bitmapG[i][j];
repbitmapB[(int)tempsx][(int)tempsy] = bitmapB[i][j];
tempsy++;
}
tempsx++;
}
}
}
for(int j=0;j<(tinggi*1.5);j++)
{
for(int i=0;i<(lebar*1.5);i++)
{
//replikasi
g.setColor(new Color(repbitmapR[i][j],repbitmapG[i][j],repbitmapB[i][j]));
g.drawLine(i+lebar+100,j+290,i+lebar+100,j+290);
}
}
setNilaiTepi(bitmapA, 128);
for(int y=1;y<=tinggi;y++)
{
for(int x=1;x<=lebar;x++)
{
hasilFR[x][y] = (int) konvolusi(x, y, m, n, bitmapR, kernelF);
hasilFG[x][y] = (int) konvolusi(x, y, m, n, bitmapG, kernelF);
hasilFB[x][y] = (int) konvolusi(x, y, m, n, bitmapB, kernelF);
}
}
for(int y=1;y<=tinggi;y++)
{
for(int x=1;x<=lebar;x++)
{
//filtering
g.setColor(new Color(hasilFR[x][y], hasilFG[x][y], hasilFB[x][y]));
g.drawLine(x+lebar+100+lebar+150,y+290,x+lebar+100+lebar+150,y+290);
}
}
for(int j=0;j<tinggi;j++)
{
for(int i=0;i<lebar;i++)
{
//normal
g.setColor(new Color(bitmapR[i][j],bitmapG[i][j],bitmapB[i][j]));
g.drawLine(i+lebar+100,j+50,i+lebar+100,j+50);
//abuabu
g.setColor(new Color(bitmapA[i][j],bitmapA[i][j],bitmapA[i][j]));
g.drawLine(i+lebar+100+lebar+50,j+50,i+lebar+100+lebar+50,j+50);
//monokrom red
if(bitmapA[i][j]<128) bitmapM[i][j]=0;
if(bitmapA[i][j]>127) bitmapM[i][j]=255;
g.setColor(new Color(bitmapM[i][j],0,0));
g.drawLine(i+lebar+100+2*lebar+2*50,j+50,i+lebar+100+2*lebar+2*50,j+50);
//grayscale red
g.setColor(new Color(bitmapA[i][j],0,0));
g.drawLine(i+lebar+100+3*lebar+3*50,j+50,i+lebar+100+3*lebar+3*50,j+50);
//normal red
g.setColor(new Color(bitmapR[i][j], 0, 0));
g.drawLine(i+lebar+100+2*lebar+2*100,j+290,i+lebar+100+2*lebar+2*100,j+290);
}
}
}
public void repaint (Graphics g)
{
//kosongkan
}
}
uas.html
<html>
<head>
<title> UAS <title>
</head>
<body>
<applet code=uas.class width=1000 height=800></applet>
</body>
</html>