Exemple #1
0
        public Image <Bgr, byte> CleanSmudges()
        {
            ProgressManager.AddSteps(9);

            SetColorProportions();
            ProgressManager.DoStep();
            Image <Bgr, byte> cleanedImage = _image.Copy();

            using (Image <Gray, byte> grayImage = _image.Convert <Gray, byte>().Copy())
            {
                #region BritherRegions
                using (Image <Gray, byte> bwGeneralMask = MorphologicalProcessing.GeneralBluredBinaryImage(_image))
                {
                    ProgressManager.DoStep();
                    #region Blue
                    RepairColor(ref cleanedImage, grayImage, bwGeneralMask, BgrColor.Blue, BlueTone, CmpType.GreaterThan);
                    ProgressManager.DoStep();
                    #endregion Blue

                    #region Green
                    RepairColor(ref cleanedImage, grayImage, bwGeneralMask, BgrColor.Green, GreenTone, CmpType.GreaterThan);
                    ProgressManager.DoStep();
                    #endregion Green

                    #region Red
                    RepairColor(ref cleanedImage, grayImage, bwGeneralMask, BgrColor.Red, RedTone, CmpType.GreaterThan);
                    ProgressManager.DoStep();
                    #endregion Red

                    using (Image <Gray, byte> bwGeneralMaskNegativ = MorphologicalProcessing.GenerateBinaryImageNegative(bwGeneralMask))
                    {
                        ProgressManager.DoStep();
                        #region Blue
                        RepairColor(ref cleanedImage, grayImage, bwGeneralMaskNegativ, BgrColor.Blue, BlueTone, CmpType.LessThan);
                        ProgressManager.DoStep();
                        #endregion Blue

                        #region Green
                        RepairColor(ref cleanedImage, grayImage, bwGeneralMaskNegativ, BgrColor.Green, GreenTone, CmpType.LessThan);
                        ProgressManager.DoStep();
                        #endregion Green

                        #region Red
                        RepairColor(ref cleanedImage, grayImage, bwGeneralMaskNegativ, BgrColor.Red, RedTone, CmpType.LessThan);
                        ProgressManager.DoStep();
                        #endregion Red
                    }
                }
                #endregion BritherRegions
            }

            //cleanedImage = AligneColor(cleanedImage);
            //CvInvoke.MedianBlur(cleanedImage.Image, cleanedImage.Image, 3);

            return(cleanedImage);
        }
Exemple #2
0
        private void RepairColor(ref Image <Bgr, byte> cleanedImage, Image <Gray, byte> grayImage, Image <Gray, byte> generalImageMask, BgrColor bgrColor, double colorTone, CmpType cmpType)
        {
            using (Image <Gray, byte> defectsMask = CreateMaskOfOverInappropriateColorProportions(grayImage, cleanedImage /*_image*/, colorTone, bgrColor, cmpType, _margin))
            {
                using (Image <Gray, byte> repairMask = generalImageMask.Mul(defectsMask))
                {
                    Image <Bgr, byte> cleanedPatchImage = cleanedImage.CopyBlank();
                    cleanedPatchImage[0] = cleanedImage[(int)bgrColor].Mul(BlueTone * 3);
                    cleanedPatchImage[1] = cleanedImage[(int)bgrColor].Mul(GreenTone * 3);
                    cleanedPatchImage[2] = cleanedImage[(int)bgrColor].Mul(RedTone * 3);

                    cleanedImage = MorphologicalProcessing.CombineTwoImages(cleanedImage, cleanedPatchImage, repairMask);
                }
            }
        }
 private Image <Gray, byte> GetMaskOfDefects(int a1, int a2, int b1, int b2, Image <Gray, float> sourceImage)
 {
     ProgressManager.AddSteps(3);
     using (Image <Gray, byte> cannyImg1 = sourceImage.Convert <Gray, byte>().Canny(a1, a2))
     {
         ProgressManager.DoStep();
         using (Image <Gray, byte> cannyImg2 = sourceImage.Convert <Gray, byte>().Canny(b1, b2))
         {
             ProgressManager.DoStep();
             using (Image <Gray, byte> cannyImg = cannyImg1.Add(cannyImg2))
             {
                 ProgressManager.DoStep();
                 return(MorphologicalProcessing.Dilate(cannyImg, new Size(3, 3), 3));
             }
         }
     }
 }