} }
2. Form Implementation
using System; using System.Drawing;
using System.Windows.Forms; using System.Drawing.Imaging;
using System.Diagnostics; using System.Runtime.InteropServices;
namespace KhalidaZia121401018 {
summary
Description of FormImplementation.
summary public partial class FormImplementation : Form
{
public FormImplementation
{ The InitializeComponent call is required for Windows
Forms designer support.
InitializeComponent; TODO: Add constructor code after the
InitializeComponent call. }
void
GroupBox2Enterobject sender, EventArgs e
{ }
void
Button1Clickobject sender, EventArgs e
{
try
{ OpenFileDialog open =
new OpenFileDialog;
open.Filter = Image Files .bmp | .bmp;
if open.ShowDialog == DialogResult.OK
Universitas Sumatera Utara
{ Bitmap bit =
new Bitmapopen.FileName; if bit.Height = 500 bit.Width = 500 bit.Hei
ght = 350 bit.Width = 350 {
pictureBox1.Image = bit; textBox1.Text = open.SafeFileName.
ToString;
textBox2.Text = bit.Width. ToString;
textBox3.Text = bit.Height. ToString;
}
else
MessageBox. ShowImage Pixel must be least 350 x
350 px and max 500 x 500 px, Warning; }
}
catch Exception
{
throw new ApplicationExceptionFailed loading image;
} }
void
Button2Clickobject sender, EventArgs e
{ pictureBox1.Image =
null;
pictureBox3.Image =
null;
pictureBox4.Image =
null;
pictureBox5.Image =
null;
pictureBox6.Image =
null;
textBox1.Text=; textBox2.Text=;
textBox3.Text=; textBox7.Text=;
textBox8.Text=; textBox9.Text=;
textBox10.Text=; textBox11.Text=;
textBox12.Text=; }
Bitmap
average5x5Bitmap image
{
Universitas Sumatera Utara
int iw = image.Width; int ih = image.Height;
double red, green, blue, hasilred =0, hasilgreen
=0, hasilblue=0;
double redfix, greenfix, bluefix;
Bitmap imagehasil = new Bitmapiw, ih;
forint i = 0; iih-4; i++
{
forint j = 0; jiw-4; j++
{
forint k = i; k=i+4; k++
{
forint l = j; l=j+4; l++
{ red = image.
GetPixell,k.R; ifred == 0
red = 255; green = image.
GetPixell,k.G; ifgreen == 0
green = 255; blue = image.
GetPixell,k.B; ifblue == 0
blue = 255; hasilred += red;
hasilgreen += green; hasilblue += blue;
} }
redfix = hasilred25;
double RED = Math.Roundredfix,0; math round
untuk membulatkan nilai terdekat greenfix = hasilgreen25;
double GREEN = Math.Roundgreenfix,0;
bluefix = hasilblue25;
double BLUE =Math.Roundbluefix,0;
imagehasil. SetPixelj+1, i+1, Color.FromArgb255, i
ntRED, intGREEN, intBLUE; hasilred=0;
hasilgreen=0; hasilblue=0;
} }
return imagehasil; }
double nilaiMSEBitmap imageAsli, Bitmap imageHasil
Universitas Sumatera Utara
{
double tambah = 0; double pikselAsli, pikselHasil, mse;
for int i = 0; iimageAsli.Height; i++
{
forint j=0; jimageHasil.Width; j++
{ pikselAsli = imageAsli.
GetPixelj,i.R;
pikselHasil = imageHasil. GetPixelj,i.R;
tambah += Math. PowpikselAsli - pikselHasil, 2;
} }
mse = tambah imageAsli.Height imageAsli.Width; return mse;
}
double nilaiPSNR double mse
{
double PSNR =Math.Log10Math.Pow255, 2mse;
return PSNR; }
public Bitmap CropBitmapBitmap bitmap
{ Rectangle rect
=
new Rectanglebitmap.Width 4, bitmap.Height 4, 200, 100;
Bitmap cropped = bitmap. Clonerect, bitmap.PixelFormat;
return cropped; }
public Bitmap CropBitmap2Bitmap bitmap
{ Rectangle rect
=
new Rectanglebitmap.Width 4, bitmap.Height 4, 250, 150;
Bitmap cropped = bitmap.
Clonerect, bitmap.PixelFormat;
clone = mengklonikan sebagian objek bitmap return cropped;
}
private Bitmap GabungBitmap citra1, Bitmap citra2
{ Bitmap Hasil;
Graphics GH; Hasil =
new Bitmapcitra1.Width, citra1.Height;
GH = Graphics. FromImageHasil; objek grafis
GH. DrawImagecitra1, new Rectangle0, 0, citra1.Width, citra
1.Height;
Universitas Sumatera Utara
GH.
DrawImagecitra2, citra1.Width 4, citra1.Height 4;
GH.
Dispose;
GH = null;
return Hasil; }
void
Button7Clickobject sender, EventArgs e
{ Stopwatch watch =
new Stopwatch; running time
watch. Start;
ifpictureBox1.Image = null
{ pictureBox3.Image
=
CropBitmap new BitmappictureBox1.Image;
pictureBox3.Image =
average5x5 BitmappictureBox3.Image;
}
else
MessageBox. Showplease browse an image, Warning;
watch. Stop;
} void
Button6Clickobject sender, EventArgs e
{
if pictureBox3.Image = null
{ Stopwatch watch =
new Stopwatch; running time
watch.
Start;
Bitmap PB2, PB8; PB2 =
new BitmappictureBox1.Image;
PB8 =
new BitmappictureBox3.Image;
pictureBox4.Image =
GabungPB2, PB8;
watch.
Stop;
textBox7.Text = Math.
RoundConvert.ToDecimalwatch.ElapsedMilliseconds1000,4.ToString
; textBox9.Text=
nilaiMSEBitmappictureBox1.Image,Bitmap
pictureBox4.Image. ToString;
textBox8.Text= nilaiPSNRConvert.ToDoubletextBox9.Text
. ToString;
}
else
MessageBox. Showpress generate please, Warning;
}
Universitas Sumatera Utara
void
Button5Clickobject sender, EventArgs e
{
ifpictureBox4.Image = null
{ SaveFileDialog save =
new SaveFileDialog;
save.Filter = image Files| .bmp; save.FileName = .bmp;
if save.ShowDialog == DialogResult.OK
{ pictureBox4.Image.
Savesave.FileName, System.Draw
ing.Imaging.ImageFormat.Bmp; MessageBox.
ShowImage has
saved, save, MessageBoxButtons.OK, MessageBoxIcon.Information; }
else
{ MessageBox.
ShowImage doesnt save ;
} }
} void
Button8Clickobject sender, EventArgs e
{ Stopwatch watch =
new Stopwatch; running time
watch. Start;
ifpictureBox1.Image = null
{ pictureBox6.Image
=
CropBitmap2 new BitmappictureBox1.Image;
pictureBox6.Image =
average5x5 BitmappictureBox6.Image;
}
else
MessageBox.
Showplease browse an image, Warning;
watch.
Stop;
} void
Button10Clickobject sender, EventArgs e
{
if pictureBox6.Image = null
{ Stopwatch watch =
new Stopwatch; running time
watch. Start;
Bitmap PB2, PB8; PB2 =
new BitmappictureBox1.Image;
PB8 = new BitmappictureBox6.Image;
Universitas Sumatera Utara
pictureBox5.Image =
GabungPB2, PB8;
watch.
Stop;
textBox10.Text = Math.
RoundConvert.ToDecimalwatch.ElapsedMilliseconds1000,4.ToString
; textBox12.Text=
nilaiMSEBitmappictureBox1.Image,Bitma
ppictureBox5.Image. ToString;
textBox11.Text= nilaiPSNRConvert.ToDoubletextBox12.Text
. ToString;
}
else
MessageBox. Showpress generate please, Warning;
} void
Button4Clickobject sender, EventArgs e
{
try
{ OpenFileDialog open =
new OpenFileDialog;
open.Filter = Image Files .bmp | .bmp;
if open.ShowDialog == DialogResult.OK
{ Bitmap bit =
new Bitmapopen.FileName; if bit.Height = 500 bit.Width = 500 bit.Hei
ght = 350 bit.Width = 350 {
pictureBox2.Image = bit; textBox6.Text = open.SafeFileName.
ToString;
textBox4.Text = bit.Height.
ToString;
textBox5.Text = bit.Width.
ToString;
}
else
MessageBox.
ShowImage Pixel must be least 350 x
350 px and max 500 x 500 px, Warning; }
}
catch Exception
{
throw new ApplicationExceptionFailed loading image;
} }
Universitas Sumatera Utara
void
Button3Clickobject sender, EventArgs e
{ pictureBox2.Image =
null;
pictureBox7.Image =
null;
textBox4.Text=; textBox5.Text=;
textBox6.Text=; textBox13.Text=;
textBox14.Text=; textBox15.Text=;
} void
Button12Clickobject sender, EventArgs e
{
ifpictureBox1.Image = null pictureBox2.Image = null
{ Stopwatch watch =
new Stopwatch; running time
watch. Start;
pictureBox7.Image = pictureBox2.Image; textBox13.Text =
Math.
RoundConvert.ToDecimalwatch.ElapsedMilliseconds1000,4.ToString
; textBox15.Text=
nilaiMSEBitmappictureBox1.Image,Bitma
ppictureBox7.Image. ToString;
textBox14.Text= nilaiPSNRConvert.ToDoubletextBox15.Text
.
ToString;
watch. Stop;
}
else
MessageBox.
Showplease select image to
analyze, Warning; }
void
GroupBox1Enterobject sender, EventArgs e
{ }
void
Panel1Paintobject sender, PaintEventArgs e
{ }
void
Button11Clickobject sender, EventArgs e
{
ifpictureBox7.Image = null
Universitas Sumatera Utara
{ SaveFileDialog save =
new SaveFileDialog;
save.Filter = image Files| .bmp; save.FileName = .bmp;
if save.ShowDialog == DialogResult.OK
{ pictureBox7.Image.
Savesave.FileName, System.Draw
ing.Imaging.ImageFormat.Bmp; MessageBox.
ShowImage has
saved, save, MessageBoxButtons.OK, MessageBoxIcon.Information; }
else
{ MessageBox.
ShowImage doesnt save ;
} }
} void
Button9Clickobject sender, EventArgs e
{
ifpictureBox5.Image = null
{ SaveFileDialog save =
new SaveFileDialog;
save.Filter = image Files| .bmp; save.FileName = .bmp;
if save.ShowDialog == DialogResult.OK
{ pictureBox5.Image.
Savesave.FileName, System.Draw
ing.Imaging.ImageFormat.Bmp; MessageBox.
ShowImage has
saved, save, MessageBoxButtons.OK, MessageBoxIcon.Information; }
else
{ MessageBox.
ShowImage doesnt save ;
} }
} }
}
3. Form Help