//write to file for some methods public static void WriteImageToFile(int[,] r, int[,] g, int[,] b, string outName, OutType type) { string ImgExtension = Path.GetExtension(outName).ToLower(); if (r.Length != g.Length || r.Length != b.Length) { Console.WriteLine("Image plane arrays size dismatch in operation -> WriteImageToFile(int[,] R, int[,] G, int[,] B, string fileName, OutType type) <-"); } else { Bitmap image = new Bitmap(r.GetLength(1), g.GetLength(0), PixelFormat.Format24bppRgb); image = Helpers.SetPixels(image, r, g, b); if (type == OutType.OneBpp) { image = PixelFormatWorks.ImageTo1BppBitmap(image, 0.5); } else if (type == OutType.EightBpp) { image = PixelFormatWorks.Bpp24Gray2Gray8bppBitMap(image); } Helpers.SaveOptions(image, outName, ImgExtension); } }
//create CheckerBoard and return as bitmap object public static Bitmap CheckerBoardBitmap(int n, int rows, int cols, OutType type) { int[,] result = new int[n * rows, n *cols]; Bitmap image = new Bitmap(result.GetLength(1), result.GetLength(0), PixelFormat.Format24bppRgb); if (rows > 0 && cols > 0) { result = CheckerBoardHelper(n, rows, cols); image = Helpers.SetPixels(image, result, result, result); if (type == OutType.OneBpp) { image = PixelFormatWorks.ImageTo1BppBitmap(image); } else if (type == OutType.EightBpp) { image = PixelFormatWorks.Bpp24Gray2Gray8bppBitMap(image); } } else { Console.WriteLine("r and c must be positive values greater than 1. Method: CheckerBoard"); } return(image); }
private static void ShapkaProcess(Bitmap img, double[,] tform, int r, int c, string fileName, bool ext) { string ImgExtension = GetImageInfo.Imginfo(Imageinfo.Extension); string imgName = GetImageInfo.Imginfo(Imageinfo.FileName); string defPath = GetImageInfo.MyPath("Affine"); Bitmap image = new Bitmap(c, r, PixelFormat.Format24bppRgb); double Depth = System.Drawing.Image.GetPixelFormatSize(img.PixelFormat); List <ArraysListInt> ColorList = Helpers.GetPixels(img); int[,] resultR = new int[r, c]; int[,] resultG = new int[r, c]; int[,] resultB = new int[r, c]; if (Depth == 1 || Depth == 8) { if (ext) { resultR = ExtenstionCount(ColorList[0].Color, tform, r, c); } else { resultR = AffineCount(ColorList[0].Color, tform, r, c); } resultG = resultR; resultB = resultR; } else { if (ext) { resultR = ExtenstionCount(ColorList[0].Color, tform, r, c); resultG = ExtenstionCount(ColorList[1].Color, tform, r, c); resultB = ExtenstionCount(ColorList[2].Color, tform, r, c); } else { resultR = AffineCount(ColorList[0].Color, tform, r, c); resultG = AffineCount(ColorList[1].Color, tform, r, c); resultB = AffineCount(ColorList[2].Color, tform, r, c); } } image = Helpers.SetPixels(image, resultR, resultG, resultB); if (Depth == 8) { image = PixelFormatWorks.Bpp24Gray2Gray8bppBitMap(image); } if (Depth == 1) { image = PixelFormatWorks.ImageTo1BppBitmap(image, 0.5); } string outName = defPath + imgName + fileName + ImgExtension; Helpers.SaveOptions(image, outName, ImgExtension); }
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); }
private static Bitmap HitMissBitmapHelper(Bitmap img, int[,] FirstStructureElement, int[,] SecondStructureElement) { Bitmap image = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb); int[,] count = BWHitMissProcess(img, FirstStructureElement, SecondStructureElement); double Depth = System.Drawing.Image.GetPixelFormatSize(img.PixelFormat); image = Helpers.SetPixels(image, count, count, count); if (Depth == 8) { image = PixelFormatWorks.Bpp24Gray2Gray8bppBitMap(image); } if (Depth == 1) { image = PixelFormatWorks.ImageTo1BppBitmap(image, 0.5); } return(image); }
//return result as 1/8/24 bitmap public static Bitmap BwmorphBitmap(Bitmap img, BwmorphOpearion operation, int repeat, BwmorphOut type) { var result = BwmorphHelper(img, operation, repeat); Bitmap image = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb); image = Helpers.SetPixels(image, result, result, result); if (type == BwmorphOut.OneBpp) { image = PixelFormatWorks.ImageTo1BppBitmap(image, 0.5); } else if (type == BwmorphOut.EightBpp) { image = PixelFormatWorks.Bpp24Gray2Gray8bppBitMap(image); } return(image); }
private static Bitmap InverseBinaryHelper(Bitmap img, OutType type) { Bitmap image = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb); int[,] result = new int[img.Height, img.Width]; if (Checks.BWinput(img)) { List <ArraysListInt> ColorList = Helpers.GetPixels(img); result = MoreHelpers.InvertBinaryArray(ColorList[0].Color); if (result.Cast <int>().Max() == 1) { for (int i = 0; i < result.GetLength(0); i++) { for (int j = 0; j < result.GetLength(1); j++) { if (result[i, j] == 1) { result[i, j] = 255; } } } } image = Helpers.SetPixels(image, result, result, result); if (type == OutType.OneBpp) { image = PixelFormatWorks.ImageTo1BppBitmap(image, 0.5); } else if (type == OutType.EightBpp) { image = PixelFormatWorks.Bpp24Gray2Gray8bppBitMap(image); } } return(image); }
private static Bitmap MirrorHelper(Bitmap img, MirrorOption side) { Bitmap image = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb); double Depth = System.Drawing.Image.GetPixelFormatSize(img.PixelFormat); List <ArraysListInt> ColorList = Helpers.GetPixels(img); int[,] resultR = new int[img.Height, img.Width]; int[,] resultG = new int[img.Height, img.Width]; int[,] resultB = new int[img.Height, img.Width]; PadMyArray <int> padArr = new PadMyArray <int>(); if (side == MirrorOption.left || side == MirrorOption.right) { resultR = padArr.PadArray(ColorList[0].Color, 0, img.Width, PadType.symmetric, Direction.pre); resultG = padArr.PadArray(ColorList[1].Color, 0, img.Width, PadType.symmetric, Direction.pre); resultB = padArr.PadArray(ColorList[2].Color, 0, img.Width, PadType.symmetric, Direction.pre); } else { resultR = padArr.PadArray(ColorList[0].Color, img.Height, 0, PadType.symmetric, Direction.pre); resultG = padArr.PadArray(ColorList[1].Color, img.Height, 0, PadType.symmetric, Direction.pre); resultB = padArr.PadArray(ColorList[2].Color, img.Height, 0, PadType.symmetric, Direction.pre); } image = Helpers.SetPixels(image, resultR, resultG, resultB); if (Depth == 8) { image = PixelFormatWorks.Bpp24Gray2Gray8bppBitMap(image); } else if (Depth == 1) { image = PixelFormatWorks.ImageTo1BppBitmap(image); } return(image); }
private static Bitmap MakeNegativeAndBackHelper(Bitmap img) { Bitmap image = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb); double Depth = System.Drawing.Image.GetPixelFormatSize(img.PixelFormat); List <ArraysListInt> ColorList = Helpers.GetPixels(img); var Rcn = ColorList[0].Color.ConstSubArrayElements(255); //R plane var Gcn = ColorList[1].Color.ConstSubArrayElements(255); //G plane var Bcn = ColorList[2].Color.ConstSubArrayElements(255); //B plane image = Helpers.SetPixels(image, Rcn, Gcn, Bcn); if (Depth == 8) { image = PixelFormatWorks.Bpp24Gray2Gray8bppBitMap(image); } else if (Depth == 1) { image = PixelFormatWorks.ImageTo1BppBitmap(image); } return(image); }
private static Bitmap SaltPepperFilterProcess(Bitmap img, int m, int n, double filterOrder, SaltPepperfilterType spfiltType, bool unsharp) { Bitmap image = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb); List <ArraysListInt> ColorList = Helpers.GetPixels(img); var Rc = ColorList[0].Color; var Gc = ColorList[1].Color; var Bc = ColorList[2].Color; double[,] filter; int[,] resultR = new int[img.Height, img.Width]; int[,] resultG = new int[img.Height, img.Width]; int[,] resultB = new int[img.Height, img.Width]; ArrGen <double> arrGen = new ArrGen <double>(); double Depth = System.Drawing.Image.GetPixelFormatSize(img.PixelFormat); if (m >= 1 && n >= 1) { switch (spfiltType) { //Arithmetic mean filtering. //help with salt noize case SaltPepperfilterType.amean: filter = ImageFilter.FspecialSize(m, n, "average"); resultR = (ImageFilter.Filter_double(Rc, filter)).ArrayToUint8(); resultG = (ImageFilter.Filter_double(Gc, filter)).ArrayToUint8(); resultB = (ImageFilter.Filter_double(Bc, filter)).ArrayToUint8(); break; //Geometric mean filtering. //help with salt noize case SaltPepperfilterType.gmean: filter = arrGen.ArrOfSingle(m, n, 1); resultR = GmeanCount(Rc, filter, m, n); resultG = GmeanCount(Gc, filter, m, n); resultB = GmeanCount(Bc, filter, m, n); break; //harmonic mean filter //help with salt noize case SaltPepperfilterType.hmean: filter = arrGen.ArrOfSingle(m, n, 1); resultR = HmeanCount(Rc, filter, m, n); resultG = HmeanCount(Gc, filter, m, n); resultB = HmeanCount(Bc, filter, m, n); break; //contraharmonic mean filter Q>0 for pepper & <0 for salt case SaltPepperfilterType.chmean: filter = arrGen.ArrOfSingle(m, n, 1); resultR = CharmeanCount(Rc, filter, filterOrder); resultG = CharmeanCount(Gc, filter, filterOrder); resultB = CharmeanCount(Bc, filter, filterOrder); break; default: resultR = Rc; resultG = Gc; resultB = Bc; break; } image = Helpers.SetPixels(image, resultR, resultG, resultB); if (unsharp) //spfiltType == SaltPepperfilterType.chmean & unsharp { image = Helpers.FastSharpImage(image); } if (Depth == 8) { image = PixelFormatWorks.Bpp24Gray2Gray8bppBitMap(image); } if (Depth == 1) { image = PixelFormatWorks.ImageTo1BppBitmap(image, 0.5); } } else { Console.WriteLine("m and n parameters must be positive geater or equal 1. Recommended 2 & 2 and higher. Method >SaltandPapperFilter<"); } return(image); }
private static void SaltandPepperShapkaProcess(Bitmap img, double densitySalt, double densityPepper, SaltandPapperNoise noiseType) { string imgExtension = GetImageInfo.Imginfo(Imageinfo.Extension); string imgName = GetImageInfo.Imginfo(Imageinfo.FileName); string defPath = GetImageInfo.MyPath("Noise"); Bitmap image = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb); double Depth = System.Drawing.Image.GetPixelFormatSize(img.PixelFormat); string outName = string.Empty; List <ArraysListInt> ColorList = Helpers.GetPixels(img); int[,] resultR = new int[img.Height, img.Width]; int[,] resultG = new int[img.Height, img.Width]; int[,] resultB = new int[img.Height, img.Width]; if (densitySalt > 0 && densitySalt <= 1 && densityPepper > 0 && densityPepper <= 1) { int white = 1; double[,] noise = Helpers.RandArray(img.Height, img.Width); if (Depth != 1 && Depth != 8) { white = 255; resultR = SaltandPepper(ColorList[0].Color, noise, densitySalt, densityPepper, white, noiseType); resultG = SaltandPepper(ColorList[1].Color, noise, densitySalt, densityPepper, white, noiseType); resultB = SaltandPepper(ColorList[2].Color, noise, densitySalt, densityPepper, white, noiseType); } else { resultR = SaltandPepper(ColorList[0].Color, noise, densitySalt, densityPepper, white, noiseType); 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); } } else { Console.WriteLine("Density must be in range [0..1]. Method NoiseTry.SaltandPepperNoise(). Return black rectangle."); } if (noiseType == SaltandPapperNoise.salt) { outName = defPath + imgName + "_SaltNoise_Density_" + densitySalt + imgExtension; } else if (noiseType == SaltandPapperNoise.pepper) { outName = defPath + imgName + "_PepperNoise_Density_" + densityPepper + imgExtension; } else { outName = defPath + imgName + "_SalptandPepperNoise_SaltDensity_" + densitySalt + "_PepperDensity_" + densityPepper + imgExtension; } Helpers.SaveOptions(image, outName, imgExtension); }