please help me with my code.. how to make a region, i think my for loops in button function is wrong.. can you tell me how to do this? or my code is wrong about region growing segmentation? the result is so weird.. there are stripes in the pict.. how to make it right? please teach me.. thank you so much...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.IO;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace RGlagi
{
public partial class Form1 : Form
{
public int threshold = 90;
bool[,] sudahdicek;
public Form1()
{
InitializeComponent();
Bitmap citraasli = new Bitmap(pictureBox1.Image);
sudahdicek = new bool[citraasli.Width,citraasli.Height];
Console.WriteLine(sudahdicek[0, 0]);
}
void banding(Bitmap citraasli, int x, int y, int x1, int y1)
{
double R = citraasli.GetPixel(x, y).R;
double G = citraasli.GetPixel(x, y).G;
double B = citraasli.GetPixel(x, y).B;
double R1 = citraasli.GetPixel(x1, y1).R;
double G1 = citraasli.GetPixel(x1, y1).G;
double B1 = citraasli.GetPixel(x1, y1).B;
double diff = Math.Sqrt(Math.Pow(R - R1, 2) + Math.Pow(G - G1, 2) + Math.Pow(B - B1, 2));
if (!sudahdicek[x1, y1])
{
Console.WriteLine(x + "," + y + ",dengan " + x1 + "," + y1 + " : " + diff + " ");
sudahdicek[x, y] = true;
if (diff < threshold)
{
citraasli.SetPixel(x1, y1, Color.FromArgb(255, (int)R, (int)G, (int)B));
sudahdicek[x1, y1] = true;
Console.Write(sudahdicek[x1, y1]);
}
else
{
segmen(citraasli, x1, y1);
}
}
}
void segmen(Bitmap citraasli, int x, int y)
{
if (x == 0 && y == 0)
{
banding(citraasli, x, y, x + 1, y);
banding(citraasli, x, y, x, y + 1);
}
else
if (x > 0 && y == 0 && x < citraasli.Width - 1)
{
banding(citraasli, x, y, x - 1, y);
banding(citraasli, x, y, x + 1, y);
banding(citraasli, x, y, x, y + 1);
}
else
if (x == citraasli.Width - 1 && y == 0)
{
banding(citraasli, x, y, x - 1, y);
banding(citraasli, x, y, x, y + 1);
}
else
if (x == 0 && y > 0 && y < citraasli.Height - 1)
{
banding(citraasli, x, y, x , y-1);
banding(citraasli, x, y, x + 1, y);
banding(citraasli, x, y, x, y + 1);
}
else
if (x == citraasli.Width - 1 && y > 0 && y < citraasli.Height - 1)
{
banding(citraasli, x, y, x, y - 1);
banding(citraasli, x, y, x - 1, y);
banding(citraasli, x, y, x, y + 1);
}
else
if (x == 0 && y == citraasli.Height - 1)
{
banding(citraasli, x, y, x , y - 1);
banding(citraasli, x, y, x + 1, y);
}
else
if (x > 0 && y == citraasli.Height - 1 && x < citraasli.Width - 1)
{
banding(citraasli, x, y, x - 1, y);
banding(citraasli, x, y, x + 1, y);
banding(citraasli, x, y, x, y - 1);
}
else
if (x == citraasli.Width - 1 && y == citraasli.Height - 1)
{
banding(citraasli, x, y, x, y - 1);
banding(citraasli, x, y, x - 1, y);
}
else
{
banding(citraasli, x, y, x , y - 1);
banding(citraasli, x, y, x , y + 1);
banding(citraasli, x, y, x - 1, y);
banding(citraasli, x, y, x + 1, y);
}
}
private void button1_Click(object sender, EventArgs e)
{
Bitmap citraasli = new Bitmap(pictureBox1.Image);
int lebar = citraasli.Width;
int panjang = citraasli.Height;
Console.Write(panjang + "," + lebar + " ukuran");
for (int i = 0; i < lebar; i++)
{
for (int j = 0; j < panjang; j++)
{
segmen(citraasli, i, j);
sudahdicek[i, j] = true;
}
}
for (int i = 0; i < lebar; i++)
{
for (int j = 0; j < panjang; j++)
{
Console.Write(sudahdicek[i, j]);
}
Console.WriteLine(" ");
}
Console.Write("berhasil");
pictureBox2.Image = citraasli;
}
}
}
Screenshot can be found at:
https://lh4.googleusercontent.com/Mfba0x9SHTq6WAEw8W4_MJLAjRZ_updeTBjRem8_k5OrdBrU4f1nOA4EA-EMJqMB0MDVcpH2Qzob2bo=w1896-h849[
^]