Example #1
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.DefaultExt = "*.jpg";
            if (ofd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
            {
                if (File.Exists(ofd.FileName))
                {
                    Bitmap oldImage = image;
                    using (Image input = Image.FromFile(ofd.FileName))
                    {
                        image = new Bitmap(input.Width, input.Height, PixelFormat.Format32bppArgb);
                        image.SetResolution(input.HorizontalResolution, input.VerticalResolution);
                        using (Graphics g = Graphics.FromImage(image))
                        {
                            g.PageUnit = GraphicsUnit.Pixel;
                            g.DrawImage(input, 0, 0);
                        }
                    }

                    lock (displayImageLock)
                    {
                        displayImage = new RawBitmapData(image);
                    }

                    if (oldImage != null)
                    {
                        oldImage.Dispose();
                    }
                }
            }
        }
Example #2
0
        private void tsbRun_Click(object sender, EventArgs e)
        {
            numberOfTasks = 1;
            waitHandle = new ManualResetEvent(false);

            RawBitmapData sourceData = new RawBitmapData(image);

            for (float t11 = 0.98f; t11 < 1.02f; t11 += 0.01f)
            {
                for (float t22 = 0.98f; t22 < 1.02f; t22 += 0.01f)
                {
                    for (float t33 = 0.98f; t33 < 1.02f; t33 += 0.01f)
                    {
                        for (float t12 = -0.02f; t12 < 0.02f; t12 += 0.01f)
                        {
                            for (float t13 = -0.02f; t13 < 0.02f; t13 += 0.01f)
                            {
                                for (float t21 = -0.02f; t21 < 0.02f; t21 += 0.01f)
                                {
                                    for (float t23 = -0.02f; t23 < 0.02f; t23 += 0.01f)
                                    {
                                        for (float t31 = -0.02f; t31 < 0.02f; t31 += 0.01f)
                                        {
                                            for (float t32 = -0.02f; t32 < 0.02f; t32 += 0.01f)
                                            {
                        //float t12 = (1f - t11) / 4;
                        //float t13 = (1f - t11) / 4;
                        //float t21 = (1f - t22) / 4;
                        //float t23 = (1f - t22) / 4;
                        //float t31 = (1f - t33) / 4;
                        //float t32 = (1f - t33) / 4;
                                                DenseMatrix matrix = DenseMatrix.Create(3, 3, (row, col) => row == col ? 1 : 0);
                                                matrix[0, 0] = t11;
                                                matrix[0, 1] = t12;
                                                matrix[0, 2] = t13;
                                                matrix[1, 0] = t21;
                                                matrix[1, 1] = t22;
                                                matrix[1, 2] = t23;
                                                matrix[2, 0] = t31;
                                                matrix[2, 1] = t32;
                                                matrix[2, 2] = t33;

                                                Tuple<RawBitmapData, DenseMatrix> stateTuple = new Tuple<RawBitmapData, DenseMatrix>(sourceData, matrix);

                                                ExecuteAsync(new WaitCallback(RunTransformation), stateTuple);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Example #3
0
        public void RunTransformation(object state)
        {
            Tuple<RawBitmapData, DenseMatrix> stateTuple = (Tuple<RawBitmapData, DenseMatrix>)state;
            RawBitmapData sourceData = stateTuple.Item1;
            DenseMatrix matrix = stateTuple.Item2;

            RawBitmapData output = new RawBitmapData(sourceData.Width, sourceData.Height);

            for (int x = 0; x < sourceData.Width; x++)
            {
                for (int y = 0; y < sourceData.Height; y++)
                {
                    int rawargbValue = sourceData.GetRawARGBValue(x, y);
                    DenseVector vector = new DenseVector(new float[] { rawargbValue >> 16 & 0xFF, rawargbValue >> 8 & 0xFF, rawargbValue & 0xFF });
                    DenseVector converted = matrix * vector;
                    rawargbValue = 0xFF << 24 | converted[0].ToTrimmedByte() << 16 | converted[1].ToTrimmedByte() << 8 | converted[2].ToTrimmedByte();
                    output.SetRawARGBValue(x, y, rawargbValue);
                }
            }

            //Bitmap transformed = output.GetBitmap();

            //lock (tempImagesLock)
            //{
            //    tempImages.Add(transformed);
            //}
            lock (displayImageLock)
            {
                displayImage = output;
                //Invoke((MethodInvoker)delegate
                //{
                //    pictureBox.Image = transformed;
                //});
            }
        }