Ejemplo n.º 1
0
        public EdgeWindow(IntensityMap iMap, bool imageFit)
        {
            InitializeComponent();

            this.iMap = iMap;
            thresholdBar.Minimum = iMap.MinThreshold;
            thresholdBar.Maximum = iMap.MaxThreshold;
            thresholdBar.TickFrequency = (iMap.MaxThreshold - iMap.MinThreshold) / 10;

            int th = iMap.MinThreshold + (iMap.MaxThreshold - iMap.MinThreshold) / 10;
            thresholdBar.Value = th;
            changeThreshold(th);

            // Resize window
            int newWidth = Math.Max(this.PreferredSize.Width, 305);
            int newHeight = Math.Max(this.PreferredSize.Height, 246);
            if (!imageFit)
            {
                newWidth = Math.Min(newWidth, Screen.PrimaryScreen.Bounds.Width * 2 / 3);
                newHeight = Math.Min(newHeight, Screen.PrimaryScreen.Bounds.Height * 2 / 3);
            }
            this.Size = new Size(newWidth, newHeight);
        }
Ejemplo n.º 2
0
        private void button_Click(object sender, EventArgs e)
        {
            Button senderBtn = (Button)sender;
            string title = "";
            int[,] smoothingMask =  {   {1,  4,  7,  4, 1},
                                        {4, 16, 26, 16, 4},
                                        {7, 26, 41, 26, 7},
                                        {4, 16, 26, 16, 4},
                                        {1,  4,  7,  4, 1}   };

            IntensityMap iMap = new IntensityMap(image);

            if (senderBtn.Name == "gsButton")
            {
                ImageWindow newWindow = new ImageWindow(iMap.getBitmap(), imageFit);
                newWindow.Text = "Grayscale";
                newWindow.Show();
            }
            else if (senderBtn.Name == "smoothButton")
            {
                iMap.applyMask(smoothingMask, 273);
                ImageWindow newWindow = new ImageWindow(iMap.getBitmap(), imageFit);
                newWindow.Text = "Smoothed Grayscale";
                newWindow.Show();
            }
            else
            {
                iMap.applyMask(smoothingMask, 273);

                if (senderBtn.Name == "laplaceBtn")
                {
                    iMap.applyMask(new[,] { { 0, -1, 0 }, { -1, 4, -1 }, { 0, -1, 0 } });
                    title = "Laplace Edge Detection";
                }
                else if (senderBtn.Name == "prewittHBtn")
                {
                    iMap.applyMask(new[,] { { -1, -1, -1 }, { 0, 0, 0 }, { 1, 1, 1 } });
                    title = "Prewitt Horizontal Edge Detection";
                }
                else if (senderBtn.Name == "prewittVBtn")
                {
                    iMap.applyMask(new[,] { { -1, 0, 1 }, { -1, 0, 1 }, { -1, 0, 1 } });
                    title = "Prewitt Vertical Edge Detection";
                }
                else if (senderBtn.Name == "prewittSBtn")
                {
                    iMap.applyMask(new[,] { { -1, -1, 0 }, { -1, 0, 1 }, { 0, 1, 1 } });
                    title = "Prewitt Diagonal (/) Edge Detection";
                }
                else if (senderBtn.Name == "prewittBBtn")
                {
                    iMap.applyMask(new[,] { { 0, 1, 1 }, { -1, 0, 1 }, { -1, -1, 0 } });
                    title = "Prewitt Diagonal (\\) Edge Detection";
                }
                else if (senderBtn.Name == "sobelHBtn")
                {
                    iMap.applyMask(new[,] { { -1, -2, -1 }, { 0, 0, 0 }, { 1, 2, 1 } });
                    title = "Sobel Horizonal Edge Detection";
                }
                else if (senderBtn.Name == "sobelVBtn")
                {
                    iMap.applyMask(new[,] { { -1, 0, 1 }, { -2, 0, 2 }, { -1, 0, 1 } });
                    title = "Sobel Vertical Edge Detection";
                }
                else if (senderBtn.Name == "sobelSBtn")
                {
                    iMap.applyMask(new[,] { { -2, -1, 0 }, { -1, 0, 1 }, { 0, 1, 2 } });
                    title = "Sobel Diagonal (/) Edge Detection";
                }
                else if (senderBtn.Name == "sobelBBtn")
                {
                    iMap.applyMask(new[,] { { 0, 1, 2 }, { -1, 0, 1 }, { -2, -1, 0 } });
                    title = "Sobel Diagonal (\\) Edge Detection";
                }
                else if (senderBtn.Name == "kirschHBtn")
                {
                    iMap.applyMask(new[,] { { -5, -5, -5 }, { 3, 0, 3 }, { 3, 3, 3 } });
                    title = "Kirsch Horizonal Edge Detection";
                }
                else if (senderBtn.Name == "kirschVBtn")
                {
                    iMap.applyMask(new[,] { { -5, 3, 3 }, { -5, 0, 3 }, { -5, 3, 3 } });
                    title = "Kirsch Vertical Edge Detection";
                }
                else if (senderBtn.Name == "kirschSBtn")
                {
                    iMap.applyMask(new[,] { { -5, -5, 3 }, { -5, 0, 3 }, { 3, 3, 3 } });
                    title = "Kirsch Diagonal (/) Edge Detection";
                }
                else if (senderBtn.Name == "kirschBBtn")
                {
                    iMap.applyMask(new[,] { { 3, 3, 3 }, { -5, 0, 3 }, { -5, -5, 3 } });
                    title = "Kirsch Diagonal (\\) Edge Detection";
                }
                else if (senderBtn.Name == "robinsonHBtn")
                {
                    iMap.applyMask(new[,] { { 1, 1, 1 }, { 1, -2, 1 }, { -1, -1, -1 } });
                    title = "Robinson Horizontal Edge Detection";
                }
                else if (senderBtn.Name == "robinsonVBtn")
                {
                    iMap.applyMask(new[,] { { -1, 1, 1 }, { -1, -2, 1 }, { -1, 1, 1 } });
                    title = "Robinson Vertical Edge Detection";
                }
                else if (senderBtn.Name == "robinsonSBtn")
                {
                    iMap.applyMask(new[,] { { -1, -1, 1 }, { -1, -2, 1 }, { 1, 1, 1 } });
                    title = "Robinson Diagonal (/) Edge Detection";
                }
                else if (senderBtn.Name == "robinsonBBtn")
                {
                    iMap.applyMask(new[,] { { 1, 1, 1 }, { -1, -2, 1 }, { -1, -1, 1 } });
                    title = "Robinson Diagonal (\\) Edge Detection";
                }
                else if (senderBtn.Name == "robertsSBtn")
                {
                    iMap.applyMask(new[,] { { 0, 0, 0 }, { 0, -1, 0 }, { 0, 0, 1 } });
                    title = "Roberts Diagonal (/) Edge Detection";
                }
                else if (senderBtn.Name == "robertsBBtn")
                {
                    iMap.applyMask(new[,] { { 0, 0, 0 }, { 0, -1, 0 }, { 1, 0, 0 } });
                    title = "Roberts Diagonal (\\) Edge Detection";
                }

                EdgeWindow newWindow = new EdgeWindow(iMap, imageFit);
                newWindow.Text = title;
                newWindow.Show();
            }
        }