Tugas Citra 4
Tugas Citra 4
MK 411
Nama : Reynold Andika
NIM : 4212001011
Laporan minggu ke :4
Hari, tanggal : Wednesday, 16 March 2022
Waktu : 19:35:43
Three Channels
• RGB
• GRB
• BGR
One Channel
• R image
• B image
Coding :
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_4_Rey
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//fullscreen display
//global variable
Bitmap sourceImage; //original image
int imageHeight, imageWidth;
int BIN = 256; //histogram bin
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
sourceImage = (Bitmap)Bitmap.FromFile(openFileDialog1.FileName);
//initialization of arrayhistogram
float[] h = new float[BIN * 3];
//histogram init
for (int i = 0; i < BIN * 3; i++)
{
h[i] = 0;
//histogram calculation
for (int x = 0; x < sourceImage.Width; x++)
for (int y = 0; y < sourceImage.Height; y++)
{
Color w = sourceImage.GetPixel(x, y);
int r = (int)(w.R * BIN / 256);
int g = (int)(w.G * BIN / 256);
int b = (int)(w.B * BIN / 256);
//calculate histogram
if (channel == 1)
{
h[r] = h[r] + 1;
h[g + BIN] = h[g + BIN] + 1;
h[b + 2 * BIN] = h[b + 2 * BIN] + 1;
}
else if (channel == 2)
{
h[r] = h[r] + 1;
h[b + BIN] = h[b + BIN] + 1;
h[g + 2 * BIN] = h[g + 2 * BIN] + 1;
}
else if (channel == 3)
{
h[g] = h[g] + 1;
h[r + BIN] = h[r + BIN] + 1;
h[b + 2 * BIN] = h[b + 2 * BIN] + 1;
}
else if (channel == 4)
{
h[g] = h[g] + 1;
h[b + BIN] = h[b + BIN] + 1;
h[r + 2 * BIN] = h[r + 2 * BIN] + 1;
}
else if (channel == 5)
if (channel == 1)
{
Bitmap rgbImage = threeChannelImage(channel);
pictureBox1.Image = rgbImage;
label1.Text = "RGB Channel Image";
label1.ForeColor = Color.White;
label2.ForeColor = Color.White;
label2.Text = string.Format("RGB Image Histogram {0} Bins", BIN * 3);
}
else if (channel == 2)
{
Bitmap rbgImage = threeChannelImage(channel);
pictureBox1.Image = rbgImage;
label1.Text = "RBG Channel Image";
label1.ForeColor = Color.White;
label2.ForeColor = Color.White;
label2.Text = string.Format("RBG Channel Image Histogram {0} Bins", BIN
* 3);
}
else if (channel == 3)
{
Bitmap grbImage = threeChannelImage(channel);
pictureBox1.Image = grbImage;
label1.Text = "GRB Channel Image";
label1.ForeColor = Color.White;
label2.ForeColor = Color.White;
//initialization of arrayhistogram
float[] h = new float[BIN];
//histogram init
for (int i = 0; i < BIN; i++)
{
h[i] = 0;
}
//histogram calculation
for (int x = 0; x < sourceImage.Width; x++)
for (int y = 0; y < sourceImage.Height; y++)
{
Color w = sourceImage.GetPixel(x, y);
int r = (int)(w.R * BIN / 256);
int g = (int)(w.G * BIN / 256);
int b = (int)(w.B * BIN / 256);
//calculate histogram
if (channel == 1)
if (channel == 1)
{
Bitmap redImage = oneChannelImage(channel);
pictureBox1.Image = redImage;
label1.Text = "Red Channel Image";
label1.ForeColor = Color.White;
threeChannelDisplay(5);
}
threeChannelDisplay(6);
}
}
}