0% found this document useful (0 votes)
43 views

Openfiledialog: " " "Bitmap Files ( .BMP) - .BMP - Jpeg Files ( .JPG) - .JPG - All Valid Files ( .BMP/ .JPG) - .BMP/ .JPG"

The document describes code for an image processing application. It includes code to open an image file, extract RGB pixel data, perform brightness enhancement and noise reduction functions, and save the processed image. Functions include opening and saving file dialogs, locking bitmap data, and applying average pixel filters within a class.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Openfiledialog: " " "Bitmap Files ( .BMP) - .BMP - Jpeg Files ( .JPG) - .JPG - All Valid Files ( .BMP/ .JPG) - .BMP/ .JPG"

The document describes code for an image processing application. It includes code to open an image file, extract RGB pixel data, perform brightness enhancement and noise reduction functions, and save the processed image. Functions include opening and saving file dialogs, locking bitmap data, and applying average pixel filters within a class.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Code 1 OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = " " ; openFileDialog.Filter = "Bitmap files (*.bmp)|*.bmp|Jpeg files (*.jpg)|*.

jpg| All valid files (*.bmp/*.jpg)|*.bmp/*.jpg"; openFileDialog.FilterIndex = 1 ; openFileDialog.RestoreDirectory = true; if(DialogResult.OK == openFileDialog.ShowDialog()) { this.AutoScroll = true; this.origImage.Image = new Bitmap(openFileDialog.FileName); this.Invalidate(); Bitmap b = new Bitmap((Bitmap) this.origImage.Image); BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat. Format24b ppRgb); int stride = bmData.Stride; System.IntPtr Scan0 = bmData.Scan0; unsafe { byte * p = (byte *)(void *)Scan0; int nOffset = stride - b.Width*3; r_data = new byte[b.Width,b.Height]; g_data = new byte[b.Width,b.Height]; b_data = new byte[b.Width,b.Height]; for(int y=0;y<b.Height;++y) { for(int x=0;x<b.Width;++x) { b_data[x,y] = p[0]; g_data[x,y] = p[1]; r_data[x,y] = p[2]; p +=3; } p += nOffset;

} } } textBox1.Text = "File " + openFileDialog.FileName + " dibuka.\n ";

Code 2 Bitmap copy = new Bitmap((Bitmap) this. procImage.Image); SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.InitialDirectory = " " ; saveFileDialog.Filter = "Bitmap files (*.bmp)|*.bmp|Jpeg files (*.jpg)|*.jpg|All valid files (*bmp/*.jpg)|*.bmp/*.jpg" ; saveFileDialog.FilterIndex = 1 ; saveFileDialog.RestoreDirectory = true ; if(DialogResult.OK == saveFileDialog. ShowDialog()) { copy.Save(saveFileDialog.FileName); } textBox1.Text = "File hasil proses disimpan.";

Code 4 /* * Created by SharpDevelop. * User: Danny * Date: 4/30/2013 * Time: 8:52 PM * * To change this template use Tools | Options | Coding | Edit Standard Headers. */ using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; // ditambahkan manual using System.Windows.Forms;

namespace Program_Pengolah_Citra { /// <summary> /// Description of MainForm. /// </summary> public partial class MainForm : Form { byte [,] r_data; byte [,] g_data; byte [,] b_data; public MainForm() { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); // // TODO: Add constructor code after the InitializeComponent() call. // } public class ImageOperator { public static bool Perbaikan(Bitmap b, int signal) { BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width,b.Height), ImageLockMode.ReadWrite, PixelFormat. Format24b ppRgb); int stride = bmData.Stride; System.IntPtr Scan0 = bmData.Scan0; unsafe { byte * PixelFormat =(byte *)(void *)Scan0; int nOffset = stride - b.Width*3; int red, green, blue; byte [,] r_tmp = new byte[b.Width,b.Height]; byte [,] g_tmp = new byte[b.Width,b.Height]; byte [,] b_tmp = new byte[b.Width,b.Height]; byte [,] r_tmp2 = new byte[b.Width,b.Height];

byte [,] g_tmp2 = new byte[b.Width,b.Height]; byte [,] b_tmp2 = new byte[b.Width,b.Height]; if(signal==1) { for(int y=0;y<b.Height;++y) { for(int x=0; x < b.Width;++x) { Blue =p[0]+10; if (blue<255) p[0]=(byte) blue ; else p[0]=(byte) 255; Green =p[1]+10; if (green<255) p[1]=(byte) green ; else p[1]=(byte) 255; Red =p[2]+10; if (red<255) p[2]=(byte) red ; else p[2]=(byte) 255; p +=3; } p += nOffset; } } if(signal==2) { for(int y=0;y<b.Height;++y) { for(int x=0; x < b.Width;++x) { b_tmp[x,y] = p[0]; g_tmp[x,y] = p[1]; r_tmp[x,y] = p[2]; p += 3; } p += nOffset; } byte * p1 = (byte *)(void *)Scan0; for(int y=1;y<b.Height- 1;++y) { for(int x=1; x < b.Width- 1;++x) { blue = (b_tmp[x,y]+b_tmp[x-1,y-1]+b_tmp[x,y-1]+b_tmp[x+1,y1]+b_tmp[x+1,y]+b_tmp[x+1,y+1]+b_tmp[x,y+1]+b_tmp[x-1,y+1]+b_tmp[x-1,y])/9; green = (g_tmp[x,y]+g_tmp[x-1,y-1]+g_tmp[x,y-1]+g_tmp[x+1,y1]+g_tmp[x+1,y]+g_tmp[x+1,y+1]+g_tmp[x,y+1]+g_tmp[x-1,y+1]+g_tmp[x-1,y])/9; red = (r_tmp[x,y]+r_tmp[x-1,y-1]+r_tmp[x,y-1]+r_tmp[x+1,y-

1]+r_tmp[x+1,y]+r_tmp[x+1,y+1]+r_tmp[x,y+1]+r_tmp[x-1,y+1]+r_tmp[x-1,y])/9; b_tmp2[x,y] = (byte) blue; g_tmp2[x,y] = (byte) green; r_tmp2[x,y] = (byte) red; p1 += 3; } p1 += nOffset; } byte * p2 = (byte *)(void *)Scan0; for(int y=0;y<b.Height;++y) { for(int x=0; x < b.Width;++x) { p2[0] = b_tmp2[x,y]; p2[1] = g_tmp2[x,y]; p2[2] = r_tmp2[x,y]; p2 += 3; } p2 += nOffset; } } } b.UnlockBits(bmData); return true; } } } } void ThresholdingMerahToolStripMenuItemClick(object sender, EventArgs e) { } void BukaFileToolStripMenuItemClick(object sender, EventArgs e) { OpenFileDialog openFileDialog = newOpenFileDialog(); openFileDialog.InitialDirectory = " " ; openFileDialog.Filter = "Bitmap files (*.bmp)|*.bmp|Jpeg files (*.jpg)|*.jpg| All valid files (*.bmp/*.jpg)|*.bmp/*.jpg";

openFileDialog.FilterIndex = 1 ; openFileDialog.RestoreDirectory = true; if(DialogResult.OK == openFileDialog.ShowDialog()) { this.AutoScroll = true; this.origImage.Image = newBitmap(openFileDialog.FileName); this.Invalidate(); Bitmap b = newBitmap((Bitmap) this. origImage.Image); BitmapData bmData = b.LockBits(newRectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat. Format24b ppRgb); int stride = bmData.Stride; System.IntPtr Scan0 = bmData.Scan0; unsafe { byte * p = (byte *)(void *)Scan0; int nOffset = stride - b.Width*3; r_data = newbyte[b.Width,b.Height]; g_data = newbyte[b.Width,b.Height]; b_data = newbyte[b.Width,b.Height]; for(int y=0;y<b.Height;++y) { for(int x=0; x < b.Width;++x) { b_data[x,y] = p[0]; g_data[x,y] = p[1]; r_data[x,y] = p[2]; p +=3; } p += nOffset; } } } textBox1.Text = "File " + openFileDialog. FileName + " dibuka.\n "; } void SimpanFileToolStripMenuItemClick(object sender, EventArgs e)

{ Bitmap copy = new Bitmap((Bitmap) this. procImage.Image); SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.InitialDirectory = " " ; saveFileDialog.Filter = "Bitmap files (*.bmp)|*.bmp|Jpeg files (*.jpg)|*.jpg|All valid files (*bmp/*.jpg)|*.bmp/*.jpg" ; saveFileDialog.FilterIndex = 1 ; saveFileDialog.RestoreDirectory = true ; if(DialogResult.OK == saveFileDialog. ShowDialog()) { copy.Save(saveFileDialog.FileName); } textBox1.Text = "File hasil proses disimpan."; } void KeluarToolStripMenuItemClick(object sender, EventArgs e) { this.Close(); } void TingkatkanKecerahanToolStripMenuItemClick(object sender, EventArgs e) { Bitmap copy = new Bitmap((Bitmap) this.origImage.Image); ImageOperator.Perbaikan(copy, 1); origImage.Image = null; origImage.Image = copy; textBox1.Text = "Kecerahan ditingkatkan."; } void ReduksiNoiseToolStripMenuItemClick(object sender, EventArgs e) { Bitmap copy = new Bitmap((Bitmap) this. origImage.Image); ImageOperator.Perbaikan(copy, 2); origImage.Image = null; origImage.Image = copy; textBox1.Text = "Noise direduksi."; } } }

You might also like