lampiran
DESCRIPTION
LampiranTRANSCRIPT
L-2
Lampiran 1Kode Program Perangkat Lunak Perbaikan Kualitas Citra berkabut (Haze)Kelas Form.cs
using Emgu.CV;using Emgu.CV.Structure;using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Diagnostics;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;
namespace Dehazing{ public partial class Form1 : Form { Image a = null; Control Controller = new Control();
public Form1() { InitializeComponent(); }
private void resetComponent() { darkChannelToolStripMenuItem.Enabled = false; darkChannel3x3ToolStripMenuItem.Enabled = false; darkChannel15x15ToolStripMenuItem.Enabled = false; dehazeToolStripMenuItem.Enabled = false; histogramToolStripMenuItem.Enabled = false; button1.Enabled = false; }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { resetComponent(); a = new Image(openFileDialog1.FileName); Controller.setImageOriginal(a); pictureBox1.Image = a.ToBitmap(); pictureBox2.Image = null; button1.Enabled = true; darkChannelToolStripMenuItem.Enabled = true; darkChannel3x3ToolStripMenuItem.Enabled = true; darkChannel15x15ToolStripMenuItem.Enabled = true; } }
private void dehazeToolStripMenuItem_Click(object sender, EventArgs e) { Controller.getTransmission(); Controller.Dehaze_Image(); pictureBox2.Image = Controller.getDehaze_Image(); dehazeToolStripMenuItem.Enabled = false; histogramToolStripMenuItem.Enabled = true; }
private void dehazeButton_Click(object sender, EventArgs e) { Stopwatch st = new Stopwatch(); st.Start(); Controller.Dehaze_Image_All(); pictureBox2.Image = Controller.getDehaze_Image(); st.Stop(); label1.Text = "Time process " + st.ElapsedMilliseconds + "ms"; Controller.MSE(); label2.Text = "MSE Value = " + Controller.getMSEValue(); darkChannelToolStripMenuItem.Enabled = false; dehazeToolStripMenuItem.Enabled = false; histogramToolStripMenuItem.Enabled = true; }
private void darkChannelToolStripMenuItem_Click(object sender, EventArgs e) { Controller.DCP_Image(); pictureBox2.Image = Controller.getDCP_Image(); darkChannelToolStripMenuItem.Enabled = false; darkChannel3x3ToolStripMenuItem.Enabled = false; darkChannel15x15ToolStripMenuItem.Enabled = false; dehazeToolStripMenuItem.Enabled = true; }
private void histogramToolStripMenuItem_Click(object sender, EventArgs e) { Controller.HistogramGraf(); }
private void saveToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp"; saveFileDialog1.Title = "Save an Image File"; saveFileDialog1.ShowDialog();
// If the file name is not an empty string open it for saving. if (saveFileDialog1.FileName != "") { System.IO.FileStream fs = (System.IO.FileStream)saveFileDialog1.OpenFile(); switch (saveFileDialog1.FilterIndex) { case 1: this.pictureBox2.Image.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg); break;
case 2: this.pictureBox2.Image.Save(fs, System.Drawing.Imaging.ImageFormat.Bmp); break; }
fs.Close(); } }
private void aboutToolStripMenuItem_Click(object sender, EventArgs e) { System.Windows.Forms.MessageBox.Show("Dini Triyama 2015"); }
private void exitToolStripMenuItem_Click(object sender, EventArgs e) { this.Close(); }
private void darkChannel3x3ToolStripMenuItem_Click(object sender, EventArgs e) { Controller.DCP_Image3x3(); pictureBox2.Image = Controller.getDCP_Image(); darkChannelToolStripMenuItem.Enabled = false; darkChannel3x3ToolStripMenuItem.Enabled = false; darkChannel15x15ToolStripMenuItem.Enabled = false; dehazeToolStripMenuItem.Enabled = true; }
private void darkChannel15x15ToolStripMenuItem_Click(object sender, EventArgs e) { Controller.DCP_Image15x15(); pictureBox2.Image = Controller.getDCP_Image(); darkChannelToolStripMenuItem.Enabled = false; darkChannel3x3ToolStripMenuItem.Enabled = false; darkChannel15x15ToolStripMenuItem.Enabled = false; dehazeToolStripMenuItem.Enabled = true; } }}
Kelas Control.cs
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Drawing;using Emgu.CV;using Emgu.CV.CvEnum;using Emgu.CV.Features2D;using Emgu.CV.Structure;using Emgu.CV.UI;using Emgu.CV.Util;
namespace Dehazing{ public class Control { Nilai Value = new Nilai(); Dark_Channel_Prior DCP = new Dark_Channel_Prior(); Transmission T = new Transmission(); Dehaze D = new Dehaze(); Kualitas Quality = new Kualitas();
public void setImageOriginal(Image ImgSrc) { Value.ImageOriginal = ImgSrc; } public void DCP_Image() { Value.ImageDCP = DCP.getMedianDarkChannel(Value.ImageOriginal, 5); Value.AirLight = DCP.estimateA(Value.ImageDCP); }
public void DCP_Image3x3() { Value.ImageDCP = DCP.getMedianDarkChannel3(Value.ImageOriginal, 5); Value.AirLight = DCP.estimateA(Value.ImageDCP); }
public void DCP_Image15x15() { Value.ImageDCP = DCP.getMedianDarkChannel15(Value.ImageOriginal, 5); Value.AirLight = DCP.estimateA(Value.ImageDCP); }
public Bitmap getDCP_Image() { return Value.ImageDCP.ToBitmap(); }
public void getTransmission() { Value.ImageTransmission= T.estimateTransmission(Value.ImageDCP, Value.AirLight); }
public void Dehaze_Image() { Value.ImageDehazing = D.getDehazed(Value.ImageOriginal, Value.ImageTransmission, Value.AirLight); }
public Bitmap getDehaze_Image() { return Value.ImageDehazing.ToBitmap(); } public void MSE() { Value.MSEValue = Quality.MSE(Value.ImageOriginal, Value.ImageDehazing); } public double getMSEValue() { return Value.MSEValue; } public void Dehaze_Image_All() { DCP_Image3x3(); getTransmission(); Dehaze_Image(); } public void HistogramGraf() { Value.HistogramInputBlue = Quality.HistogramValue(Value.ImageOriginal, 0); Value.HistogramInputGreen = Quality.HistogramValue(Value.ImageOriginal, 1); Value.HistogramInputRed = Quality.HistogramValue(Value.ImageOriginal, 2);
Value.HistogramOutputBlue = Quality.HistogramValue(Value.ImageDehazing, 0); Value.HistogramOutputGreen = Quality.HistogramValue(Value.ImageDehazing, 1); Value.HistogramOutputRed = Quality.HistogramValue(Value.ImageDehazing, 2);
HTG HTG_Form = new HTG(Value.HistogramInputRed,Value.HistogramInputGreen,Value.HistogramInputBlue, Value.HistogramOutputRed,Value.HistogramOutputGreen,Value.HistogramOutputBlue); HTG_Form.DrawGraf(); HTG_Form.Show();
}
}}
Kelas Nilai.cs
using System;using System.Collections.Generic;using System.Linq;using System.Text;using Emgu.CV;using Emgu.CV.CvEnum;using Emgu.CV.Features2D;using Emgu.CV.Structure;using Emgu.CV.UI;using Emgu.CV.Util;
namespace Dehazing{ public class Nilai { private int Airlight; //airlight value private double mse; private const double maxValue = 16777215;
private int[] HInputR = new int[256]; private int[] HInputG = new int[256]; private int[] HInputB = new int[256]; private int[] HOutputR = new int[256]; private int[] HOutputG = new int[256]; private int[] HOutputB = new int[256];
private Image imgSource; private Image darkChannel; private Image transmission; private Image dehaze;
public Image ImageOriginal { get { return imgSource; } set { imgSource = value; } }
public Image ImageDCP { get { return darkChannel; } set { darkChannel = value; } }
public Image ImageTransmission { get { return transmission; } set { transmission = value; } }
public Image ImageDehazing { get { return dehaze; } set { dehaze = value; } }
public int[] HistogramInputRed { get { return HInputR; } set { HInputR = value; } } public int[] HistogramInputGreen { get { return HInputG; } set { HInputG = value; } } public int[] HistogramInputBlue { get { return HInputB; } set { HInputB = value; } } public int[] HistogramOutputRed { get { return HOutputR; } set { HOutputR = value; } } public int[] HistogramOutputGreen { get { return HOutputG; } set { HOutputG = value; } } public int[] HistogramOutputBlue { get { return HOutputB; } set { HOutputB = value; } } public double MSEValue { get { return mse; } set { mse = value; } } public double getPixelMaxValue() { return maxValue; } public int AirLight { get { return Airlight; } set { Airlight = value; } } }}
Kelas Dark_Channel_Prior.cs
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Drawing;using Emgu.CV;using Emgu.CV.CvEnum;using Emgu.CV.Features2D;using Emgu.CV.Structure;using Emgu.CV.UI;using Emgu.CV.Util;
namespace Dehazing{ public class Dark_Channel_Prior {
public Image getMedianDarkChannel(Image src, int patch) { Image rgbmin = new Image(src.Width, src.Height);
for (int m = 0; m < src.Width; m++) { for (int n = 0; n < src.Height; n++) { rgbmin.Data[n, m, 0] = Math.Min(Math.Min(src.Data[n, m, 0], src.Data[n, m, 1]), src.Data[n, m, 2]); } } rgbmin = rgbmin.SmoothMedian(patch); //smoothing with median filter return rgbmin; }
public Image getMedianDarkChannel3(Image src, int patch) { Image rgbmin = new Image(src.Width, src.Height);
for (int m = 0; m < src.Width; m++) { for (int n = 0; n < src.Height; n++) { rgbmin.Data[n, m, 0] = (byte)getCenterPx3(m,n,src); } } rgbmin = rgbmin.SmoothMedian(patch); //smoothing with median filter return rgbmin; }
public Image getMedianDarkChannel15(Image src, int patch) { Image rgbmin = new Image(src.Width, src.Height);
for (int m = 0; m < src.Width; m++) { for (int n = 0; n < src.Height; n++) { rgbmin.Data[n, m, 0] = (byte)getCenterPx15(m, n, src); } } rgbmin = rgbmin.SmoothMedian(patch); //smoothing with median filter return rgbmin; } private int getCenterPx3(int x, int y, Image imgSource) { int i, j, r = 0, g = 0, b = 0; int min = 255; Color cMin = Color.White;
for (i = x - 1; i = 0 && j < imgSource.Height) { if (((imgSource.Data[j,i,0] + imgSource.Data[j,i,1] + imgSource.Data[j,i,2]) / 3) < min) { min = ((imgSource.Data[j, i, 0] + imgSource.Data[j, i, 1] + imgSource.Data[j, i, 2]) / 3); r = imgSource.Data[j, i, 2]; g = imgSource.Data[j, i, 1]; b = imgSource.Data[j, i, 0]; } } } } min = 255; if (r < min) min = r; if (b < min) min = b; if (g < min) min = g;
return min; }
private int getCenterPx15(int x, int y, Image imgSource) { int i, j, r = 0, g = 0, b = 0; int min = 255; Color cMin = Color.White;
for (i = x - 7; i = 0 && j < imgSource.Height) {
if (((imgSource.Data[j, i, 0] + imgSource.Data[j, i, 1] + imgSource.Data[j, i, 2]) / 3) < min) { min = ((imgSource.Data[j, i, 0] + imgSource.Data[j, i, 1] + imgSource.Data[j, i, 2]) / 3); r = imgSource.Data[j, i, 2]; g = imgSource.Data[j, i, 1]; b = imgSource.Data[j, i, 0]; } } } } min = 255; if (r < min) min = r; if (b < min) min = b; if (g < min) min = g;
return min; } public int estimateA(Image DC) { double[] minDC, maxDC; Point[] minDC_Loc, maxDC_Loc; DC.MinMax(out minDC, out maxDC, out minDC_Loc, out maxDC_Loc); return (int)maxDC[0]; } }}
Kelas Transmission.cs
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Drawing;
using Emgu.CV;using Emgu.CV.CvEnum;using Emgu.CV.Features2D;using Emgu.CV.Structure;using Emgu.CV.UI;using Emgu.CV.Util;
namespace Dehazing{ public class Transmission { public Image estimateTransmission(Image DCP, int ac) { double w = 0.75; Image transmission = new Image(DCP.Width, DCP.Height);
for (int m = 0; m < DCP.Width; m++) { for (int n = 0; n < DCP.Height; n++) { transmission.Data[n, m, 0] = (byte)((1 - w * (double)DCP.Data[n, m, 0] / ac) * 255); } } return transmission; } }}
Kelas Dehaze.cs
#undef DEBUG
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Drawing;using Emgu.CV;using Emgu.CV.CvEnum;using Emgu.CV.Features2D;using Emgu.CV.Structure;using Emgu.CV.UI;using Emgu.CV.Util;
public class Dehaze{ public Image getDehazed(Image source, Image t, int al) { double tmin = 0.1; double tmax;
Image dehazed = source.CopyBlank(); //CV_8UC3 == Bgr image
for (int i = 0; i < source.Width; i++) { for (int j = 0; j < source.Height; j++) {
tmax = ((double)t.Data[j, i, 0] / 255) < tmin ? tmin : ((double)t.Data[j, i, 0] / 255); for (int k = 0; k < 3; k++) { dehazed.Data[j, i, 0] = (byte)(Math.Abs(((double)source.Data[j, i, 0] - al) / tmax + al) > 255 ? 255 : Math.Abs(((double)source.Data[j, i, 0] - al) / tmax + al)); //blue dehazed.Data[j, i, 1] = (byte)(Math.Abs(((double)source.Data[j, i, 1] - al) / tmax + al) > 255 ? 255 : Math.Abs(((double)source.Data[j, i, 1] - al) / tmax + al)); //green dehazed.Data[j, i, 2] = (byte)(Math.Abs(((double)source.Data[j, i, 2] - al) / tmax + al) > 255 ? 255 : Math.Abs(((double)source.Data[j, i, 2] - al) / tmax + al)); //red } } } return dehazed; }}
Kelas Kualitas.cs
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Drawing;
using Emgu.CV;using Emgu.CV.CvEnum;using Emgu.CV.Features2D;using Emgu.CV.Structure;using Emgu.CV.UI;using Emgu.CV.Util;
namespace Dehazing{ public class Kualitas { public double MSE(Image ImgSource, Image ImgOutput) { double pembilang = 0, r, g, b; for (int i = 0; i < ImgSource.Width; i++) { for (int j = 0; j < ImgSource.Height; j++) { r = (double)ImgOutput.Data[j, i, 2] - (double)ImgSource.Data[j, i, 2]; g = (double)ImgOutput.Data[j, i, 1] - (double)ImgSource.Data[j, i, 1]; b = (double)ImgOutput.Data[j, i, 0] - (double)ImgSource.Data[j, i, 0]; pembilang = pembilang + ((r * r) + (g * g) + (b * b)); } } return (double)pembilang / (ImgSource.Width * ImgSource.Height); }
public int[] HistogramValue(Image src, int n) { int h = src.Height; int w = src.Width; src.ToBitmap(); int[] hist = new int[256]; for (int i = 0; i < 256; i++) hist[i] = 0;
for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { hist[src.Data[j, i, n]] = hist[src.Data[j, i, n]] + 1; } }
return hist; }
} }
L-1