示例#1
0
        private void btnOpen_Click(object sender, EventArgs e)
        {
            double         before          = System.Environment.TickCount;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                //Open the browsed image and display it
                string OpenedFilePath = openFileDialog1.FileName;
                ImageMatrix = ImageOperations.OpenImage(OpenedFilePath);
                ImageOperations.DisplayImage(ImageMatrix, pictureBox1);
            }
            txtWidth.Text  = ImageOperations.GetWidth(ImageMatrix).ToString();
            txtHeight.Text = ImageOperations.GetHeight(ImageMatrix).ToString();

            //my role
            Operations();
            double after  = System.Environment.TickCount;
            double result = after - before;

            msec.Text = result.ToString() + " M-Sec";
            result   /= 1000;
            sec.Text  = result.ToString() + " Sec";
        }
示例#2
0
        private void btnOpen_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog openFileDialog1 = new OpenFileDialog();
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    //Open the browsed image and display it
                    string OpenedFilePath = openFileDialog1.FileName;

                    ImageMatrix           = ImageOperations.OpenImage(OpenedFilePath);
                    Width                 = ImageOperations.GetWidth(ImageMatrix);
                    Height                = ImageOperations.GetHeight(ImageMatrix);
                    Program.OriginalImage = new RGBPixel[Height, Width];
                    Program.OriginalImage = ImageMatrix;
                }
                txtWidth.Text  = ImageOperations.GetWidth(ImageMatrix).ToString();
                txtHeight.Text = ImageOperations.GetHeight(ImageMatrix).ToString();
            }
            catch
            {
                MessageBox.Show("No image selected.");
            }
        }
示例#3
0
        private void btnQuantize_Click(object sender, EventArgs e)
        {
            long before = System.Environment.TickCount;                                          // get the current time in miliseconds  // -> O(1)
            int  K      = (int)ClusterK.Value;                                                   // -> O(1)

            txtDisColor.Text = ImageAnalytics.Find_Distinct_Color(ImageMatrix).ToString();       // -> O(W*H)
            txtMST.Text      = (Math.Round(ImageAnalytics.MinimumSpanningTree(), 2)).ToString(); // -> O(E Log V)
            DetectNumOfClusters x = new DetectNumOfClusters(ImageAnalytics.edges);               // -> O(E*V)

            if (K == 0)
            {
                K = x.k;                                               // -> O(1)
            }
            QuantizeImage.Extract_K_Cluster(K);                        // -> O(K*D)
            QuantizeImage.Find_K_Cluster();                            // -> O(D)
            ImageOperations.DisplayImage(ImageMatrix, pictureBox2, 1); //O(N^2) where N is the height or the weight of image
            ClusterK.Value = K;                                        // print the number of cluster if changed // -> O(1)
            long   after = System.Environment.TickCount;               // get the current time // -> O(1)
            double total = after - before;                             // Calculate the taken time // -> O(1)

            total         /= 60000;                                    // convert miliseconds to minutes // -> O(1)
            total          = Math.Round(total, 3);                     // Round the Minutes to three decimal digits // -> O(1)
            TimeLable.Text = total.ToString() + " M (s)";              // -> O(1)
        }
示例#4
0
 public static RGBPixel[,] dec(int pass, RGBPixel[,] pic, int position, int len) //ϴ(n^2)
 {
     RGBPixel[,] decrepted;
     decrepted = ImageOperations.enc(pass, pic, position, len); //ϴ(n^2)
     return(decrepted);
 }
示例#5
0
        private void button1_Click(object sender, EventArgs e)
        {
            Stopwatch sp = new Stopwatch();

            sp.Start();
            long[]         Red_array      = new long[256];
            long[]         Green_array    = new long[256];
            long[]         Blue_array     = new long[256];
            Priority_Queue Red_priority   = new Priority_Queue();
            Priority_Queue Green_priority = new Priority_Queue();
            Priority_Queue Blue_priority  = new Priority_Queue();

            Red_Huffman   = new HuffmanTree();
            Green_Huffman = new HuffmanTree();
            Blue_Huffman  = new HuffmanTree();

            List <HuffmanNode> Red_Nodes   = new List <HuffmanNode>();
            List <HuffmanNode> Green_Nodes = new List <HuffmanNode>();
            List <HuffmanNode> Blue_Nodes  = new List <HuffmanNode>();

            Red_Root   = new HuffmanNode();
            Green_Root = new HuffmanNode();
            Blue_Root  = new HuffmanNode();

            int Height = ImageOperations.GetHeight(ImageMatrix);
            int width  = ImageOperations.GetWidth(ImageMatrix);

            for (int h = 0; h < Height; h++)
            {
                for (int w = 0; w < width; w++)
                {
                    Red_array[ImageMatrix[h, w].red]++;
                    Green_array[ImageMatrix[h, w].green]++;
                    Blue_array[ImageMatrix[h, w].blue]++;
                }
            }

            for (int k = 0; k < 256; k++)
            {
                if (Red_array[k] > 0)
                {
                    Red_Nodes.Add(new HuffmanNode {
                        value = Convert.ToByte(k), freq = Red_array[k], CoLoR_CoDe = ""
                    });
                }
                if (Green_array[k] > 0)
                {
                    Green_Nodes.Add(new HuffmanNode {
                        value = Convert.ToByte(k), freq = Green_array[k], CoLoR_CoDe = ""
                    });
                }
                if (Blue_array[k] > 0)
                {
                    Blue_Nodes.Add(new HuffmanNode {
                        value = Convert.ToByte(k), freq = Blue_array[k], CoLoR_CoDe = ""
                    });
                }
            }
            Red_priority.Build_Min_Heap(ref Red_Nodes);
            Green_priority.Build_Min_Heap(ref Green_Nodes);
            Blue_priority.Build_Min_Heap(ref Blue_Nodes);

            Red_Root   = Red_Huffman.BuildHuffmanTree(ref Red_Nodes);
            Green_Root = Green_Huffman.BuildHuffmanTree(ref Green_Nodes);
            Blue_Root  = Blue_Huffman.BuildHuffmanTree(ref Blue_Nodes);

            FileStream Trunc_Red_File = new FileStream("Red_Info.txt", FileMode.Truncate);

            Trunc_Red_File.Close();
            FileStream   Red_File   = new FileStream("Red_Info.txt", FileMode.Append);
            StreamWriter Red_Writer = new StreamWriter(Red_File);

            Red_Writer.WriteLine("--R--");
            Red_Writer.WriteLine("Color - Frequency - Huffman Representation - Total Bits");
            Red_Writer.Close();
            Red_File.Close();
            Red_Huffman.PrintCodes(Red_Root, "", "Red_Info.txt");

            FileStream Trunc_Green_File = new FileStream("Green_Info.txt", FileMode.Truncate);

            Trunc_Green_File.Close();
            FileStream   Green_File   = new FileStream("Green_Info.txt", FileMode.Append);
            StreamWriter Green_Writer = new StreamWriter(Green_File);

            Green_Writer.WriteLine("--G--");
            Green_Writer.WriteLine("Color - Frequency - Huffman Representation - Total Bits");
            Green_Writer.Close();
            Green_File.Close();
            Green_Huffman.PrintCodes(Green_Root, "", "Green_Info.txt");

            FileStream Trunc_Blue_File = new FileStream("Blue_Info.txt", FileMode.Truncate);

            Trunc_Blue_File.Close();
            FileStream   Blue_File   = new FileStream("Blue_Info.txt", FileMode.Append);
            StreamWriter Blue_Writer = new StreamWriter(Blue_File);

            Blue_Writer.WriteLine("--B--");
            Blue_Writer.WriteLine("Color - Frequency - Huffman Representation - Total Bits");
            Blue_Writer.Close();
            Blue_File.Close();
            Blue_Huffman.PrintCodes(Blue_Root, "", "Blue_Info.txt");

            FileStream truncate_total_info = new FileStream("Total_Info.dat", FileMode.Truncate);

            truncate_total_info.Close();


            sp.Stop();
            lbl_construct_tree.Text = sp.Elapsed.ToString();
            MessageBox.Show("Constructed !");
        }
示例#6
0
 private void button22_Click(object sender, EventArgs e)
 {
     ImageOperations.save(ImageMatrix);
 }
示例#7
0
 private void button12_Click(object sender, EventArgs e)
 {
     ImageOperations.greyscale(ImageMatrix, pictureBox6);
 }
示例#8
0
        private void button2_Click(object sender, EventArgs e)
        {
            string       path       = textBox1.Text;
            Stream       readStream = new FileStream(path, FileMode.Open);
            BinaryReader br         = new BinaryReader(readStream);

            int height  = br.ReadInt32();
            int width   = br.ReadInt32();
            int initial = br.ReadInt32();
            int tap     = br.ReadInt32();

            int redCount   = br.ReadInt16();
            int redpadding = br.ReadByte();

            byte[] redBytes     = br.ReadBytes(redCount);
            int    greenCount   = br.ReadInt16();
            int    greenpadding = br.ReadByte();

            byte[] greenBytes  = br.ReadBytes(greenCount);
            int    blueCount   = br.ReadInt16();
            int    bluepadding = br.ReadByte();

            byte[] blueBytes = br.ReadBytes(blueCount);
            br.Close();
            string red = "";

            foreach (var item in redBytes)
            {
                red += Convert.ToString(item, 2).PadLeft(8, '0');
            }
            string green = "";

            foreach (var item in greenBytes)
            {
                green += Convert.ToString(item, 2).PadLeft(8, '0');
            }
            string blue = "";

            foreach (var item in blueBytes)
            {
                blue += Convert.ToString(item, 2).PadLeft(8, '0');
            }
            Dictionary <string, byte> redDic   = new Dictionary <string, byte>(256);
            Dictionary <string, byte> greenDic = new Dictionary <string, byte>(256);
            Dictionary <string, byte> blueDic  = new Dictionary <string, byte>(256);

            ImageOperations.getdic(ref redDic, red, ref redpadding, "");
            ImageOperations.getdic(ref greenDic, green, ref greenpadding, "");
            ImageOperations.getdic(ref blueDic, blue, ref bluepadding, "");
            string res = height.ToString() + " " + width.ToString() + " " + initial + " " + tap + System.Environment.NewLine;

            foreach (var item in redDic)
            {
                res += string.Format("{0}:{1}{2}", item.Key, item.Value, System.Environment.NewLine);
            }
            res += "blue:" + System.Environment.NewLine;
            foreach (var item in blueDic)
            {
                res += string.Format("{0}:{1}{2}", item.Key, item.Value, System.Environment.NewLine);
            }
            res += "green:" + System.Environment.NewLine;
            foreach (var item in greenDic)
            {
                res += string.Format("{0}:{1}{2}", item.Key, item.Value, System.Environment.NewLine);
            }
            System.IO.File.WriteAllText("path.txt", res);
        }
        private void btnGaussSmooth_Click(object sender, EventArgs e)
        {
            int sigma = 0;

            if (txtGaussSigma.Text.ToString() != "")
            {
                sigma = int.Parse(txtGaussSigma.Text);
            }

            MST_value.Text = "";
            if (sigma > li.Count || sigma == 0)
            {
                MessageBox.Show(" Please Enter a valid Number of cluster .");
            }
            else if (TypeofCluster.Text == "")
            {
                MessageBox.Show(" Please Choose Type of Clustering .");
            }
            else
            {
                RGBPixel[, ,] grid = RGB.Clone() as RGBPixel[, , ]; // Get Clone  to Save True 3dRGP
                if (TypeofCluster.Text == TypeofCluster.Items[0].ToString())
                {
                    quan = new MST(ref li, sigma, grid, Auto_Detect.Checked);
                    quan.getcluster();
                    if (Auto_Detect.Checked == true)
                    {
                        txtGaussSigma.Text = quan.Pallete.Count.ToString();
                    }
                    MST_value.Text = "MST Value: " + (quan as MST).MST_Value.ToString();
                }
                else if (TypeofCluster.Text == TypeofCluster.Items[1].ToString())
                {
                    quan = new Kmean(ref li, ref sigma, grid);
                    quan.getcluster();
                }
                else if (TypeofCluster.Text == TypeofCluster.Items[2].ToString())
                {
                    if (MedianCutCluster.Text != "")
                    {
                        sigma = int.Parse(MedianCutCluster.Text);
                        if (sigma < li.Count)
                        {
                            quan = new MedianCutHelper(ref li, sigma, grid);
                            quan.getcluster();
                        }
                        else
                        {
                            MessageBox.Show("Invalid Number of Cluster .");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please Choose Number of Cluster .");
                    }
                }

                else
                {
                    MessageBox.Show("Invalid Quantizer Method .");
                }
                ImageOperations.DisplayImage(ImageMatrix, pictureBox2, grid);
            }
        }
 private void button1_Click(object sender, EventArgs e)
 {
     ImageOperations.huffman_encoding(ImageMatrix);
 }
示例#11
0
        private void btnGaussSmooth_Click(object sender, EventArgs e)
        {
            // Begin timing.
            stopwatch.Start();

            int k = int.Parse(k_txt.Text);

            mst_edges     = prim_algo.prim_edit(my_distinct);
            textBox1.Text = (Math.Round(mst_edges.Item1, 1)).ToString();

            //   for (int i = 0; i < mst_edges.Item2.Count; i++)
            //       MessageBox.Show(mst_edges.Item2[i].ToString());

            List <edges> sortedMST = prim_algo.Sort(mst_edges.Item2);                           //;;  SORT

            if (k - 1 > sortedMST.Count || k == 1 || k == 0)
            {
                MessageBox.Show("K is not allawed!");
                return;
            }
            if (my_distinct.Count == 0)
            {
                MessageBox.Show("No Image entered !");
                return;
            }
            //MessageBox.Show(mst_edges.Item2.Count.ToString() + "edges ");


            int[] my_clusters = new int[sortedMST.Count + 1];


            Graph g = new Graph(my_distinct.Count, false);                  //  vertices    ->(undirected)

            for (int i = k - 1; i < sortedMST.Count; i++)                   // skip longest k-1 edges then buit graph from the rest
            {
                g.AddEdge(sortedMST[i].from, sortedMST[i].to);
            }

            for (int index = 0; index < my_clusters.Length; index++)
            {
                my_clusters[index] = get_avg(g.BreadthFirstSearch(index));
            }

            // all its values is zero


            for (int i = 0; i < ImageOperations.GetHeight(ImageMatrix); i++)
            {
                for (int j = 0; j < ImageOperations.GetWidth(ImageMatrix); j++)
                {
                    int rgb = ImageMatrix[i, j].red;
                    rgb = (rgb << 8) + ImageMatrix[i, j].green;
                    rgb = (rgb << 8) + ImageMatrix[i, j].blue;

                    int rgb1 = agian[rgb];

                    int r11 = (rgb1 >> 16) & 0xFF;
                    int g11 = (rgb1 >> 8) & 0xFF;
                    int b11 = rgb1 & 0xFF;
                    //mst_edges.Item2.Clear();
                    ImageMatrix[i, j].red   = (byte)r11;
                    ImageMatrix[i, j].green = (byte)g11;
                    ImageMatrix[i, j].blue  = (byte)b11;
                }
            }

            ImageOperations.DisplayImage(ImageMatrix, pictureBox2);

            stopwatch.Stop();

            // Write result.
            textBox2.Text = stopwatch.Elapsed.ToString();
        }
示例#12
0
 private void mailestoneOne()
 {
     numberofcolor.Text = ImageOperations.Get_Number_of_color(ImageMatrix).ToString();
     mst          = ImageOperations.MST_Weight(ImageMatrix);
     MST_Sum.Text = mst.Weight.ToString();
 }
示例#13
0
 private void colorbutton_Click(object sender, EventArgs e)
 {
     colortext.Clear();
     colortext.Text = ImageOperations.distinct_colour().Count.ToString();
 }
示例#14
0
        public static void EncodeAndDecode(ref RGBPixel[,] ImageMatrix, BitArray seedInBit, int Tap)
        {
            int length = seedInBit.Length - 1;

            int[] valueInDecimal = new int[1];
            seedInBit.CopyTo(valueInDecimal, 0);
            BitArray Seed = new BitArray(new int[] { valueInDecimal[0] });

            RGBPixel[,] Imageenc = new RGBPixel[ImageOperations.GetHeight(ImageMatrix), ImageOperations.GetWidth(ImageMatrix)];
            byte valueInByte = new byte();

            byte[]   valueAftermodification = new byte[1];
            BitArray valueInBits;

            for (int i = 0; i < ImageOperations.GetHeight(ImageMatrix); i++)
            {
                for (int j = 0; j < ImageOperations.GetWidth(ImageMatrix); j++)
                {
                    valueInByte = ImageMatrix[i, j].red;
                    valueInBits = new BitArray(new byte[] { valueInByte });
                    BitArray SeedAfterShifting = ImageOperations.xorKEy(ref Seed, length, Tap);
                    ImageOperations.xorr(SeedAfterShifting, valueInBits).CopyTo(valueAftermodification, 0);
                    Imageenc[i, j].red = valueAftermodification[0];

                    valueInByte       = ImageMatrix[i, j].green;
                    valueInBits       = new BitArray(new byte[] { valueInByte });
                    SeedAfterShifting = ImageOperations.xorKEy(ref Seed, length, Tap);
                    ImageOperations.xorr(SeedAfterShifting, valueInBits).CopyTo(valueAftermodification, 0);
                    Imageenc[i, j].green = valueAftermodification[0];

                    valueInByte       = ImageMatrix[i, j].blue;
                    valueInBits       = new BitArray(new byte[] { valueInByte });
                    SeedAfterShifting = ImageOperations.xorKEy(ref Seed, length, Tap);
                    ImageOperations.xorr(SeedAfterShifting, valueInBits).CopyTo(valueAftermodification, 0);
                    Imageenc[i, j].blue = valueAftermodification[0];
                }
            }
            ImageMatrix = Imageenc;
        }
示例#15
0
        public static RGBPixel[,] decompress(string path)
        {
            int fileoffset;//Θ(1)

            byte[]  fileData    = FileToByteArray(path);
            int     RedTreesize = BitConverter.ToInt32(fileData, 0);                                                                                  //Θ(1)  n=4
            Huffman huffmanRed  = new Huffman(getPriorityQueue(Encoding.ASCII.GetString(fileData, 4, RedTreesize)));                                  //Θ(N) n is size of redTree

            int     greenTreesize = BitConverter.ToInt32(fileData, RedTreesize + 4);                                                                  //Θ(1)  n=4
            Huffman huffmanGreen  = new Huffman(getPriorityQueue(Encoding.ASCII.GetString(fileData, 8 + RedTreesize, greenTreesize)));                //Θ(N) n is size of greenTree

            int     blueTreesize = BitConverter.ToInt32(fileData, 8 + greenTreesize + RedTreesize);                                                   //Θ(1)  n=4
            Huffman huffmanBlue  = new Huffman(getPriorityQueue(Encoding.ASCII.GetString(fileData, 12 + greenTreesize + RedTreesize, blueTreesize))); //Θ(N) n is size of blueTree

            fileoffset = RedTreesize + blueTreesize + greenTreesize + 12;                                                                             //Θ(1)

            int width = BitConverter.ToInt32(fileData, fileoffset);                                                                                   //Θ(1)  n=4

            fileoffset += 4;                                                                                                                          //Θ(1)
            int height = BitConverter.ToInt32(fileData, fileoffset);                                                                                  //Θ(1)  n=4

            fileoffset += 4;                                                                                                                          //Θ(1)
            int seedLength = BitConverter.ToInt32(fileData, fileoffset);                                                                              //Θ(1)  n=4

            fileoffset += 4;                                                                                                                          //Θ(1)

            string seed = Encoding.ASCII.GetString(fileData, fileoffset, seedLength);                                                                 //Θ(N) n is size of Seed

            fileoffset += seedLength;                                                                                                                 //Θ(1)

            int tap = (int)BitConverter.ToInt16(fileData, fileoffset);                                                                                //Θ(1)  n=2

            fileoffset += 2;                                                                                                                          //Θ(1)

            int redL = BitConverter.ToInt32(fileData, fileoffset);                                                                                    //Θ(1)  n=4

            fileoffset += 4;                                                                                                                          //Θ(1)

            int greenL = BitConverter.ToInt32(fileData, fileoffset);                                                                                  //Θ(1)  n=4

            fileoffset += 4;                                                                                                                          //Θ(1)

            int blueL = BitConverter.ToInt32(fileData, fileoffset);                                                                                   //Θ(1)  n=4

            fileoffset += 4;                                                                                                                          //Θ(1)

            redL -= greenL;                                                                                                                           //Θ(1)
            redL -= blueL;                                                                                                                            //Θ(1)

            byte[] binR = new byte[fileData.Length - fileoffset];                                                                                     //Θ(1)
            Array.Copy(fileData, fileoffset, binR, 0, fileData.Length - fileoffset);                                                                  //Θ(N) n is size of BinR

            BitArray bR = new BitArray(binR);                                                                                                         //Θ(N) n is size of BinR

            countR = 0;                                                                                                                               //Θ(1)
            countG = redL;                                                                                                                            //Θ(1)
            countB = redL + greenL;                                                                                                                   //Θ(1)

            RGBPixel[,] Image = new RGBPixel[width, height];                                                                                          //Θ(1)
            //Θ(N^2*K) K is size of binary node represation;
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    Image[i, j].red = getColor(huffmanRed.start, bR, ref countR);     //Θ(N) n is size of binary represtation of node

                    Image[i, j].green = getColor(huffmanGreen.start, bR, ref countG); //Θ(N) n is size of binary represtation of node

                    Image[i, j].blue = getColor(huffmanBlue.start, bR, ref countB);   //Θ(N) n is size of binary represtation of node
                }
            }

            ImageOperations.encrypt(Image, tap, seed); //Θ(N^2) large between width and height
            return(Image);                             //Θ(1)
        }
示例#16
0
        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            /*----------------------------------CONSTRUCTION Begin------------------------------------------------------*/

            if (comboBox2.SelectedItem == "Compress")
            {
                int[] RedFreq   = new int[256];
                int[] GreenFreq = new int[256];
                int[] BlueFreq  = new int[256];
                int   height    = ImageOperations.GetHeight(encryptedimg);
                int   width     = ImageOperations.GetWidth(encryptedimg);
                RGBPixel[,] CompressedImg = new RGBPixel[height, width];

                for (int intializer = 0; intializer < 256; intializer++)
                {
                    RedFreq[intializer]   = 0;
                    GreenFreq[intializer] = 0;
                    BlueFreq[intializer]  = 0;
                }
                for (int i = 0; i < height; i++)
                {
                    for (int j = 0; j < width; j++)
                    {
                        RGBPixel pixel = encryptedimg[i, j];
                        RedFreq[pixel.red]     += 1;
                        GreenFreq[pixel.green] += 1;
                        BlueFreq[pixel.blue]   += 1;
                    }
                }
                IDictionary <byte, int> HuffmanRed   = new Dictionary <byte, int>();
                IDictionary <byte, int> HuffmanGreen = new Dictionary <byte, int>();
                IDictionary <byte, int> HuffmanBlue  = new Dictionary <byte, int>();
                byte key = 0;
                for (int looper = 0; looper <= 255; looper++)
                {
                    HuffmanRed.Add(key, RedFreq[key]);
                    HuffmanGreen.Add(key, GreenFreq[key]);
                    HuffmanBlue.Add(key, BlueFreq[key]);
                    key++;
                }
                ImageEncryptCompress.HuffmanTree RedTree   = new ImageEncryptCompress.HuffmanTree(HuffmanRed);
                ImageEncryptCompress.HuffmanTree GreenTree = new ImageEncryptCompress.HuffmanTree(HuffmanGreen);
                ImageEncryptCompress.HuffmanTree BlueTree  = new ImageEncryptCompress.HuffmanTree(HuffmanBlue);

                /*----------CONSTRUCTION END------------------------------------------------------*/

                IDictionary <byte, string> RedEncodings   = RedTree.CreateEncodings();
                IDictionary <byte, string> GreenEncodings = GreenTree.CreateEncodings();
                IDictionary <byte, string> BlueEncodings  = BlueTree.CreateEncodings();
                for (int i = 0; i < height; i++)
                {
                    for (int j = 0; j < width; j++)
                    {
                        RGBPixel pixel      = encryptedimg[i, j];
                        string   redValue   = RedEncodings[pixel.red];
                        string   greenValue = GreenEncodings[pixel.green];
                        string   blueValue  = BlueEncodings[pixel.blue];
                        RGBPixel newPixel   = new RGBPixel();
                        newPixel.red        = Convert.ToByte(redValue, 2);
                        newPixel.green      = Convert.ToByte(greenValue, 2);
                        newPixel.blue       = Convert.ToByte(blueValue, 2);
                        CompressedImg[i, j] = newPixel;
                    }
                }
                //   ImageOperations.DisplayImage(CompressedImg, pictureBox2);
            }
        }
示例#17
0
        public RGBPixel[,] encryptOrdecrypt(RGBPixel[,] ImageMatrix)
        {
            int    width = ImageOperations.GetWidth(ImageMatrix);
            string seed;
            bool   useAlphaPassword = false;

            if (checkBox1.Checked == true)
            {
                useAlphaPassword = true;
            }
            if (useAlphaPassword)
            {
                seed = toBinaryString(textBox2.Text);
            }
            else
            {
                seed = textBox2.Text;
            }
            int tapIndex = int.Parse(textBox1.Text);
            int height   = ImageOperations.GetHeight(ImageMatrix);

            RGBPixel[,] EncryptedImageMatrix = new RGBPixel[height, width];
            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    RGBPixel pixel = ImageMatrix[i, j];
                    for (int k = 0; k < 8; k++)
                    {
                        seed = step(seed, tapIndex);
                    }
                    int    index = seed.Length - 8;
                    string e     = "";
                    for (int empededZ = 0; empededZ < (8 - seed.Length); empededZ++)
                    {
                        e += "0";
                    }
                    string xoringseed = seed.Length >= 8 ? seed.Substring(index, 8) : e + seed;
                    string newRed     = xor(xoringseed, pixel.red);
                    for (int k = 0; k < 8; k++)
                    {
                        seed = step(seed, tapIndex);
                    }
                    index = seed.Length - 8;
                    e     = "";
                    for (int empededZ = 0; empededZ < (8 - seed.Length); empededZ++)
                    {
                        e += "0";
                    }
                    xoringseed = seed.Length >= 8 ? seed.Substring(index, 8) : e + seed;
                    string newGreen = xor(xoringseed, pixel.green);
                    for (int k = 0; k < 8; k++)
                    {
                        seed = step(seed, tapIndex);
                    }
                    index = seed.Length - 8;
                    e     = "";
                    for (int empededZ = 0; empededZ < (8 - seed.Length); empededZ++)
                    {
                        e += "0";
                    }
                    xoringseed = seed.Length >= 8 ? seed.Substring(index, 8) : e + seed;
                    string   newBlue  = xor(xoringseed, pixel.blue);
                    RGBPixel NewPixel = new RGBPixel();
                    NewPixel.red               = binarytobyte(newRed);
                    NewPixel.green             = binarytobyte(newGreen);
                    NewPixel.blue              = binarytobyte(newBlue);
                    EncryptedImageMatrix[i, j] = NewPixel;
                }
            }
            return(EncryptedImageMatrix);
        }
示例#18
0
        private void btnOpen_Click(object sender, EventArgs e)
        {
            //PriorityQueue<KeyValuePair<double, KeyValuePair<RGBPixel, RGBPixel>>> P =
            //new PriorityQueue<KeyValuePair<double, KeyValuePair<RGBPixel, RGBPixel>>>((int)1e8);


            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                //Open the browsed image and display it
                string OpenedFilePath = openFileDialog1.FileName;
                ImageMatrix = ImageOperations.OpenImage(OpenedFilePath);
                ImageOperations.DisplayImage(ImageMatrix, pictureBox1);

                List <RGBPixel> listOfDistColor = ExtractDistColors(ImageMatrix);
            }

            /* while (P.Size() > 0)
             * {
             *   MessageBox.Show(P.Dequeue().Key.ToString());
             * }*/
            System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
            double ans = prim(listOfDistColor.Count, listOfDistColor);

            find_cal();
            adjustMatrix(ref ImageMatrix);
            sw.Stop();
            long time = sw.ElapsedMilliseconds;

            //OpenedFilePath = openFileDialog1.FileName;
            //ImageMatrix = ImageOperations.OpenImage(OpenedFilePath);
            ImageOperations.DisplayImage(ImageMatrix, pictureBox2);

            MessageBox.Show(ans.ToString() + " && " + listOfDistColor.Count.ToString());
            MessageBox.Show("Time elapsed: " + time + "ms ");

            /*int k=3;
             * List<RGBPixel> centers = new List<RGBPixel>();
             * Dictionary<int, int> dec = new Dictionary<int, int>();
             * while (centers.Count < k)
             * {
             *  Random rnd = new Random();
             *  int rd = rnd.Next(0, 1000000000)% listOfDistColor.Count;
             *  if (dec[rd] == 0)
             *  {
             *      centers.Add(listOfDistColor[rd]);
             *      dec[rd] = 1;
             *  }
             * }
             * dec.Clear();
             * List<int> myList = new List<int>(listOfDistColor.Count);
             * for(int ii = 0; ii < listOfDistColor.Count; ++ii)
             * {
             *  myList[ii] = -1;
             * }
             * double Last_error = 0;
             * while (true)
             * {
             *  for(int ii = 0; ii < listOfDistColor.Count; ++ii)
             *  {
             *      int cid = find_cal(listOfDistColor, listOfDistColor[ii]);
             *      myList[ii]=cid;
             *
             *  }
             *
             * }*/

            txtWidth.Text  = ImageOperations.GetWidth(ImageMatrix).ToString();
            txtHeight.Text = ImageOperations.GetHeight(ImageMatrix).ToString();
        }
 private void quantizedToolStripMenuItem1_Click(object sender, EventArgs e)
 {
     if (Histo != null)
     {
         Histo.Close();
     }
     if (pictureBox2.Image != null)
     {
         Histo = new Histogram((Bitmap)pictureBox2.Image, ImageOperations.GetHeight(ImageMatrix), ImageOperations.GetWidth(ImageMatrix));
         Histo.Show();
     }
     else
     {
         MessageBox.Show("Please Select an Image .");
     }
 }
示例#20
0
 private void button1_Click(object sender, EventArgs e)
 {
     ImageOperations.DisplayImage(ImageMatrix, pictureBox2);
 }
示例#21
0
 private void btnGaussSmooth_Click(object sender, EventArgs e)
 {
     K = double.Parse(txtGaussSigma.Text);
     GetConstractGrph(ImageMatrix, ImageOperations.GetHeight(ImageMatrix), ImageOperations.GetWidth(ImageMatrix));
     ImageOperations.DisplayImage(ImageMatrix, pictureBox2);
 }
示例#22
0
        public static void sum(int N, RGBPixel[,] image, string crack, int tapPosition)
        {
            long sz = 0;

            int[] array_red   = new int[256];
            int[] array_green = new int[256];
            int[] array_blue  = new int[256];
            int   Height      = ImageOperations.GetHeight(image);
            int   Width       = ImageOperations.GetWidth(image);

            for (int l = 0; l < Height; l++)
            {
                for (int j = 0; j < Width; j++)
                {
                    if (array_red[image[l, j].red] == 0)
                    {
                        sz++;
                    }
                    if (array_green[image[l, j].green] == 0)
                    {
                        sz++;
                    }
                    if (array_blue[image[l, j].blue] == 0)
                    {
                        sz++;
                    }
                    array_red[image[l, j].red]++;
                    array_green[image[l, j].green]++;
                    array_blue[image[l, j].blue]++;
                }
            }

            lock (all)
            {
                TMP = sz;
                TMP = 768 - TMP;
                if (TMP > CNTA)
                {
                    all_sz        = 0;
                    all[all_sz].S = crack;
                    all[all_sz].T = tapPosition;
                    all_sz++;

                    //FinalCrack = string.Copy(crack).ToCharArray();
                    CNTA = TMP;
                    //for (int i = 0; i < N; i++)
                    //    FinalCrack[i] = Crack[i];
                    //FinalTapPosition = tapPosition;
                }
                else if (TMP == CNTA)
                {
                    all[all_sz].S = crack;
                    all[all_sz].T = tapPosition;
                    all_sz++;
                    //FinalCrack = string.Copy(crack).ToCharArray();
                    CNTA = TMP;
                    //for (int i = 0; i < N; i++)
                    //    FinalCrack[i] = Crack[i];
                    //FinalTapPosition = tapPosition;
                }
            }
        }
示例#23
0
 private void button13_Click(object sender, EventArgs e)
 {
     ImageOperations.reverse(ImageMatrix, pictureBox6);
 }
 private void button1_Click(object sender, EventArgs e)
 {
     EncryptionImageMatrix = ImageOperations.EncryptImage(EncryptionImageMatrix, 6, "10001111");
     ImageOperations.DisplayImage(EncryptionImageMatrix, pictureBox2);
 }
示例#25
0
 private void button16_Click(object sender, EventArgs e)
 {
     pictureBox9.SizeMode = PictureBoxSizeMode.StretchImage;
     ImageOperations.DisplayImage(ImageMatrix, pictureBox9);
 }
 private void EncBtn_Click(object sender, EventArgs e)
 {
     ImageMatrix_Enc = ImageOperations.Process(ImageMatrix, initSeedTxt.Text, Convert.ToInt32(TapIndxUpDown.Value));
     ImageOperations.DisplayImage(ImageMatrix_Enc, pictureBox2);
 }
        private void btnOpen_Click(object sender, EventArgs e)
        {
            distColorsBox1.Text     = "";
            distinctColorsBox2.Text = "";
            ClustersNumber.Text     = "";
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                //Open the browsed image and display it

                string OpenedFilePath = openFileDialog1.FileName;
                ImageMatrix = ImageOperations.OpenImage(OpenedFilePath);
                ImageOperations.DisplayImage(ImageMatrix, pictureBox1);
                WhiteDistButton.Enabled = true;
                MstQtButton.Enabled     = true;
                ClustersNumber.Enabled  = true;
            }
            else
            {
                MessageBox.Show("please open an Image");
                return;
            }
            txtWidth.Text  = ImageOperations.GetWidth(ImageMatrix).ToString();
            txtHeight.Text = ImageOperations.GetHeight(ImageMatrix).ToString();

            distColorsBox1.Text = CalculateOriginalDistinctColors(ImageOperations.GetHeight(ImageMatrix), ImageOperations.GetWidth(ImageMatrix)).ToString();
        }
示例#28
0
        private void btnGaussSmooth_Click(object sender, EventArgs e)
        {
            // Begin timing.
            stopwatch.Start();

            int k = int.Parse(k_txt.Text);

            mst_edges     = prim_algo.prim_edit(my_distinct);
            textBox1.Text = (Math.Round(mst_edges.Item1, 3)).ToString();


            List <edges> sortedMST = prim_algo.Sort(mst_edges.Item2);           //  SORT  O( E log|E| )  |E| -> number of edges

            if (k - 1 > sortedMST.Count || k == 1 || k == 0)
            {
                MessageBox.Show("K is not allawed!");
                return;
            }
            if (my_distinct.Count == 0)
            {
                MessageBox.Show("No Image entered !");
                return;
            }


            int[] my_clusters = new int[sortedMST.Count + 1];  // max_size = # of V

            Graph g = new Graph(my_distinct.Count, false);     // construct (undirected) Graph  ( vertices = # distinct color )

            for (int i = k - 1; i < sortedMST.Count; i++)      // skip (~ cut) longest k-1 edges then build graph from the rest
            {
                g.AddEdge(sortedMST[i].from, sortedMST[i].to);
            }
            int test = 0;

            for (int i = 0; i < k - 1; i++)
            {
                if (MY_visited[sortedMST[i].from] == false)
                {
                    my_clusters[sortedMST[i].from] = get_avg(g.BreadthFirstSearch(sortedMST[i].from)); test++;
                }
                if (MY_visited[sortedMST[i].to] == false)
                {
                    my_clusters[sortedMST[i].to] = get_avg(g.BreadthFirstSearch(sortedMST[i].to)); test++;
                }
            }

            int[] optimize = new int[90000000];    // all its values is zero

            int size_mycluster = my_clusters.Length;

            //    MessageBox.Show(test.ToString());



            ///////////////////////////////////////////

            for (int i = 0; i < ImageOperations.GetHeight(ImageMatrix); i++)        //
            {
                for (int j = 0; j < ImageOperations.GetWidth(ImageMatrix); j++)
                {
                    double minn = 0;
                    int    rgb  = ImageMatrix[i, j].red;
                    rgb = (rgb << 8) + ImageMatrix[i, j].green;
                    rgb = (rgb << 8) + ImageMatrix[i, j].blue;
                    if (optimize[rgb] == 0)                  // if you see this rgb befor returns its value
                    {
                        for (int count = 0; count < size_mycluster; count++)
                        {
                            int rgbb = my_clusters[count];

                            int r1 = (rgbb >> 16) & 0xFF;
                            int g1 = (rgbb >> 8) & 0xFF;
                            int b1 = rgbb & 0xFF;

                            byte   r2  = ImageMatrix[i, j].red;;
                            byte   g2  = ImageMatrix[i, j].green;
                            byte   b2  = ImageMatrix[i, j].blue;
                            double dis = (((r1 - r2) * (r1 - r2) + (g1 - g2) * (g1 - g2) + (b1 - b2) * (b1 - b2)));
                            if (count == 0)
                            {
                                minn          = dis;
                                optimize[rgb] = rgbb;
                            }
                            else
                            {
                                if (dis < minn)
                                {
                                    minn          = dis;
                                    optimize[rgb] = rgbb;
                                }
                            }
                        }
                    }
                    int rgb1 = optimize[rgb];

                    int r11 = (rgb1 >> 16) & 0xFF;
                    int g11 = (rgb1 >> 8) & 0xFF;
                    int b11 = rgb1 & 0xFF;
                    //mst_edges.Item2.Clear();
                    ImageMatrix[i, j].red   = (byte)r11;
                    ImageMatrix[i, j].green = (byte)g11;
                    ImageMatrix[i, j].blue  = (byte)b11;
                }
            }

            ImageOperations.DisplayImage(ImageMatrix, pictureBox2);

            stopwatch.Stop();

            // Write result.
            textBox2.Text = stopwatch.Elapsed.ToString();
            stopwatch.Reset();
            my_distinct.Clear();
            mst_edges.Item2.Clear();
        }