예제 #1
0
 private void ContrastStretchMethod()
 {
     sw.Restart();
     this.SourceImage = Operations.ContrastStretch((Bitmap)SourceImage.Clone(), 30, 225);
     sw.Stop();
     this.ElapsedTimeMessage = string.Format("A művelet időtartama: {0} ms.", sw.ElapsedMilliseconds);
 }
예제 #2
0
        private void MedianFilterMethod()
        {
            sw.Restart();
            this.SourceImage = Operations.MedianFilter((Bitmap)SourceImage.Clone());
            sw.Stop();

            this.ElapsedTimeMessage = string.Format("A művelet időtartama: {0} ms.", sw.ElapsedMilliseconds);
        }
예제 #3
0
        private void HistogramEqualizationMethod()
        {
            this.SourceImage = Operations.Grayscale((Bitmap)SourceImage.Clone());
            sw.Restart();
            this.SourceImage = Operations.HistogramEqualization((Bitmap)SourceImage.Clone());
            sw.Stop();

            this.ElapsedTimeMessage = string.Format("A művelet időtartama: {0} ms.", sw.ElapsedMilliseconds);
        }
예제 #4
0
        private void SobelEdgeDetectorMethod()
        {
            this.SourceImage = Operations.Grayscale((Bitmap)SourceImage.Clone());
            sw.Restart();
            this.SourceImage = Operations.SobelEdgeDetector((Bitmap)SourceImage.Clone());
            sw.Stop();

            this.ElapsedTimeMessage = string.Format("A művelet időtartama: {0} ms.", sw.ElapsedMilliseconds);
        }
예제 #5
0
 private void CreateCroppedImage()
 {
     CroppedImage = new Image <Rgba32>(CropArea.Width, CropArea.Height);
     CroppedImage = SourceImage.Clone(
         ctx => ctx.Resize(CropArea.Width, CropArea.Height, new SixLabors.ImageSharp.Processing.Processors.Transforms.BicubicResampler(), CropArea, new Rectangle(0, 0, CroppedImage.Width, CroppedImage.Height), true));
     if (CroppedImageRotationDegrees > 0.0)
     {
         CroppedImage.Mutate(i => i.Rotate(CroppedImageRotationDegrees));
     }
 }
예제 #6
0
        private void HarrisMethod()
        {
            this.SourceImage = Operations.Grayscale((Bitmap)SourceImage.Clone());
            sw.Restart();
            this.SourceImage = Operations.HarrisCornerDetector((Bitmap)SourceImage.Clone());
            //this.SourceImage = Operations.Treshold((Bitmap)SourceImage.Clone(),135);
            sw.Stop();

            this.ElapsedTimeMessage = string.Format("A művelet időtartama: {0} ms.", sw.ElapsedMilliseconds);
        }
예제 #7
0
        private void ApplyTransform(Func <byte, byte> pointTransformFunc)
        {
            byte[,] result = (byte[, ])SourceImage.Clone();
            Func <byte, byte> transformFunc = x => FixRange(pointTransformFunc(x));
            int width = result.GetLength(0), height = result.GetLength(1);

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    result[x, y] = transformFunc(result[x, y]);
                }
            }

            ShowTransformed(result);
        }
예제 #8
0
        private void GlobalTransform(Func <byte[, ], byte> thresholdFunc)
        {
            byte[,] result = (byte[, ])SourceImage.Clone();
            int width = result.GetLength(0), height = result.GetLength(1);

            byte t = thresholdFunc(result);

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    result[x, y] = (byte)(result[x, y] <= t ? 0 : 255);
                }
            }

            ShowTransformed(result);
        }
예제 #9
0
        public void AdoptiveTransform()
        {
            int k         = 1; // TODO params
            int blockSize = 2 * k + 1;

            alpha = float.Parse(paramsTextBox.Text);

            byte[,] result = (byte[, ])SourceImage.Clone();
            int width = result.GetLength(0), height = result.GetLength(1);

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    int  currentK;
                    byte t = countT(result, x, y, k, out currentK);

                    result[x, y] = (byte)(adoptiveCheckCriteria(result, x, y, k, t) ? 0 : 255);
                }
            }

            ShowTransformed(result);
        }
예제 #10
0
        public override ExecutionResult Run(IStepExecutionContext context)
        {
            var overlayOptions = _options.Overlay;

            if (!overlayOptions.ApplyOverlay)
            {
                return(ExecutionResult.Next());
            }
            Guard.Against.Null(SourceImage, nameof(SourceImage));
            var clut = _clutService.GetClut();

            var equalisedSource = SourceImage.Clone();

            equalisedSource.AdjustLevels(_options.AdaptiveLevelAdjustment);

            OverlayImage = new Image <Rgba32>(equalisedSource.Width, equalisedSource.Height);

            var operation = new ApplyClutRowOperation(equalisedSource, OverlayImage, clut);

            ParallelRowIterator.IterateRows(Configuration.Default, SourceImage.Bounds(), in operation);

            return(ExecutionResult.Next());
        }
예제 #11
0
        private void CreateHistogramMethod()
        {
            int[,] histogramRGB = Operations.CreateHistogramRGB((Bitmap)SourceImage.Clone());
            int[] histogramGS = Operations.CreateHistogramGray(Operations.Grayscale((Bitmap)SourceImage.Clone()));

            float maxBlue  = 0;
            float maxRed   = 0;
            float maxGreen = 0;
            float maxGrey  = 0;

            for (int i = 0; i < 256; i++)
            {
                if (histogramRGB[0, i] > maxBlue)
                {
                    maxBlue = histogramRGB[0, i];
                }
                if (histogramRGB[1, i] > maxGreen)
                {
                    maxGreen = histogramRGB[1, i];
                }
                if (histogramRGB[2, i] > maxRed)
                {
                    maxRed = histogramRGB[2, i];
                }
                if (histogramGS[i] > maxGrey)
                {
                    maxGrey = histogramGS[i];
                }
            }

            int imageHeight = 150;

            Bitmap imgGrey  = new Bitmap(512, imageHeight + 10);
            Bitmap imgBlue  = new Bitmap(512, imageHeight + 10);
            Bitmap imgGreen = new Bitmap(512, imageHeight + 10);
            Bitmap imgRed   = new Bitmap(512, imageHeight + 10);

            using (Graphics gr = Graphics.FromImage(imgGrey))
            {
                gr.Clear(Color.White);
                for (int i = 0; i < 256; i++)
                {
                    float percentage = histogramGS[i] / maxGrey;
                    gr.DrawLine(Pens.Gray, new System.Drawing.Point(2 * i, imgGrey.Height - 10), new System.Drawing.Point(2 * i, imgGrey.Height - 10 - (int)(percentage * imageHeight)));
                    gr.DrawLine(Pens.Gray, new System.Drawing.Point(2 * i + 1, imgGrey.Height - 10), new System.Drawing.Point(2 * i + 1, imgGrey.Height - 10 - (int)(percentage * imageHeight)));
                }
            }

            using (Graphics gr = Graphics.FromImage(imgBlue))
            {
                gr.Clear(Color.White);
                for (int i = 0; i < 256; i++)
                {
                    float percentage = histogramRGB[0, i] / maxBlue;
                    gr.DrawLine(Pens.Blue, new System.Drawing.Point(2 * i, imgBlue.Height - 10), new System.Drawing.Point(2 * i, imgBlue.Height - 10 - (int)(percentage * imageHeight)));
                    gr.DrawLine(Pens.Blue, new System.Drawing.Point(2 * i + 1, imgBlue.Height - 10), new System.Drawing.Point(2 * i + 1, imgBlue.Height - 10 - (int)(percentage * imageHeight)));
                }
            }

            using (Graphics gr = Graphics.FromImage(imgGreen))
            {
                gr.Clear(Color.White);
                for (int i = 0; i < 256; i++)
                {
                    float percentage = histogramRGB[1, i] / maxGreen;
                    gr.DrawLine(Pens.Green, new System.Drawing.Point(i * 2, imgGreen.Height - 10), new System.Drawing.Point(i * 2, imgGreen.Height - 10 - (int)(percentage * imageHeight)));
                    gr.DrawLine(Pens.Green, new System.Drawing.Point(2 * i + 1, imgGreen.Height - 10), new System.Drawing.Point(2 * i + 1, imgGreen.Height - 10 - (int)(percentage * imageHeight)));
                }
            }

            using (Graphics gr = Graphics.FromImage(imgRed))
            {
                gr.Clear(Color.White);
                for (int i = 0; i < 256; i++)
                {
                    float percentage = histogramRGB[2, i] / maxRed;
                    gr.DrawLine(Pens.Red, new System.Drawing.Point(2 * i, imgRed.Height - 10), new System.Drawing.Point(2 * i, imgRed.Height - 10 - (int)(percentage * imageHeight)));
                    gr.DrawLine(Pens.Red, new System.Drawing.Point(2 * i + 1, imgRed.Height - 10), new System.Drawing.Point(2 * i + 1, imgRed.Height - 10 - (int)(percentage * imageHeight)));
                }
            }

            imgGrey.Save(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "/Histogram/Grey.jpg");
            imgBlue.Save(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "/Histogram/Blue.jpg");
            imgGreen.Save(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "/Histogram/Green.jpg");
            imgRed.Save(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "/Histogram/Red.jpg");

            new Histogram(imgGrey, imgBlue, imgGreen, imgRed).ShowDialog();
        }
예제 #12
0
 protected virtual CodedImage CreateVisualImage()
 {
     return(SourceImage.Clone(false));
 }
예제 #13
0
        protected override void DoProcess()
        {
            mUpdatePending = false;
            if (SourceImage != null)
            {
                try
                {
                    SetUIState(UIState.Processing);

                    CancelProcessingPending = false;

                    if (mProcessImageDuringUpdate)
                    {
                        // Checking if the stage is frozen or not and is there a frozen image.
                        if (FrozenAt == null || mFrozenImage == null)
                        {
                            CurrentImage = (IBitmapCore)SourceImage.Clone();

                            if (mZoomAfterPrescaleValue < 0.999 || mZoomAfterPrescaleValue > 1.001)
                            {
                                CurrentImage.ScaleFast(mZoomAfterPrescaleValue, delegate(double progress) {
                                    OnProgressMessageReport(true, progress, "Applying zoom (downscaling)...", false);
                                    return(!CancelProcessingPending);
                                });
                            }
                            if (ImageChanged != null)
                            {
                                ImageChanged(this, EventArgs.Empty);
                            }
                        }
                        else
                        {
                            CurrentImage = (IBitmapCore)mFrozenImage.Clone();
                            if (ImageChanged != null)
                            {
                                ImageChanged(this, EventArgs.Empty);
                            }
                        }

                        // Making the list of stage operations to apply
                        List <StageOperation> operationsToApply = new List <StageOperation>();
                        List <double>         efforts           = new List <double>();
                        double full_efforts = 0;

                        int start_index = 0;
                        if (FrozenAt != null && mFrozenImage != null)
                        {
                            start_index = StageQueue.IndexOf(FrozenAt) + 1;
                        }

                        for (int i = start_index; i < StageQueue.Count; i++)
                        {
                            if (StageQueue[i] != _EditingOperation)
                            {
                                // Don't add inactives
                                if (StageQueue[i].Active == false)
                                {
                                    continue;
                                }

                                StageOperation newOperation = CallStageOperationFactory(StageQueue[i]);
                                operationsToApply.Add(newOperation);
                                efforts.Add(newOperation.CalculateEfforts(CurrentImage));
                                full_efforts += efforts[efforts.Count - 1];

                                newOperation.ReportProgress += delegate(object sender, ReportStageOperationProgressEventArgs e) {
                                    double cur_eff = 0;
                                    int    j       = 0;
                                    while (operationsToApply[j] != (StageOperation)sender)
                                    {
                                        cur_eff += efforts[j];
                                        j++;
                                    }
                                    cur_eff += e.Progress * efforts[j];
                                    string desc = StageOperationDescriptionAttribute.GetName(sender.GetType());

                                    OnProgressMessageReport(true,
                                                            cur_eff / full_efforts,
                                                            "" + (j + 1) + " of " + efforts.Count + ": " + desc + "...", true);

                                    if (CancelProcessingPending)
                                    {
                                        e.Cancel = true;
                                    }
                                };
                            }
                            else
                            {
                                break;
                            }
                        }

                        // Executing
                        for (int k = 0; k < operationsToApply.Count; k++)
                        {
                            Console.WriteLine("AnalyzeImage Calling for " + operationsToApply[k].GetType().Name);
                            _Holders[operationsToApply[k].Parameters].StageOperationParametersEditor.AnalyzeImage(CurrentImage);
                            operationsToApply[k].OnDo(CurrentImage);
                            if (operationsToApply[k].Parameters == FrozenAt)
                            {
                                // After the frozen line is reached,
                                // setting the current frozen image
                                mFrozenImage = (IBitmapCore)CurrentImage.Clone();
                            }
                        }
                    }

                    if (_EditingOperation != null)
                    {
                        Console.WriteLine("AnalyzeImage Calling for " + _EditingOperation.GetType().Name);
                        _Holders[_EditingOperation].StageOperationParametersEditor.AnalyzeImage(CurrentImage);
                    }

                    OnImageUpdatingCompleted();
                    SetUIState(UIState.Idle);
                }
                catch (UserCancelException)
                {
                    // The user cancelled processing.
                    // Setting to idle state
                    SetUIState(UIState.Idle);
                    // Unset cancelling flag.
                    AskUpdate();
                }
            }
        }