0% found this document useful (0 votes)
9 views8 pages

Convert RGB

Uploaded by

ymingzhe01
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)
9 views8 pages

Convert RGB

Uploaded by

ymingzhe01
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/ 8

້ ງ 2CPR2

ນາງ ນ ັດທິດາ ແສງມະໂນທາ ຫອ

ບ ົດເຝິກຫັດເພີີ່ມເຕີມ

Convert to RGB
1. ໂຫຼດຮູບພາບ

2. Color Transfomation Menu


1.
2.

3.
4.
5.

6.
using Emgu.CV.Structure;
using Emgu.CV;
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 Lab_Imageprocessing
{
public partial class ConvertRGB : Form
{
public ConvertRGB()
{
InitializeComponent();
}
Image<Bgr, byte> imgInput;
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog opf = new OpenFileDialog();

if (opf.ShowDialog() == DialogResult.OK)
{

imgInput = new Image<Bgr, byte>(opf.FileName);

pictureBox1.Image = imgInput.Bitmap;

}
}

private void exitToolStripMenuItem_Click(object sender, EventArgs e)


{
this.Close();
}

private void bGRGrayToolStripMenuItem_Click(object sender, EventArgs e)


{
if (imgInput == null)

MessageBox.Show("Please select an image.");

return;

Image<Gray, byte> imgOutput = new Image<Gray, byte>(imgInput.Width,


imgInput.Height, new Gray(0));

CvInvoke.CvtColor(imgInput, imgOutput,
Emgu.CV.CvEnum.ColorConversion.Bgr2Gray);
pictureBox2.Image = imgOutput.Bitmap;
}

private void bGRYCrCbToolStripMenuItem_Click(object sender, EventArgs e)


{
if (imgInput == null)
{
MessageBox.Show("Please select an image.");

return;
}

Image<Ycc, byte> imgOutput = new Image<Ycc, byte>(imgInput.Width,


imgInput.Height);
Image<Bgr, byte> imgFinalOutput = new Image<Bgr,
byte>(imgInput.Width, imgInput.Height);

CvInvoke.CvtColor(imgInput, imgOutput,
Emgu.CV.CvEnum.ColorConversion.Bgr2YCrCb);

imgFinalOutput.Data = imgOutput.Data;
pictureBox2.Image = imgFinalOutput.Bitmap;
}

private void bGRHSVToolStripMenuItem_Click(object sender, EventArgs e)


{
if (imgInput == null)
{
MessageBox.Show("Please select an image.");

return;
}
Image<Hsv, byte> imgOutput = new Image<Hsv, byte>(imgInput.Width,
imgInput.Height);
Image<Bgr, byte> imgFinalOutput = new Image<Bgr,
byte>(imgInput.Width, imgInput.Height);
CvInvoke.CvtColor(imgInput, imgOutput,
Emgu.CV.CvEnum.ColorConversion.Bgr2Hsv);

imgFinalOutput.Data = imgOutput.Data;
pictureBox2.Image = imgFinalOutput.Bitmap;
}

private void bGRLUVToolStripMenuItem_Click(object sender, EventArgs e)


{
if (imgInput == null)
{
MessageBox.Show("Please select an image.");

return;
}
Image<Luv, byte> imgOutput = new Image<Luv, byte>(imgInput.Width,
imgInput.Height);
Image<Bgr, byte> imgFinalOutput = new Image<Bgr,
byte>(imgInput.Width, imgInput.Height);
//imgOutput = imgInput.Convert<Gray, byte>();

CvInvoke.CvtColor(imgInput, imgOutput,
Emgu.CV.CvEnum.ColorConversion.Bgr2Luv);

imgFinalOutput.Data = imgOutput.Data;
pictureBox2.Image = imgFinalOutput.Bitmap;
}
private void bGRLabToolStripMenuItem_Click(object sender, EventArgs e)
{
if (imgInput == null)
{
MessageBox.Show("Please select an image.");

return;
}
Image<Lab, byte> imgOutput = new Image<Lab, byte>(imgInput.Width,
imgInput.Height);
Image<Bgr, byte> imgFinalOutput = new Image<Bgr,
byte>(imgInput.Width, imgInput.Height);
//imgOutput = imgInput.Convert<Gray, byte>();

CvInvoke.CvtColor(imgInput, imgOutput,
Emgu.CV.CvEnum.ColorConversion.Bgr2Lab);

imgFinalOutput.Data = imgOutput.Data;
pictureBox2.Image = imgFinalOutput.Bitmap;
}

private void bGRHSLToolStripMenuItem_Click(object sender, EventArgs e)


{
if (imgInput == null)
{
MessageBox.Show("Please select an image.");

return;
}

Image<Hls, byte> imgOutput = new Image<Hls, byte>(imgInput.Width,


imgInput.Height);
Image<Bgr, byte> imgFinalOutput = new Image<Bgr,
byte>(imgInput.Width, imgInput.Height);
//imgOutput = imgInput.Convert<Gray, byte>();

CvInvoke.CvtColor(imgInput, imgOutput,
Emgu.CV.CvEnum.ColorConversion.Bgr2Hls);

imgFinalOutput.Data = imgOutput.Data;
pictureBox2.Image = imgFinalOutput.Bitmap;
}
}
}

You might also like