Belajar Image Processing Binary Threshold Visual Studio C#
Dalam tutorial C# kali ini akan mengulas mengenai bagaimana merancang project binary threshold dalam digital image processing, pengolahan gambaran digital, dengan memakai framework AForge.
Berikut yakni video tutorialnya.
Sebelumnya perlu diingat untuk install terlebih dahulu AForge, lalu tambahkan file reference yang diperlukan, yakni dengan cara pilih tab PROJECT lalu Add Reference, sanggup juga pada Solution Explorer pilih References lalu klik kanan dan Add Reference. Setelah itu akan tampil window pencarian file yang diperlukan. Untuk project ini gunakan AForge.dll dan AForge.Imaging.dll.
Untuk source code yang dipakai ialah sebagai berikut.
Project ini akan mengubah suatu gambaran RGB menjadi binary, hitam-putih. Batas nilai hitam-putih ditentukan dari nilai threshold yang diatur dengan memakai scroll. Selain itu terdapat pula pengaturan ukuran gambaran dari Normal, Fit, Stretched, dan Centered. Sumber http://lang8088.blogspot.com/
Berikut yakni video tutorialnya.
Sebelumnya perlu diingat untuk install terlebih dahulu AForge, lalu tambahkan file reference yang diperlukan, yakni dengan cara pilih tab PROJECT lalu Add Reference, sanggup juga pada Solution Explorer pilih References lalu klik kanan dan Add Reference. Setelah itu akan tampil window pencarian file yang diperlukan. Untuk project ini gunakan AForge.dll dan AForge.Imaging.dll.
Untuk source code yang dipakai ialah sebagai berikut.
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;
using AForge;
using AForge.Imaging;
using AForge.Imaging.Filters;
namespace binaryThreshold
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
label1.Text = "Threshold " + hScrollBar1.Value;
}
private void clearChecked()
{
normalToolStripMenuItem.Checked = false;
fitToolStripMenuItem.Checked = false;
stretchedToolStripMenuItem.Checked = false;
centeredToolStripMenuItem.Checked = false;
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
FileDialog fileDialog = new OpenFileDialog();
fileDialog.ShowDialog(this);
string fileName = fileDialog.FileName;
if (fileName == string.Empty) return;
initialPicture.Image = System.Drawing.Image.FromFile(fileName);
hScrollBar1.Enabled = (initialPicture.Image != null);
resetToolStripMenuItem.Enabled = (initialPicture.Image != null);
}
private void normalToolStripMenuItem_Click(object sender, EventArgs e)
{
clearChecked();
normalToolStripMenuItem.Checked = true;
initialPicture.SizeMode = PictureBoxSizeMode.Normal;
filteredPicture.SizeMode = PictureBoxSizeMode.Normal;
}
private void fitToolStripMenuItem_Click(object sender, EventArgs e)
{
clearChecked();
fitToolStripMenuItem.Checked = true;
initialPicture.SizeMode = PictureBoxSizeMode.Zoom;
filteredPicture.SizeMode = PictureBoxSizeMode.Zoom;
}
private void stretchedToolStripMenuItem_Click(object sender, EventArgs e)
{
clearChecked();
stretchedToolStripMenuItem.Checked = true;
initialPicture.SizeMode = PictureBoxSizeMode.StretchImage;
filteredPicture.SizeMode = PictureBoxSizeMode.StretchImage;
}
private void centeredToolStripMenuItem_Click(object sender, EventArgs e)
{
clearChecked();
centeredToolStripMenuItem.Checked = true;
initialPicture.SizeMode = PictureBoxSizeMode.CenterImage;
filteredPicture.SizeMode = PictureBoxSizeMode.CenterImage;
}
private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
label1.Text = "Threshold " + hScrollBar1.Value;
Bitmap image = new Bitmap(initialPicture.Image);
IFilter threshold = new Threshold(hScrollBar1.Value);
image = Grayscale.CommonAlgorithms.RMY.Apply(image);
image = threshold.Apply(image);
filteredPicture.Image = image;
}
private void resetToolStripMenuItem_Click(object sender, EventArgs e)
{
initialPicture.Image = null;
filteredPicture.Image = null;
label1.Text = "Threshold 0";
hScrollBar1.Value = 0;
hScrollBar1.Enabled = false;
resetToolStripMenuItem.Enabled = false;
}
}
}
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;
using AForge;
using AForge.Imaging;
using AForge.Imaging.Filters;
namespace binaryThreshold
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
label1.Text = "Threshold " + hScrollBar1.Value;
}
private void clearChecked()
{
normalToolStripMenuItem.Checked = false;
fitToolStripMenuItem.Checked = false;
stretchedToolStripMenuItem.Checked = false;
centeredToolStripMenuItem.Checked = false;
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
FileDialog fileDialog = new OpenFileDialog();
fileDialog.ShowDialog(this);
string fileName = fileDialog.FileName;
if (fileName == string.Empty) return;
initialPicture.Image = System.Drawing.Image.FromFile(fileName);
hScrollBar1.Enabled = (initialPicture.Image != null);
resetToolStripMenuItem.Enabled = (initialPicture.Image != null);
}
private void normalToolStripMenuItem_Click(object sender, EventArgs e)
{
clearChecked();
normalToolStripMenuItem.Checked = true;
initialPicture.SizeMode = PictureBoxSizeMode.Normal;
filteredPicture.SizeMode = PictureBoxSizeMode.Normal;
}
private void fitToolStripMenuItem_Click(object sender, EventArgs e)
{
clearChecked();
fitToolStripMenuItem.Checked = true;
initialPicture.SizeMode = PictureBoxSizeMode.Zoom;
filteredPicture.SizeMode = PictureBoxSizeMode.Zoom;
}
private void stretchedToolStripMenuItem_Click(object sender, EventArgs e)
{
clearChecked();
stretchedToolStripMenuItem.Checked = true;
initialPicture.SizeMode = PictureBoxSizeMode.StretchImage;
filteredPicture.SizeMode = PictureBoxSizeMode.StretchImage;
}
private void centeredToolStripMenuItem_Click(object sender, EventArgs e)
{
clearChecked();
centeredToolStripMenuItem.Checked = true;
initialPicture.SizeMode = PictureBoxSizeMode.CenterImage;
filteredPicture.SizeMode = PictureBoxSizeMode.CenterImage;
}
private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
label1.Text = "Threshold " + hScrollBar1.Value;
Bitmap image = new Bitmap(initialPicture.Image);
IFilter threshold = new Threshold(hScrollBar1.Value);
image = Grayscale.CommonAlgorithms.RMY.Apply(image);
image = threshold.Apply(image);
filteredPicture.Image = image;
}
private void resetToolStripMenuItem_Click(object sender, EventArgs e)
{
initialPicture.Image = null;
filteredPicture.Image = null;
label1.Text = "Threshold 0";
hScrollBar1.Value = 0;
hScrollBar1.Enabled = false;
resetToolStripMenuItem.Enabled = false;
}
}
}
Project ini akan mengubah suatu gambaran RGB menjadi binary, hitam-putih. Batas nilai hitam-putih ditentukan dari nilai threshold yang diatur dengan memakai scroll. Selain itu terdapat pula pengaturan ukuran gambaran dari Normal, Fit, Stretched, dan Centered. Sumber http://lang8088.blogspot.com/
0 Response to "Belajar Image Processing Binary Threshold Visual Studio C#"
Posting Komentar