public static BitmapHandler CreateBitmap(this IMatrixImage matrixImage) { return(new BitmapHandler(matrixImage)); //MatrixLayer<byte>[] layers = matrixImage.Split(false).Select(a => a.ToByteLayer(false)).ToArray(); //Bitmap bitmap; //if (layers.Length == 1) //{ // // GrayScale // bitmap = new Bitmap(matrixImage.Width, matrixImage.Height, PixelFormat.Format8bppIndexed); // ColorPalette palette = bitmap.Palette; // Color[] ent = palette.Entries; // for (int i = 0; i < 256; i++) // { // ent[i] = Color.FromArgb(i, i, i); // Настроить для Bitmap только цвета с оттенками серого // } // bitmap.Palette = palette; // bitmap.FillGrayBitmap(matrixImage.Split(false)[0]); // return new BitmapHandler(bitmap, matrixImage, a => bitmap.FillGrayBitmap(a.Image.Split(false)[0])); //} //else if (layers.Length == 3) //{ // // RGB // bitmap = new Bitmap(matrixImage.Width, matrixImage.Height, PixelFormat.Format24bppRgb); // bitmap.FillBgrBitmap(matrixImage.Split(false)); // return new BitmapHandler(bitmap, matrixImage, a => bitmap.FillBgrBitmap(a.Image.Split(false))); //} //else if (layers.Length == 4) //{ // // RGBA // bitmap = new Bitmap(matrixImage.Width, matrixImage.Height, PixelFormat.Format32bppPArgb); // bitmap.FillBgraBitmap(matrixImage.Split(false)); // return new BitmapHandler(bitmap, matrixImage, a => bitmap.FillAbgrBitmap(a.Image.Split(false))); //} //throw new NotImplementedException(); }
public override IMatrixImage Invoke(IMatrixImage input) { var img = input.ConvertTo <byte>(); img.ForEachPixelsSet((s, x, y) => s.Select(a => (byte)(a + x - y)).ToArray()); return(img); }
public override IMatrixImage Invoke(IMatrixImage input) { if (Math.Round(X0Y0, 0) == X0Y0 && Math.Round(X1Y0, 0) == X1Y0 && Math.Round(X2Y0, 0) == X2Y0 && Math.Round(X0Y1, 0) == X0Y1 && Math.Round(X1Y1, 0) == X1Y1 && Math.Round(X2Y1, 0) == X2Y1 && Math.Round(X0Y2, 0) == X0Y2 && Math.Round(X1Y2, 0) == X1Y2 && Math.Round(X2Y2, 0) == X2Y2) { input.SlidingWindow(new MatrixOperation <int>(new int[, ] { { (int)X0Y0, (int)X1Y0, (int)X2Y0 }, { (int)X0Y1, (int)X1Y1, (int)X2Y1 }, { (int)X0Y2, (int)X1Y2, (int)X2Y2 }, }, (int?)MinLimit, (int?)MaxLimit)); } else { input.SlidingWindow(new MatrixOperation <double>(new double[, ] { { X0Y0, X1Y0, X2Y0 }, { X0Y1, X1Y1, X2Y1 }, { X0Y2, X1Y2, X2Y2 }, }, MinLimit, MaxLimit)); } return(input); }
public override IMatrixImage Invoke(IMatrixImage input) { var image = input.ToByteImage(true); Mat <byte> mat = image.GetCVMat(); image.SetCVMat(mat.MedianBlur(Kernel)); return(image); }
public override IMatrixImage Invoke(IMatrixImage input) { foreach (IMatrixLayer layer in input) { layer.Sub(255, false); } return(input); }
public override IMatrixImage Invoke(IMatrixImage input) { MatrixLayer <byte> layer = new MatrixLayer <byte>(255, 255); layer.ForEachPixelsSet((x, y) => (byte)(x * 16 - x % 16)); return(new MatrixImage <byte>(new MatrixLayer <byte>[] { layer }, false)); }
public override bool Change(ImageMethod method) { using Form form = new Form(); TableLayoutPanel tlp = new TableLayoutPanel { RowCount = 3, ColumnCount = 2, Dock = DockStyle.Fill, Parent = form }; tlp.RowStyles.Add(new RowStyle(SizeType.Percent, 100)); tlp.RowStyles.Add(new RowStyle(SizeType.Absolute, 30)); tlp.RowStyles.Add(new RowStyle(SizeType.Absolute, 30)); tlp.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50)); tlp.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50)); PropertyGrid pg = new PropertyGrid { Dock = DockStyle.Fill, SelectedObject = method }; tlp.Controls.Add(pg, 0, 0); tlp.SetColumnSpan(pg, 2); Button preview = new Button { Text = "Предпросмотр", Dock = DockStyle.Fill }; Button ok = new Button { Text = "OK", Dock = DockStyle.Fill, DialogResult = DialogResult.OK }; Button cancel = new Button { Text = "Отмена", Dock = DockStyle.Fill, DialogResult = DialogResult.Cancel }; tlp.Controls.Add(preview, 0, 1); tlp.SetColumnSpan(preview, 2); tlp.Controls.Add(ok, 0, 2); tlp.Controls.Add(cancel, 1, 2); preview.Click += (_, __) => { try { IMatrixImage image = method.Invoke((IMatrixImage)ImageLib.Controller.MainController.CurrentController.CurrentImage.Clone()); ImageLib.Controller.MainController.CurrentController.SetPreviewImage(image); } catch (System.Reflection.TargetInvocationException targetEx) { MessageBox.Show($"{targetEx.Message}{Environment.NewLine}{targetEx.InnerException.Message}", targetEx.InnerException.GetType().Name); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().Name); } }; return(form.ShowDialog() == DialogResult.OK); }
public override IMatrixImage Invoke(IMatrixImage input) { Map map = (Map)MainController.CurrentController.Storage["Map"]; map.Clear(); MatrixImage <byte> img = (MatrixImage <byte>)ImageLib.Controller.MainController.CurrentController.Storage["img"]; return(img.Clone()); }
public override IMatrixImage Invoke(IMatrixImage input) { MethodImpl.Preview.Contours.Implementations.Laplas(input); //var image = input.ToByteImage(true); //foreach (var layer in image.SplitWithoutAlpha()) // layer.SlidingWindow(3, 3, Func); return(input); }
public static void SetCVMat(this IMatrixImage image, Mat mat) { //var method = // typeof(ImageExtensions).GetMethod(nameof(SetCVMat), 1, new Type[] { typeof(MatrixImage<>) }) // .MakeGenericMethod(image.ElementType); var method = Info.OfMethod("OpenCVSupport", "OpenCVSupport.ImageExtensions", "SetCVMat", "MatrixImage`1,Mat"); method = method.MakeGenericMethod(image.ElementType); method.Invoke(null, new object[] { image, mat }); }
public static Mat GetCVMat(this IMatrixImage image, bool sync = true) { var method = Info.OfMethod("OpenCVSupport", "OpenCVSupport.ImageExtensions", "GetCVMat", "MatrixImage`1"); method = method.MakeGenericMethod(image.ElementType); //var method = // typeof(ImageExtensions).GetMethod(nameof(GetCVMat), 1, new Type[] { typeof(MatrixImage<>) }) // .MakeGenericMethod(image.ElementType); return((Mat)method.Invoke(null, new object[] { image })); }
//public static TElement Test<TElement>(IndexResolver<TElement> indexResolver) //{ //} //public static bool UseContourFunc(this IMatrixImage image, out MatrixImage<byte> retImage, Func<byte[], byte> coreFunc, int width, int height, bool alwaysCreateNew = false) //{ //} public static void Laplas(this IMatrixImage image) { var mask = new int[, ] { { -1, -2, -1 }, { -2, 12, -2 }, { -1, -2, -1 } }; image.SlidingWindow(new MatrixOperation <int>(mask, 0, 255)); }
public static void Negative(this IMatrixImage image) { using (image.SupressUpdating()) // Подавление обновлений при редактировании слоев { foreach (var item in image.Split(false)) // Для каждого слоя без копирования { item.Sub(256, false); // Вычитание каждого пикселя (256 - значение пикселя) } } }
public override IMatrixImage Invoke(IMatrixImage input) { var layers = input.Split(false); if (layers.Length == 1) { return(input); } else { return(input.CreateSingleGray().CreateImage()); } }
public static bool GetGray(this IMatrixImage image, out IMatrixImage?retImage) { if (image.LayerCount == 1) { retImage = null; return(false); } else { retImage = image.CreateSingleGray().CreateImage(); return(true); } }
public static bool GetRemoveAlpha(this IMatrixImage image, out IMatrixImage?retImage) { if (image.LayerCount == 4) { IMatrixLayer[] layers = image.Split(false); retImage = MatrixImageBuilder.CreateImage(layers, true); return(true); } else { retImage = null; return(false); } }
public override IMatrixImage Invoke(IMatrixImage input) { if (UseOpenCV) { OpenCvSharp.Mat mat = input.GetCVMat(); input.SetCVMat(mat.MedianBlur(Width)); mat.Dispose(); return(input); } else { input.SlidingWindow(new MedianeOperation(Width, Height)); //int offset = (Width * Height) / 2; //if (image is MatrixImage<byte> imgByte) //{ // foreach (var layer in imgByte.SplitWithoutAlpha()) // layer.SlidingWindow(Width, Height, a => a.OrderBy(a => a).ElementAt(offset)); //} //else if (image is MatrixImage<short> imgInt16) //{ // foreach (var layer in imgInt16.SplitWithoutAlpha()) // layer.SlidingWindow(Width, Height, a => a.OrderBy(a => a).ElementAt(offset)); //} //else if (image is MatrixImage<int> imgInt32) //{ // foreach (var layer in imgInt32.SplitWithoutAlpha()) // layer.SlidingWindow(Width, Height, a => a.OrderBy(a => a).ElementAt(offset)); //} //else if (image is MatrixImage<long> imgInt64) //{ // foreach (var layer in imgInt64.SplitWithoutAlpha()) // layer.SlidingWindow(Width, Height, a => a.OrderBy(a => a).ElementAt(offset)); //} //else if (image is MatrixImage<float> imgSingle) //{ // foreach (var layer in imgSingle.SplitWithoutAlpha()) // layer.SlidingWindow(Width, Height, a => a.OrderBy(a => a).ElementAt(offset)); //} //else if (image is MatrixImage<double> imgDouble) //{ // foreach (var layer in imgDouble.SplitWithoutAlpha()) // layer.SlidingWindow(Width, Height, a => a.OrderBy(a => a).ElementAt(offset)); //} //else throw new NotSupportedException(); return(input); } }
public override IMatrixImage Invoke(IMatrixImage input) { double[,] x = new double[, ] { { 1, 2, 1 }, { 0, 0, 0 }, { -1, -2, -1 } }; double[,] y = new double[, ] { { 1, 0, -1 }, { 2, 0, -2 }, { 1, 0, -1 } }; input.SlidingWindow(new GxGyOperation(3, 3, x, y)); return(input); //MatrixImage<byte> image = input.ToByteImage(true); //foreach (var layer in image.SplitWithoutAlpha()) // layer.SlidingWindow(3, 3, Func); //return image; }
partial void PartialCtor(IMatrixImage matrixImage, MatrixLayer <byte>[] layers) { PlotModel = new PlotModel(); if (layers.Length == 1) { PlotModel.Series.Add(CreateLineSeries(layers[0], OxyColor.FromRgb(64, 64, 64), "Gray")); } else if (layers.Length == 3) { PlotModel.Series.Add(CreateLineSeries(layers[0], OxyColor.FromArgb(192, 16, 16, 192), "Blue")); PlotModel.Series.Add(CreateLineSeries(layers[1], OxyColor.FromArgb(192, 16, 192, 16), "Green")); PlotModel.Series.Add(CreateLineSeries(layers[2], OxyColor.FromArgb(192, 192, 16, 16), "Red")); } else if (layers.Length == 4) { PlotModel.Series.Add(CreateLineSeries(layers[0], OxyColor.FromArgb(192, 16, 16, 192), "Blue")); PlotModel.Series.Add(CreateLineSeries(layers[1], OxyColor.FromArgb(192, 16, 192, 16), "Green")); PlotModel.Series.Add(CreateLineSeries(layers[2], OxyColor.FromArgb(192, 192, 16, 16), "Red")); PlotModel.Series.Add(CreateLineSeries(layers[3], OxyColor.FromArgb(128, 128, 128, 192), "Alpha")); } }
public override IMatrixImage Invoke(IMatrixImage input) { double[,] x = new double[, ] { { 0, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } }; double[,] y = new double[, ] { { 0, 0, 0 }, { 0, 0, 1 }, { 0, 1, 0 } }; input.SlidingWindow(new GxGyOperation(3, 3, x, y)); //input.SlidingWindow(new RobertsOperation(3, 3), true); return(input); //var image = input.ToByteImage(true); //foreach (var layer in image.SplitWithoutAlpha()) // layer.SlidingWindow(3, 3, Func); //return image; }
public override IMatrixImage Invoke(IMatrixImage input) { var image = (IMatrixImage)input.Clone(); if (image is MatrixImage <byte> imgByte) { foreach (var layer in imgByte.SplitWithoutAlpha()) { layer.SlidingWindow(Width, Height, ScriptFactory.GetFuncArr_T <byte>(Code, this)); } } else if (image is MatrixImage <int> imgInt) { foreach (var layer in imgInt.SplitWithoutAlpha()) { layer.SlidingWindow(Width, Height, ScriptFactory.GetFuncArr_T <int>(Code, this)); } } else if (image is MatrixImage <float> imgSingle) { foreach (var layer in imgSingle.SplitWithoutAlpha()) { layer.SlidingWindow(Width, Height, ScriptFactory.GetFuncArr_T <float>(Code, this)); } } else if (image is MatrixImage <double> imgDouble) { foreach (var layer in imgDouble.SplitWithoutAlpha()) { layer.SlidingWindow(Width, Height, ScriptFactory.GetFuncArr_T <double>(Code, this)); } } else { throw new NotSupportedException(); } return(image); }
public BitmapHandler(IMatrixImage matrixImage) : base(matrixImage) { MatrixLayer <byte>[] layers = matrixImage.Split(false).Select(a => a.ToByteLayer(false)).ToArray(); if (layers.Length == 1) { // GrayScale Bitmap = new Bitmap(matrixImage.Width, matrixImage.Height, PixelFormat.Format8bppIndexed); ColorPalette palette = Bitmap.Palette; Color[] ent = palette.Entries; for (int i = 0; i < 256; i++) { ent[i] = Color.FromArgb(i, i, i); // Настроить для Bitmap только цвета с оттенками серого } Bitmap.Palette = palette; Bitmap.FillGrayBitmap(layers[0]); matrixImage.Updated += (_, upd) => Bitmap.FillGrayBitmap(upd.Image.Split(false)[0]); } else if (layers.Length == 3) { // Bgr Bitmap = new Bitmap(matrixImage.Width, matrixImage.Height, PixelFormat.Format24bppRgb); Bitmap.FillBgrBitmap(matrixImage.Split(false)); matrixImage.Updated += (_, upd) => Bitmap.FillBgrBitmap(upd.Image.Split(false)); } else if (layers.Length == 4) { // Bgra Bitmap = new Bitmap(matrixImage.Width, matrixImage.Height, PixelFormat.Format32bppPArgb); Bitmap.FillBgraBitmap(matrixImage.Split(false)); matrixImage.Updated += (_, upd) => Bitmap.FillBgraBitmap(upd.Image.Split(false)); } else { throw new NotSupportedException(); } PartialCtor(matrixImage, layers); }
public override IMatrixImage Invoke(IMatrixImage input) { input.SlidingWindow(new AverageOperation(CoreWidth, CoreHeight)); return(input); }
partial void PartialCtor(IMatrixImage matrixImage, MatrixLayer <byte>[] layers);
public static void FillBitmap(this Bitmap bitmap, IMatrixImage image) { bitmap.FillBitmap(image.Split(false)); }
public void AddHistory(IMatrixImage image, string message) { AddHistory(new ImageHistory(image, message)); }
protected virtual void PartialCtor(IMatrixImage matrixImage, MatrixLayer <byte>[] layers) { }
public override IMatrixImage Invoke(IMatrixImage input) => Invoke((MatrixImage <TInput>)input);
public UpdateImage(UpdateLayer singleLayerUpdate, IMatrixImage image, Update update, (int x, int y, int width, int height)?rectangleUpdate)
public override IMatrixImage Invoke(IMatrixImage input) { var image = (IMatrixImage)input.Clone(); int offset = (3 * 3) / 2; if (image is MatrixImage <byte> imgByte) { foreach (var layer in imgByte.SplitWithoutAlpha()) { layer.SlidingWindow(3, 3, a => { var t = a[0] * 3; if (t > byte.MaxValue) { t = byte.MaxValue; } a[0] = (byte)t; return(a.OrderBy(a => a).ElementAt(offset)); }); } } else if (image is MatrixImage <short> imgInt16) { foreach (var layer in imgInt16.SplitWithoutAlpha()) { layer.SlidingWindow(3, 3, a => { var t = a[0] * 3; if (t > short.MaxValue) { t = short.MaxValue; } a[0] = (short)t; return(a.OrderBy(a => a).ElementAt(offset)); }); } } else if (image is MatrixImage <int> imgInt32) { foreach (var layer in imgInt32.SplitWithoutAlpha()) { layer.SlidingWindow(3, 3, a => { a[0] *= 3; return(a.OrderBy(a => a).ElementAt(offset)); }); } } else if (image is MatrixImage <long> imgInt64) { foreach (var layer in imgInt64.SplitWithoutAlpha()) { layer.SlidingWindow(3, 3, a => { a[0] *= 3; return(a.OrderBy(a => a).ElementAt(offset)); }); } } else if (image is MatrixImage <float> imgSingle) { foreach (var layer in imgSingle.SplitWithoutAlpha()) { layer.SlidingWindow(3, 3, a => { a[0] *= 3; return(a.OrderBy(a => a).ElementAt(offset)); }); } } else if (image is MatrixImage <double> imgDouble) { foreach (var layer in imgDouble.SplitWithoutAlpha()) { layer.SlidingWindow(3, 3, a => { a[0] *= 3; return(a.OrderBy(a => a).ElementAt(offset)); }); } } else { throw new NotSupportedException(); } return(image); }