Sie sind auf Seite 1von 5

OPERASI CITRA NEGATIF DAN OPERASI CLIPPING

TUGAS 2
DISUSUN UNTUK MEMENUHI TUGAS MATAKULIAH
PENGOLAHAN CITRA DIGITAL

Disusun Oleh:
Hairul Anam S (140431100103)

PROGRAM STUDI S1 TEKNIK ELEKTRO


FAKULTAS TEKNIK
UNIVERSITAS TRUNOJOYO MADURA
MARET 2017
OPERASI CITRA NEGATIF DAN OPERASI CLIPPING

1. Source Code program dengan software Visual Studio C#


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ImageProcessing
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

Bitmap imgray, imneg, imclip;

private void btnOpen_Click(object sender, EventArgs e)


{
OpenFileDialog ofile = new OpenFileDialog();
ofile.Filter = "Image File (*.bmp,*.jpg)|*.bmp;*.jpg";
if (DialogResult.OK == ofile.ShowDialog())
{
this.picOriginal.Image = new Bitmap(ofile.FileName);
}

//PROSES
imgray = new Bitmap((Bitmap)this.picOriginal.Image);
imneg = new Bitmap((Bitmap)this.picOriginal.Image);
imclip = new Bitmap((Bitmap)this.picOriginal.Image);

for (int i = 0; i < imgray.Width; i++)


for (int j = 0; j < imgray.Height; j++)
{
// GRAYSCALE
Color c1 = imgray.GetPixel(i, j);
int r1 = c1.R;
int g1 = c1.G;
int b1 = c1.B;
int gray = (byte)(.299 * r1 + .587 * g1 + .114 * b1);
r1 = gray;
g1 = gray;
b1 = gray;
imgray.SetPixel(i, j, Color.FromArgb(r1, g1, b1));
// NEGATIF
Color c2 = imneg.GetPixel(i, j);
int r2 = 255 - c2.R;
int g2 = 255 - c2.G;
int b2 = 255 - c2.B;
imneg.SetPixel(i, j, Color.FromArgb(r2, g2, b2));

// CLIPPING
Color c3 = imclip.GetPixel(i, j);
int r3 = c3.R;
if (r3 > 127)
{
r3 = 255;
}
else if (r3 < 127)
{
r3 = 0;
}

int g3 = c3.G;
if (g3 > 127)
{
g3 = 255;
}
else if (g3 < 127)
{
g3 = 0;
}

int b3 = c3.B;
if (b3 > 127)
{
b3 = 255;
}
else if (b3 < 127)
{
b3 = 0;
}
imclip.SetPixel(i, j, Color.FromArgb(r3, g3, b3));
}
}

private void btnClose_Click(object sender, EventArgs e)


{
Close();
}

private void clippingToolStripMenuItem_Click(object sender,EventArgs e)


{
this.picResult.Image = imclip;
}

private void negativToolStripMenuItem_Click(object sender, EventArgs e)


{
this.picResult.Image = imneg;
}

private void grayscaleToolStripMenuItem_Click(object sender,EventArgs e)


{
this.picResult.Image = imgray;
}

}
}

2. Tampilan (Interface)

Gambar 1. Tampilan Awal

Gambar 2. Hasil Operasi Negatif


Gambar 3. Hasil Operasi Clipping

Gambar 4. Hasil Operasi Grayscale (Keabu-abuan)

Das könnte Ihnen auch gefallen