0% found this document useful (0 votes)
53 views21 pages

Tugas Citra 2

The document is a lab report submitted by Reynold Andika containing screenshots and code from their image processing program assignments. It includes screenshots of the program's graphical user interface and results, as well as code implementing functions to convert images to single-channel, two-channel, and three-channel representations and extract individual color channels. The report also responds to a question asking to add buttons for the green and blue color channels.

Uploaded by

Anonymous
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views21 pages

Tugas Citra 2

The document is a lab report submitted by Reynold Andika containing screenshots and code from their image processing program assignments. It includes screenshots of the program's graphical user interface and results, as well as code implementing functions to convert images to single-channel, two-channel, and three-channel representations and extract individual color channels. The report also responds to a question asking to add buttons for the green and blue color channels.

Uploaded by

Anonymous
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Laporan Praktikum Citra

MK 411
Nama : Reynold Andika
NIM : 4212001011
Laporan minggu ke :2
Hari, tanggal : Thursday, 10 March 2022
Waktu : 16:02:44

Laporan Praktikum yang diupload :


1. Screen shoot hasil eksekusi program
2. Penjelasan hasil program
3. Jawaban pertanyaan jika ada

Screen shoot GUI hasil running anda

Pengolahan Citra (MK-411) 1|


Screen shoot semua hasil running program anda

Pengolahan Citra (MK-411) 2|


Pengolahan Citra (MK-411) 3|
Pengolahan Citra (MK-411) 4|
Pengolahan Citra (MK-411) 5|
Tambahkan kode program untuk tombol Channel G dan Channel B dan screen
hasilnya

Channel G = oneChannelImage(false, true, false);

Channel B = oneChannelImage(false, false, true);

Pengolahan Citra (MK-411) 6|


Coding program :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Tugas_citra_kedua_Rey
{
public partial class Form1 : Form
{

Pengolahan Citra (MK-411) 7|


//global variable
Bitmap sourceImage; //original image
int imageHeight, imageWidth;
public Form1()
{
InitializeComponent();
//fullscreen display
WindowState = FormWindowState.Maximized;
}
private void openFile()
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
sourceImage = (Bitmap)Bitmap.FromFile(openFileDialog1.FileName);
//display original image
pictureBox1.Image = sourceImage;
//determining image width and height
imageHeight = sourceImage.Height;
imageWidth = sourceImage.Width;
}
}

private void label1_Click(object sender, EventArgs e)


{

private void button14_Click(object sender, EventArgs e)


{
redGrayImage();
}

private void button17_Click(object sender, EventArgs e)


{
grayImageMin();
}

Pengolahan Citra (MK-411) 8|


private void Form1_Load(object sender, EventArgs e)
{

private void button1_Click(object sender, EventArgs e)


{
openFile();
}

private void button3_Click(object sender, EventArgs e)


{
Close();
}
//converting RGB to One Channel R Image
private void oneChannelImage(bool red, bool green, bool blue)
{
//avoiding if the source image is null
if (sourceImage == null) return;
Bitmap redChannel = new Bitmap(sourceImage);
Bitmap greenChannel = new Bitmap(sourceImage);
Bitmap blueChannel = new Bitmap(sourceImage);
for (int x = 0; x < imageWidth; x++)
for (int y = 0; y < imageHeight; y++)
{
//get the RGB value of the pixel at (x,y)
Color w = sourceImage.GetPixel(x, y);
byte r = w.R; //red value
byte g = w.G; //green value
byte b = w.B; //blue value
//set the color of each channel
Color redColor = Color.FromArgb(r, 0, 0);
Color greenColor = Color.FromArgb(0, g, 0);
Color blueColor = Color.FromArgb(0, 0, b);
//set the image pixel
redChannel.SetPixel(x, y, redColor);
greenChannel.SetPixel(x, y, greenColor);

Pengolahan Citra (MK-411) 9|


blueChannel.SetPixel(x, y, blueColor);
}
if (red) pictureBox2.Image = redChannel;
else if (green) pictureBox2.Image = greenChannel;
else if (blue) pictureBox2.Image = blueChannel;
}

private void button2_Click(object sender, EventArgs e)


{
oneChannelImage(true, false, false);
}
//converting RGB to Two Channel RG
private void twoChannelImageRG()
{
//avoiding if the source image is null
if (sourceImage == null) return;
Bitmap redgreenChannel = new Bitmap(sourceImage);
for (int x = 0; x < imageWidth; x++)
for (int y = 0; y < imageHeight; y++)
{
//get the RGB value of the pixel at (x,y)
Color w = sourceImage.GetPixel(x, y);
byte r = w.R; //red value
byte g = w.G; //green value
byte b = w.B; //blue value
//set the color of each channel
Color redgreenColor = Color.FromArgb(r, g, 0);
//set the image pixel
redgreenChannel.SetPixel(x, y, redgreenColor);
}
pictureBox2.Image = redgreenChannel;
}

private void button6_Click(object sender, EventArgs e)


{
twoChannelImageRG();
}

Pengolahan Citra (MK-411) 10 |


//converting RGB to Three Channels RBG
private void threeChannelsImageRBG()
{
//avoiding if the source image is null
if (sourceImage == null) return;
Bitmap redbluegreenChannel = new Bitmap(sourceImage);
for (int x = 0; x < imageWidth; x++)
for (int y = 0; y < imageHeight; y++)
{
//get the RGB value of the pixel at (x,y)
Color w = sourceImage.GetPixel(x, y);
byte r = w.R; //red value
byte g = w.G; //green value
byte b = w.B; //blue value
//set the color of each channel
Color redbluegreenColor = Color.FromArgb(r, b, g);
//set the image pixel
redbluegreenChannel.SetPixel(x, y, redbluegreenColor);
}
pictureBox2.Image = redbluegreenChannel;
}

private void button9_Click(object sender, EventArgs e)


{
threeChannelsImageRBG();
}
//converting RGB to gray image red
private void redGrayImage()
{
//avoiding if the source image is null
if (sourceImage == null) return;
Bitmap redGrayChannel = new Bitmap(sourceImage);
for (int x = 0; x < imageWidth; x++)
for (int y = 0; y < imageHeight; y++)
{
//get the RGB value of the pixel at (x,y)
Color w = sourceImage.GetPixel(x, y);

Pengolahan Citra (MK-411) 11 |


byte r = w.R; //red value
byte g = w.G; //green value
byte b = w.B; //blue value
//set the color of each channel
Color redGrayColor = Color.FromArgb(r, r, r);
//set the image pixel
redGrayChannel.SetPixel(x, y, redGrayColor);
}
pictureBox2.Image = redGrayChannel;
}

//converting RGB to Gray Image minimum


private void grayImageMin()
{
//avoiding if the source image is null
if (sourceImage == null) return;
Bitmap grayMinChannel = new Bitmap(sourceImage);
byte min = 255; //initialization
for (int x = 0; x < imageWidth; x++)
for (int y = 0; y < imageHeight; y++)
{
//get the RGB value of the pixel at (x,y)
Color w = sourceImage.GetPixel(x, y);
byte r = w.R; //red value
byte g = w.G; //green value
byte b = w.B; //blue value
if (min >= r)
min = r;
if (min >= g)
min = g;
if (min >= b)
min = b;
//set the color of each channel
Color grayMinColor = Color.FromArgb(min, min, min);
//set the image pixel
grayMinChannel.SetPixel(x, y, grayMinColor);
//reset

Pengolahan Citra (MK-411) 12 |


min = 255;
}
pictureBox2.Image = grayMinChannel;
}

private void button4_Click(object sender, EventArgs e)


{
oneChannelImage(false, true, false);
}

private void button5_Click(object sender, EventArgs e)


{
oneChannelImage(false, false, true);
}

private void button7_Click(object sender, EventArgs e);

//converting RGB to Two Channel GB


private void twoChannelImageGB()
{
//avoiding if the source image is null
if (sourceImage == null) return;
Bitmap greenblueChannel = new Bitmap(sourceImage);
for (int x = 0; x < imageWidth; x++)
for (int y = 0; y < imageHeight; y++)
{
//get the RGB value of the pixel at (x,y)
Color w = sourceImage.GetPixel(x, y);
byte r = w.R; //red value
byte g = w.G; //green value
byte b = w.B; //blue value
//set the color of each channel
Color greenblueColor = Color.FromArgb(0, g, b);
//set the image pixel
greenblueChannel.SetPixel(x, y, greenblueColor);
}
pictureBox2.Image = greenblueChannel;

Pengolahan Citra (MK-411) 13 |


}

private void button6_Click(object sender, EventArgs e)


{
twoChannelImageGB();
}

private void button8_Click(object sender, EventArgs e)


{}
//converting RGB to Two Channel RB
private void twoChannelImageRB()
{
//avoiding if the source image is null
if (sourceImage == null) return;
Bitmap redblueChannel = new Bitmap(sourceImage);
for (int x = 0; x < imageWidth; x++)
for (int y = 0; y < imageHeight; y++)
{
//get the RGB value of the pixel at (x,y)
Color w = sourceImage.GetPixel(x, y);
byte r = w.R; //red value
byte g = w.G; //green value
byte b = w.B; //blue value
//set the color of each channel
Color redblueColor = Color.FromArgb(r, 0, b);
//set the image pixel
redblueChannel.SetPixel(x, y, redblueColor);
}
pictureBox2.Image = redblueChannel;
}

private void button6_Click(object sender, EventArgs e)


{
twoChannelImageRG();
}
//converting RGB to Three Channel GRB
private void threeChannelImageGRB()

Pengolahan Citra (MK-411) 14 |


{
//avoiding if the source image is null
if (sourceImage == null) return;
Bitmap greenredblueChannel = new Bitmap(sourceImage);
for (int x = 0; x < imageWidth; x++)
for (int y = 0; y < imageHeight; y++)
{
//get the RGB value of the pixel at (x,y)
Color w = sourceImage.GetPixel(x, y);
byte r = w.R; //red value
byte g = w.G; //green value
byte b = w.B; //blue value
//set the color of each channel
Color greenredblueColor = Color.FromArgb(g, r, b);
//set the image pixel
greenredblueChannel.SetPixel(x, y, greenredblueColor);
}
pictureBox2.Image = greenredblueChannel;
}

private void button10_Click(object sender, EventArgs e)


{
threeChannelImageGRB();

}
//converting RGB to Three Channel GBR
private void threeChannelImageGBR()
{
//avoiding if the source image is null
if (sourceImage == null) return;
Bitmap greenblueredChannel = new Bitmap(sourceImage);
for (int x = 0; x < imageWidth; x++)
for (int y = 0; y < imageHeight; y++)
{
//get the RGB value of the pixel at (x,y)
Color w = sourceImage.GetPixel(x, y);
byte r = w.R; //red value

Pengolahan Citra (MK-411) 15 |


byte g = w.G; //green value
byte b = w.B; //blue value
//set the color of each channel
Color greenblueredColor = Color.FromArgb(g, b, r);
//set the image pixel
greenblueredChannel.SetPixel(x, y, greenblueredColor);
}
pictureBox2.Image = greenblueredChannel;
}
private void button11_Click(object sender, EventArgs e)
{
threeChannelImageGBR();
}
//converting RGB to Three Channel BGR
private void threeChannelImageBGR()
{
//avoiding if the source image is null
if (sourceImage == null) return;
Bitmap bluegreenredChannel = new Bitmap(sourceImage);
for (int x = 0; x < imageWidth; x++)
for (int y = 0; y < imageHeight; y++)
{
//get the RGB value of the pixel at (x,y)
Color w = sourceImage.GetPixel(x, y);
byte r = w.R; //red value
byte g = w.G; //green value
byte b = w.B; //blue value
//set the color of each channel
Color bluegreenredColor = Color.FromArgb(b, g, r);
//set the image pixel
bluegreenredChannel.SetPixel(x, y, bluegreenredColor);
}
pictureBox2.Image = bluegreenredChannel;
}

private void button12_Click(object sender, EventArgs e)

Pengolahan Citra (MK-411) 16 |


{
threeChannelImageBGR();
}
//converting RGB to Three Channel BRG
private void threeChannelImageBRG()
{
//avoiding if the source image is null
if (sourceImage == null) return;
Bitmap blueredgreenChannel = new Bitmap(sourceImage);
for (int x = 0; x < imageWidth; x++)
for (int y = 0; y < imageHeight; y++)
{
//get the RGB value of the pixel at (x,y)
Color w = sourceImage.GetPixel(x, y);
byte r = w.R; //red value
byte g = w.G; //green value
byte b = w.B; //blue value
//set the color of each channel
Color blueredgreenColor = Color.FromArgb(b, r, g);
//set the image pixel
blueredgreenChannel.SetPixel(x, y, blueredgreenColor);
}
pictureBox2.Image = blueredgreenChannel;
}
private void button13_Click(object sender, EventArgs e)
{
threeChannelImageBRG();
}
//converting RGB to gray image green
private void greenGrayImage()
{
//avoiding if the source image is null
if (sourceImage == null) return;
Bitmap greenGrayChannel = new Bitmap(sourceImage);
for (int x = 0; x < imageWidth; x++)
for (int y = 0; y < imageHeight; y++)
{

Pengolahan Citra (MK-411) 17 |


//get the RGB value of the pixel at (x,y)
Color w = sourceImage.GetPixel(x, y);
byte r = w.R; //red value
byte g = w.G; //green value
byte b = w.B; //blue value
//set the color of each channel
Color greenGrayColor = Color.FromArgb(g, g, g);
//set the image pixel
greenGrayChannel.SetPixel(x, y, greenGrayColor);
}
pictureBox2.Image = greenGrayChannel;
}

private void button15_Click(object sender, EventArgs e)


{
greenGrayImage();
}
//converting RGB to gray image blue
private void blueGrayImage()
{
//avoiding if the source image is null
if (sourceImage == null) return;
Bitmap blueGrayChannel = new Bitmap(sourceImage);
for (int x = 0; x < imageWidth; x++)
for (int y = 0; y < imageHeight; y++)
{
//get the RGB value of the pixel at (x,y)
Color w = sourceImage.GetPixel(x, y);
byte r = w.R; //red value
byte g = w.G; //green value
byte b = w.B; //blue value
//set the color of each channel
Color blueGrayColor = Color.FromArgb(b, b, b);
//set the image pixel
blueGrayChannel.SetPixel(x, y, blueGrayColor);
}
pictureBox2.Image = blueGrayChannel;

Pengolahan Citra (MK-411) 18 |


}
private void button16_Click(object sender, EventArgs e)
{
blueGrayImage();
}
//converting RGB to Gray Image maximum
private void grayImageMax()
{
//avoiding if the source image is null
if (sourceImage == null) return;
Bitmap grayMaxChannel = new Bitmap(sourceImage);
byte max = 255; //initialization
for (int x = 0; x < imageWidth; x++)
for (int y = 0; y < imageHeight; y++)
{
//get the RGB value of the pixel at (x,y)
Color w = sourceImage.GetPixel(x, y);
byte r = w.R; //red value
byte g = w.G; //green value
byte b = w.B; //blue value
if (max >= r)
max = r;
if (max >= g)
max = g;
if (max >= b)
max = b;
//set the color of each channel
Color grayMaxColor = Color.FromArgb(max, max, max);
//set the image pixel
grayMaxChannel.SetPixel(x, y, grayMaxColor);
//reset
max = 255;
}
pictureBox2.Image = grayMaxChannel;
}
private void button18_Click(object sender, EventArgs e)
{

Pengolahan Citra (MK-411) 19 |


grayImageMax();
}

//converting RGB to Gray Image average


private void grayImageavg()
{
//avoiding if the source image is null
if (sourceImage == null) return;
Bitmap grayavgChannel = new Bitmap(sourceImage);
byte avg = 255; //initialization
for (int x = 0; x < imageWidth; x++)
for (int y = 0; y < imageHeight; y++)
{
//get the RGB value of the pixel at (x,y)
Color w = sourceImage.GetPixel(x, y);
byte r = w.R; //red value
byte g = w.G; //green value
byte b = w.B; //blue value
if (avg >= r)
avg = r;
if (avg >= g)
avg = g;
if (avg >= b)
avg = b;
//set the color of each channel
Color grayavgColor = Color.FromArgb(avg, avg, avg);
//set the image pixel
grayavgChannel.SetPixel(x, y, grayavgColor);
//reset
avg = 255;
}
pictureBox2.Image = grayavgChannel;
}

private void button19_Click(object sender, EventArgs e)


{
grayImageavg();

Pengolahan Citra (MK-411) 20 |


}
}
}

Pengolahan Citra (MK-411) 21 |

You might also like