Lab DIP Week2
Lab DIP Week2
ຂຽນໂປຼແກຼມ:
1. ເພື່ອຊອກຄ່າລະດັບເທົາ (Gray scale) ຂອງຮູບພາບທີ່ກຳນົດ, ໂດຍນຳໃຊ້
ສູດທີ1: ຄ່າໃໝ່ = (R+G+B)/3;
ສູດທີ2: ຄ່າໃໝ່ = (0.3*R+0.59*G+0.11*B);
2. ເພື່ອປ່ຽນຄ່າຟິກເຊວ ໃຫ້ເປັນຂາວດຳ ໂດຍນຳໃຊ້ສູດ Thresholding (t ແມ່ນຄ່າ threshold ທີ່ກຳນົດ)
ຖ້າ ຄ່າຟິກເຊວ > t ຄ່າໃໝ່ = 255;
ຖ້າ ຄ່າຟິກເຊວ <= t ຄ່າໃໝ່ = 0;
3. ເພື່ອປ່ຽນຄ່າກົງກັນຂ້າມຂອງຮູບຂາວດຳ ໂດຍນຳໃຊ້ສູດ:
ຖ້າ ຄ່າຟິກເຊວ = 0 ຄ່າໃໝ່ = 255;
ຖ້າ ຄ່າຟິກເຊວ = 255 ຄ່າໃໝ່ = 0;
4. ເພື່ອປ່ຽນຄ່າລົບ (Negative) ຂອງຟິກເຊວ, ໂດຍນຳໃຊ້ສູດ: (s = L-1-r)
ຄ່າໃໝ່ = 255 – ຟິກເຊວປະຈຸບັນ;
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;
1
namespace Gray_Scale1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Bitmap pict_C;
Bitmap pict_O = (Bitmap)Image.FromFile("Im1.jpg");
//setting threshold
public Bitmap Thresholding1(Bitmap source)
{
Bitmap bmp = new Bitmap(source.Width, source.Height);
int t = int.Parse(textBox1.Text);
2
avg = 255;
else avg = 0;
//setting invert
public Bitmap Invert(Bitmap source)
{
Bitmap bmp = new Bitmap(source.Width, source.Height);
int t = int.Parse(textBox1.Text);
//setting Negative
public Bitmap Negative(Bitmap source)
{
Bitmap bmp = new Bitmap(source.Width, source.Height);
int t = int.Parse(textBox1.Text);
3
pictureBox1.Image = pict_O;
pictureBox1.Refresh();
}
//origin
private void button1_Click(object sender, EventArgs e)
{
pictureBox1.Image = pict_O;
}
//grayscale1
private void button2_Click(object sender, EventArgs e)
{
pict_C = new Bitmap(pictureBox1.Image);
pictureBox1.Image = ConvertToGrayScale(pict_C);
}
//Black and White1
private void button4_Click(object sender, EventArgs e)
{
pict_C = new Bitmap(pictureBox1.Image);
pictureBox1.Image = Thresholding1(pict_C);
}
//invert
private void button3_Click(object sender, EventArgs e)
{
pict_C = new Bitmap(pictureBox1.Image);
pictureBox1.Image = Invert(pict_C);
}
//grayscale2
private void button5_Click(object sender, EventArgs e)
{
pict_C = new Bitmap(pictureBox1.Image);
pictureBox1.Image = ConvertToGrayScale2(pict_C);
}