Click here to Skip to main content
15,563,248 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
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...
C#
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)
        {
            //Console.WriteLine("segmen jalan" + x + " ,, " + 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);
            }
            /*if (x > 0 && x < citraasli.Height && y + 1 > 0 && y + 1 < citraasli.Width)                
                banding(citraasli, x, y, x, y + 1);
            if (x-1> 0 && x-1< citraasli.Height && y > 0 && y < citraasli.Width)
                banding(citraasli, x, y, x-1, y);
            if (x > 0 && x < citraasli.Height && y-1 > 0 && y-1 < citraasli.Width)
                banding(citraasli, x, y, x, y-1);
            if (x + 1 > 0 && x + 1 < citraasli.Height && y > 0 && y < citraasli.Width)
                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;
                    
                    //Console.WriteLine(i+","+j + "jalan akhir");
                }
            }
            for (int i = 0; i < lebar; i++)
            {
                for (int j = 0; j < panjang; j++)
                {
                    Console.Write(sudahdicek[i, j]);
                   

                    //Console.WriteLine(i+","+j + "jalan akhir");
                }
                Console.WriteLine(" ");
            }
            Console.Write("berhasil");
            pictureBox2.Image = citraasli;
        }
    }
            
}


Screenshot can be found at: https://lh4.googleusercontent.com/Mfba0x9SHTq6WAEw8W4_MJLAjRZ_updeTBjRem8_k5OrdBrU4f1nOA4EA-EMJqMB0MDVcpH2Qzob2bo=w1896-h849[^]
Posted
Updated 1-Aug-15 3:18am
v2
Comments
Afzaal Ahmad Zeeshan 1-Aug-15 7:12am    
You may also want to show the screenshot of that image. :-)
Stitchme 1-Aug-15 8:07am    
https://drive.google.com/open?id=0B3b9kLkGP4ZOczgzS1M4V1h1MDQ
you can see the screenshot there.. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900