Ошибка в коде преобразования изображения - C#
Формулировка задачи:
есть вот такой код есть ошибка помогите разобраться в этом
Листинг программы
- using System.Drawing;
- using Image.Contracts;
- using System.Windows.Forms;
- using System.Drawing.Imaging;
- namespace Binarization.Transformation
- {
- public class BinarizationTransformation : IImageTransformation
- {
- public BinarizationTransformation()
- {
- BinarizationThreshold = 122;
- }
- public string Name
- {
- get
- {
- return "Binarization";
- }
- }
- public string Description
- {
- get
- {
- return "Transfroms the input image into binary image.";
- }
- }
- public int BinarizationThreshold { get; set; }
- public Control UI {
- get
- {
- return _ui ?? (_ui = new BinarizationParameters { numThreshhold = { Value = BinarizationThreshold } });
- }
- }
- private BinarizationParameters _ui;
- private Bitmap GetArgbCopy(System.Drawing.Image sourceImage)
- {
- var bmpNew = new Bitmap(sourceImage.Width, sourceImage.Height, PixelFormat.Format32bppArgb);
- using (Graphics graphics = Graphics.FromImage(bmpNew))
- {
- graphics.DrawImage(sourceImage, new Rectangle(0, 0, bmpNew.Width, bmpNew.Height)
- , new Rectangle(0, 0, bmpNew.Width, bmpNew.Height), GraphicsUnit.Pixel);
- graphics.Flush();
- }
- return bmpNew;
- }
- private Bitmap ApplyColorMatrix(System.Drawing.Image sourceImage, ColorMatrix colorMatrix)
- {
- Bitmap bmp32BppSource = GetArgbCopy(sourceImage);
- Bitmap bmp32BppDest = new Bitmap(bmp32BppSource.Width, bmp32BppSource.Height, PixelFormat.Format32bppArgb);
- using (Graphics graphics = Graphics.FromImage(bmp32BppDest))
- {
- ImageAttributes bmpAttributes = new ImageAttributes();
- bmpAttributes.SetColorMatrix(colorMatrix);
- graphics.DrawImage(bmp32BppSource, new Rectangle(0, 0, bmp32BppSource.Width, bmp32BppSource.Height),
- 0, 0, bmp32BppSource.Width, bmp32BppSource.Height, GraphicsUnit.Pixel, bmpAttributes);
- }
- bmp32BppSource.Dispose();
- return bmp32BppDest;
- }
- public Bitmap brg(System.Drawing.Image sourceImage, int threshold)
- {
- var k = threshold;
- ColorMatrix colorMatrix = new ColorMatrix(new float[][]
- {
- new float[] {k, k, k, 0, 0},
- new float[] {k, k, k, 0, 0},
- new float[] {k, k, k, 0, 0},
- new float[] {0, 0, 0, 1, 0},
- new float[] {-k, -k, -k, 0, 0}
- });
- return ApplyColorMatrix(sourceImage, colorMatrix);
- }
- public Bitmap Apply(Bitmap bmpImg)
- {
- /*
- Bitmap BinarizationImage = new Bitmap(bmpImg.Width, bmpImg.Height);
- BinarizationImage = (brg(BinarizationImage, BinarizationThreshold));
- return BinarizationImage;
- */ где-то тут ошибка как я думаю
- }
- }
- }
на формах так работает
Листинг программы
- private void Apply_Click(object sender, EventArgs e)
- {
- var pic =new Bitmap(pictureBox1.Image);
- var RGBFilters = new ExtBitmap();
- if (pictureBox1.Image != null)
- {
- pictureBox2.Image = (RGBFilters.ColorBalance(pic,(byte)trcRed.Value, (byte)trcGreen.Value, (byte)trcRed.Value));
- }
с выводом решено но теперь проблема с BinarizationThreshold он при выполнение не учитывается
Листинг программы
- public Bitmap Apply(Bitmap bmpImg)
- {
- Bitmap BinarizationImage = new Bitmap(bmpImg.Width, bmpImg.Height);
- BinarizationImage = (brg(bmpImg,BinarizationThreshold ));
- return BinarizationImage;
- }
Решение задачи: «Ошибка в коде преобразования изображения»
textual
Листинг программы
- public Control UI
- {
- get
- {
- if (_ui == null)
- {
- _ui = new BinarizationParameters {numThreshhold = {Value = BinarizationThreshold}};
- _ui.numThreshhold.ValueChanged += (o, args) => { BinarizationThreshold = (int) _ui.numThreshhold.Value; };
- }
- return _ui;
- }
- }
- private BinarizationParameters _ui;
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д