Пример #1
0
        private void SetSharpenC(object obj)
        {
            Bitmap bmp = null;

            try
            {
                bmp = (Bitmap)Images.Instance.CurrentBitmap.Clone();
            }
            catch { }
            Bitmap bmpselected = null;

            try
            {
                bmpselected = (Bitmap)Images.Instance.SelectedBitmap.Clone();
            }
            catch { }
            if (partarea == true && bmpselected != null)
            {
                sharpenFilter.ApplyInPlace(bmpselected);
                Graphics newImage = Graphics.FromImage(bmp);
                newImage.DrawImage(bmpselected, (int)SelectedPoints.selectPointForEfX, (int)SelectedPoints.selectPointForEfY, bmpselected.Width, bmpselected.Height);
            }
            else if (bmp != null)
            {
                sharpenFilter.ApplyInPlace(bmp);
            }
            Images.Instance.CurrentBitmap = bmp;
            Images.Instance.NotifyImages();
            this.Temporary = bmp;
        }
Пример #2
0
        public static Bitmap Sharpen(Bitmap bmp)
        {
            Sharpen filter = new Sharpen();

            filter.ApplyInPlace(bmp);
            return(bmp);
        }
Пример #3
0
        private Bitmap ProcessSingleImage(Bitmap _src)
        {
            Sharpen sharpenFilter = new Sharpen();

            sharpenFilter.ApplyInPlace(_src);

            return(_src);
        }
Пример #4
0
        public static void ApplyMatrix(Bitmap image, int[,] matrix, int threshold = 1)
        {
            Sharpen sharpenFilter = new Sharpen()
            {
                Kernel    = matrix,
                Threshold = threshold
            };

            sharpenFilter.ApplyInPlace(image);
        }
Пример #5
0
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            if (lastUsableFrame != null)
            {
                string minTemp = rawToTemp(gModeLeft);
                string maxTemp = rawToTemp(gModeRight);

                lblSliderMin.Text = minTemp;
                lblSliderMax.Text = maxTemp;
                lblMinTemp.Text   = minTemp;
                lblMaxTemp.Text   = maxTemp;

                lblLeft.Text  = gModeLeft.ToString();
                lblRight.Text = gModeRight.ToString();
                label2.Text   = maxTempRaw.ToString();

                if (autoRange)//set sliders position
                {
                    trackBar2.Value = gModeLeft;
                    trackBar1.Value = gModeRight;
                }

                bitmap_data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
                Marshal.Copy(imgBuffer, 0, bitmap_data.Scan0, imgBuffer.Length);
                bitmap.UnlockBits(bitmap_data);

                //crop image to 206x156
                croppedBitmap = cropFilter.Apply(bitmap);

                //upscale 200 %
                bigBitmap = bilinearResize.Apply(croppedBitmap);

                //sharpen image
                if (SharpenImage)
                {
                    sfilter.ApplyInPlace(bigBitmap);
                }

                pictureBox3.Image = bigBitmap;

                if (firstAfterCal)
                {
                    firstAfterCal     = false;
                    pictureBox5.Image = bigBitmap;
                    if (autoSaveImg)
                    {
                        bigBitmap.Save(localPath + @"\export\seek_" + DateTime.Now.ToString("yyyy-MM-dd_hh-mm-ss_fff") + ".png");
                    }
                }

                DrawHistogram();
            }
        }
Пример #6
0
        private Bitmap ProcessSingleImage(Bitmap _src)
        {
            Bitmap  img           = (_src.PixelFormat == PixelFormat.Format24bppRgb) ? _src : CloneTo24bpp(_src);
            Sharpen sharpenFilter = new Sharpen();

            sharpenFilter.ApplyInPlace(img);

            if (_src.PixelFormat != PixelFormat.Format24bppRgb)
            {
                Graphics g = Graphics.FromImage(_src);
                g.DrawImageUnscaled(img, 0, 0);
                img.Dispose();
            }

            return(_src);
        }
Пример #7
0
        void SharpenToolStripMenuItemClick(object sender, EventArgs e)
        {
            //jika gambar kosong/null maka akan mengembalikan nilai kosong/null
            if (gambar == null)
            {
                return;
            }
            //membuat filter dari inisiasi class Sharpen() pada objek sharpen
            Sharpen sharpen = new Sharpen( );

            //clone variable gambar pada variable gambar2
            gambar2 = (Bitmap)gambar.Clone();
            //aplikasikan filter objek sharpen pada gambar2
            sharpen.ApplyInPlace(gambar2);
            //tampilkan hasil gambar2 yang sudah diaplikasikan filter pada pictureBox2
            pictureBox2.Image = gambar2;
        }
Пример #8
0
        /// <summary>Handles the Click event of the Process button which crops the main image and applies the filter stack to generate the output image.</summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void cmdProcess_Click(object sender, EventArgs e)
        {
            if (!_placed)
            {
                return;
            }

            if (pcFullImage.Image == null)
            {
                return;
            }


            Bitmap   b = new Bitmap(pbSource.Width, pbSource.Height);
            Graphics g = Graphics.FromImage(b);

            g.Clear(Color.White);
            g.DrawImage(pcFullImage.Image, new Rectangle(0, 0, pbSource.Width, pbSource.Height), _selection.X, _selection.Y, _selection.Width, _selection.Height, GraphicsUnit.Pixel);
            g.Dispose();

            pbSource.Image = b;

            if (filterStack.Count != 0)
            {
                b = filterStack.Apply(b);
            }

            var sc = new SaturationCorrection();

            if (sc.FormatTranslations.ContainsKey(b.PixelFormat))
            {
                sc.AdjustValue = hsbSaturation.Value / 100.0f;
                // apply the filter
                sc.ApplyInPlace(b);
            }

            Bitmap greyb = null;

            if (AForge.Imaging.Filters.Grayscale.CommonAlgorithms.BT709.FormatTranslations.ContainsKey(b.PixelFormat))
            {
                greyb = AForge.Imaging.Filters.Grayscale.CommonAlgorithms.BT709.Apply(b);
            }
            else
            {
                this.Text = "Cannot convert to greyscale";
                greyb     = b;
            }

            var bc = new BrightnessCorrection();

            if (bc.FormatTranslations.ContainsKey(b.PixelFormat))
            {
                bc.AdjustValue = hsbBrightness.Value;
                bc.ApplyInPlace(greyb);
            }

            var cc = new ContrastCorrection();

            if (cc.FormatTranslations.ContainsKey(b.PixelFormat))
            {
                cc.Factor = hsbContrast.Value;
                cc.ApplyInPlace(greyb);
            }

            if (filterStack.Count == 0)
            {
                var sharpen = new Sharpen();
                if (sharpen.FormatTranslations.ContainsKey(b.PixelFormat))
                {
                    sharpen.ApplyInPlace(greyb);
                }
            }

            if (chkInvert.Checked)
            {
                var invert = new Invert();
                invert.ApplyInPlace(greyb);
            }

            pbInt.Image = greyb;

            b = greyb;

            //BaseInPlacePartialFilter filter = new AForge.Imaging.Filters.FloydSteinbergDithering();
            BaseInPlacePartialFilter filter = null;

            if (cmbAlgorithm.SelectedItem != null && cmbAlgorithm.SelectedItem is AForge.Imaging.Filters.BaseInPlacePartialFilter)
            {
                filter = cmbAlgorithm.SelectedItem as AForge.Imaging.Filters.BaseInPlacePartialFilter;
            }

            if (filter == null)
            {
                filter = new AForge.Imaging.Filters.SierraDithering();
            }

            if (filter.FormatTranslations.ContainsKey(b.PixelFormat))
            {
                var ditheredb = filter.Apply(b);
                pbDest.Image = ditheredb;
                this.Text    = "Badger!";
            }
            else
            {
                this.Text = "Cannot dither this image!";
            }
        }
Пример #9
0
        static void Main(string[] args)
        {
            Console.Title = "Basic OCR.exe";
            string filename, path, dir, language;

            //take full path from user
            Console.WriteLine("Enter path:");
            //Separating filename and directory
            path     = Console.ReadLine();
            dir      = Path.GetDirectoryName(path);
            filename = Path.GetFileNameWithoutExtension(path);
            //Enter language for Tesseract engine
            Console.WriteLine("Enter language(hin-Hindi,eng-English,ori-Oriya):");
            language = Console.ReadLine();
            //Create Bitmap object
            Bitmap img2 = Accord.Imaging.Image.FromFile(path);

            //Image is first converted to Grayscale as Thresholding doesn't support coloured images as input
            Grayscale gray   = new Grayscale(0.2125, 0.7154, 0.0721);
            Bitmap    result = gray.Apply(img2);

            // This blackens the whole area in shades:  Threshold thres = new Threshold(100);

            /*
             * Applying Bradley Thresholding which brightens up the area in shades hence a uniformly bright
             * image is obtained.
             */
            Console.WriteLine("Applying Bradley Local Thresholding...");
            BradleyLocalThresholding thres = new BradleyLocalThresholding();

            thres.WindowSize = 80;
            thres.PixelBrightnessDifferenceLimit = 0.1F;
            thres.ApplyInPlace(result);

            //Save the binarized image
            result.Save(dir + "\\" + filename + "_1thres.bmp");

            //Sharpening
            Console.WriteLine("Sharpening...");
            Sharpen sharp = new Sharpen();

            // apply the filter
            sharp.ApplyInPlace(result);
            //result.Save(dir + "\\" + filename + "_2sharp.bmp");

            //Bilateral Smoothing
            // create filter
            Console.WriteLine("Applying Bilateral smoothing...");
            BilateralSmoothing smooth = new BilateralSmoothing();

            smooth.KernelSize    = 7;
            smooth.SpatialFactor = 10;
            smooth.ColorFactor   = 60;
            smooth.ColorPower    = 0.5;
            // apply the filter
            smooth.ApplyInPlace(result);

            //Save cleaned image
            //result.Save(dir + "\\" + filename + "_3smooth.bmp");

            //Document skew, line detection
            DocumentSkewChecker skew = new DocumentSkewChecker();
            double angle             = skew.GetSkewAngle(result);

            Console.WriteLine("Skewing and rotating...");
            RotateBilinear rot = new RotateBilinear(-angle);

            rot.FillColor = Color.White;
            result        = rot.Apply(result);

            result.Save(dir + "\\" + filename + "_4rot.bmp");

            try
            {
                using (var engine = new TesseractEngine(@".\tessdata", language, EngineMode.Default))
                {
                    using (var img = result)
                    {
                        using (var page = engine.Process(img))
                        {
                            var text = page.GetText();
                            //Console.WriteLine("Text(get text): \r\n{0}", text);

                            StreamWriter sw;
                            string       Filename = dir + "\\" + filename + "_text.doc";
                            sw = File.CreateText(Filename);
                            Console.WriteLine("Generating file...");
                            string FileData = text;
                            sw.WriteLine(FileData);
                            sw.Close();

                            //We make a list of type Rectangle. It stores data of all the bounding boxes
                            List <Rectangle> boxes = page.GetSegmentedRegions(PageIteratorLevel.Symbol);


                            /*
                             * Graphics gives the following error in case of result/img:
                             * A Graphics object cannot be created from an image that has an indexed pixel format. ...
                             * ...System.Exception: A Graphics object cannot be created from an image that has an indexed pixel format.
                             *
                             * I am using the following solution for now:
                             */
                            Bitmap rez = new Bitmap(result);


                            using (Graphics g = Graphics.FromImage(rez))
                            {
                                Pen p = new Pen(Brushes.Red, 1.0F);
                                foreach (Rectangle r in boxes)
                                {
                                    //Console.WriteLine(r);
                                    g.DrawRectangle(p, r);
                                }

                                g.DrawImage(rez, 0, 0);
                            }

                            //Saving the image with bounding boxes
                            Console.WriteLine("Generating image with bounding boxes...");
                            rez.Save(dir + "\\" + filename + "_5seg.bmp");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Trace.TraceError(e.ToString());
                Console.WriteLine(e.Message);
                Console.WriteLine(e.ToString());
            }
            finally
            {
                Console.WriteLine("\n\nPress ENTER/RETURN to exit");
                Console.ReadKey(true);
            }
        }