C#을 사용하여 임계값을 주어서 그 값을 상대로 그림을 변환시킵니다.
<<소스>>
OpenFileDialog openFile = new OpenFileDialog();
openFile.Filter = "All files(*.*)|*.*|jpg(*.jpg)|*.jpg";
openFile.ShowDialog();
if (openFile.FileName.Length > 0)
{
Image image = Image.FromFile(openFile.FileName);
pictureBox1.Image = image;
gBitmap = new Bitmap(image);
grBitmap = new Bitmap(image.Width, image.Height);
arr = new int[image.Height, image.Width];
arr1 = new int[image.Height, image.Width];
for (int y = 0; y < image.Height; y++)
{
for (int x = 0; x < image.Width; x++)
{
//RGB
m_color = gBitmap.GetPixel(x, y);
brightness = (m_color.R + m_color.G + m_color.B) / 3;
arr[y, x] = brightness;
}
}
for (int y = 0; y < image.Height; y++)
{
for (int x = 0; x < image.Width; x++)
if (100 < arr[y, x])//임계치 100
{//임계값보다 높으면 255
arr1[y, x] = 255;
}
else
{//임계값보다 낮으면 0
arr1[y, x] = 0;
}
}
for (int x = 0; x < image.Width; x++)
{
for (int y = 0; y < image.Height; y++)
{
//넣어주기
gray = Color.FromArgb(arr1[y, x], arr1[y, x], arr1[y, x]);
grBitmap.SetPixel(x, y, gray);
}
}
pictureBox2.Image = grBitmap;
}
아 어려워잉.,.,ㅜㅜ