Beispiel #1
0
        //call and process selected morph opeartion at image array(-s)
        private static int[,] MorphOperationHelper(int [,] arr, MorphOp operation, int[,] structureElement)
        {
            int[,] result = new int[arr.GetLength(0), arr.GetLength(1)];

            switch (operation)
            {
            case MorphOp.Dilate:
                result = Dilate.DilateMe(arr, structureElement);
                break;

            case MorphOp.Erode:
                result = Erode.ErodeMe(arr, structureElement);
                break;

            case MorphOp.imOpen:
                result = Dilate.DilateMe(Erode.ErodeMe(arr, structureElement), structureElement);
                break;

            case MorphOp.imClose:
                result = Erode.ErodeMe(Dilate.DilateMe(arr, structureElement), structureElement);
                break;
            }

            return(result);
        }
Beispiel #2
0
        //return array after morph operation
        public static int [,] MorphOperationArray(int[,] arr, MorphOp operation, int[,] structureElement)
        {
            int[,] result = new int[arr.GetLength(0), arr.GetLength(1)];
            result        = MorphOperationHelper(arr, operation, structureElement);

            return(result);
        }
Beispiel #3
0
        public void bwMorph(ref Mat inputImage, MorphOp operation, ElementShape mShape = ElementShape.Rectangle, int mSize = 3, int iterations = 1)
        {
            int _mSize = (mSize % 2 == 1) ? mSize : mSize + 1;

            Mat element = CvInvoke.GetStructuringElement(mShape, new Size(_mSize, _mSize), new Point(-1, -1));

            CvInvoke.MorphologyEx(inputImage, inputImage, operation, element, new Point(-1, -1), iterations, BorderType.Default, new MCvScalar(255, 0, 0, 255));
        }
Beispiel #4
0
        private static Bitmap MorphOperationProcess(Bitmap img, MorphOp operation, int[,] structureElement)
        {
            Bitmap image = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb);
            bool   type  = true;

            //array, where store color components result after operations
            int[,] resultR = new int[img.Height, img.Width];
            int[,] resultG = new int[img.Height, img.Width];
            int[,] resultB = new int[img.Height, img.Width];

            var ColorList = Helpers.GetPixels(img);

            double Depth = System.Drawing.Image.GetPixelFormatSize(img.PixelFormat);

            if (Depth == 8 || Depth == 1 || Checks.BlackandWhite24bppCheck(ColorList))
            {
                type = false;
            }

            if (type)
            {
                resultR = MorphOperationHelper(ColorList[0].Color, operation, structureElement);
                resultG = MorphOperationHelper(ColorList[1].Color, operation, structureElement);
                resultB = MorphOperationHelper(ColorList[2].Color, operation, structureElement);
            }
            else
            {
                resultR = MorphOperationHelper(ColorList[0].Color, operation, structureElement);
                resultG = resultR; resultB = resultR;
            }

            image = Helpers.SetPixels(image, resultR, resultG, resultB);

            if (Depth == 8)
            {
                image = PixelFormatWorks.Bpp24Gray2Gray8bppBitMap(image);
            }
            if (Depth == 1)
            {
                image = PixelFormatWorks.ImageTo1BppBitmap(image, 0.5);
            }

            return(image);
        }
Beispiel #5
0
        private static void MorphOperationShapkaProcess(Bitmap img, MorphOp operation, int[,] structureElement, string elementInf)
        {
            string imgExtension = GetImageInfo.Imginfo(Imageinfo.Extension);
            string imgName      = GetImageInfo.Imginfo(Imageinfo.FileName);
            string defPath      = GetImageInfo.MyPath("Morph");

            string outName = string.Empty;
            Bitmap image   = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb);

            image = MorphOperationProcess(img, operation, structureElement);

            if (string.IsNullOrEmpty(elementInf))
            {
                outName = defPath + imgName + "_" + operation.ToString() + imgExtension;
            }
            else
            {
                outName = defPath + imgName + "_" + operation.ToString() + elementInf + imgExtension;
            }
            Helpers.SaveOptions(image, outName, imgExtension);
        }
Beispiel #6
0
        private static void MorphOperationArray2FileShapka(int[,] arr, MorphOp operation, int[,] structureElement, string elementInf)
        {
            string defPath = GetImageInfo.MyPath("Morph");
            string outName = string.Empty;

            Bitmap image = new Bitmap(arr.GetLength(1), arr.GetLength(0), PixelFormat.Format24bppRgb);

            int[,] result = new int[arr.GetLength(0), arr.GetLength(1)];

            result = MorphOperationHelper(arr, operation, structureElement);
            image  = Helpers.SetPixels(image, result, result, result);

            if (string.IsNullOrEmpty(elementInf))
            {
                outName = defPath + "_Array2File_" + operation.ToString() + ".png";
            }
            else
            {
                outName = defPath + "_Array2File_" + operation.ToString() + elementInf + ".png";
            }

            image = PixelFormatWorks.Bpp24Gray2Gray8bppBitMap(image);
            Helpers.SaveOptions(image, outName, ".png");
        }
Beispiel #7
0
        public void bwMorph(ref Mat inputImage, ref Mat outputImage, MorphOp operation, ElementShape mShape = ElementShape.Rectangle, int mSize = 3, int iterations = 1)
        {
            inputImage.CopyTo(outputImage);

            bwMorph(ref outputImage, operation, mShape, mSize, iterations);
        }
Beispiel #8
0
        public void Morph(MorphOp op, Size size)
        {
            Mat hStruct = CvInvoke.GetStructuringElement(ElementShape.Rectangle, size, new Point());

            CvInvoke.MorphologyEx(this.Data, this.Data, op, hStruct, new Point(), 1, BorderType.Default, new MCvScalar());
        }
Beispiel #9
0
 //return bitmap after morph operation
 public static Bitmap MorphOperationBitmap(Bitmap img, MorphOp operation, int[,] structureElement)
 {
     return(MorphOperationProcess(img, operation, structureElement));
 }
Beispiel #10
0
 public static void MorphOperation(Bitmap img, MorphOp operation, int[,] structureElement, string elementInf)
 {
     MorphOperationShapkaProcess(img, operation, structureElement, elementInf);
 }
Beispiel #11
0
 public static void MorphOperationArray2File(int[,] arr, MorphOp operation, int[,] structureElement, string elementInf)
 {
     MorphOperationArray2FileShapka(arr, operation, structureElement, elementInf);
 }
 private void SecondMorphType_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
 {
     secondMorphOp = (MorphOp)SecondMorphType.SelectedValue;
 }