Ejemplo n.º 1
0
        public override QBitmap processImage(QBitmap sourceImage, BackgroundWorker worker)
        {
            QBitmap resultImage = new QBitmap(sourceImage, false);
            int     ImgsW       = sourceImage.Width;
            int     ImgsH       = sourceImage.Height;

            int MaskW = Mask.SizeX;
            int MaskH = Mask.SizeY;

            for (int y = MaskH / 2; y < ImgsH - MaskH / 2; y++)
            {
                worker.ReportProgress(progressOffs + (int)(((float)y * progressPerc) / (ImgsH - MaskH)));
                if (worker.CancellationPending)
                {
                    return(null);
                }

                for (int x = MaskW / 2; x < ImgsW - MaskW / 2; x++)
                {
                    resultImage.SetPixel(x, y, calculateNewPixelColor(sourceImage, x, y));
                }
            }

            return(resultImage);
        }
Ejemplo n.º 2
0
        public SubstractionFilter(QBitmap mask, int persentage = 100, int offset = 0)
        {
            maskImage = mask;

            progressPerc = QM.clamp(persentage, 0, 100);
            progressOffs = QM.clamp(offset, 0, 100 - progressPerc);
        }
Ejemplo n.º 3
0
        protected override Color calculateNewPixelColor(QBitmap sourceImage, int x, int y)
        {
            int radiusX = kernel.GetLength(0) / 2;
            int radiusY = kernel.GetLength(1) / 2;

            double resultR = 0;
            double resultG = 0;
            double resultB = 0;

            for (int l = -radiusY; l <= radiusY; l++)
            {
                for (int k = -radiusX; k <= radiusX; k++)
                {
                    // Значение по X
                    int idX = QM.clamp(x + k, 0, sourceImage.Width - 1);
                    // Значение по Y
                    int idY = QM.clamp(y + l, 0, sourceImage.Height - 1);

                    // Каналы в точки X,Y
                    (byte R, byte G, byte B) = sourceImage.GetPixel(idX, idY);


                    // kernel[0...radiusX, 0...radiusY]
                    // Двумерная свертка
                    resultR += R * kernel[k + radiusX, l + radiusY];
                    resultG += G * kernel[k + radiusX, l + radiusY];
                    resultB += B * kernel[k + radiusX, l + radiusY];
                }
            }

            return(QM.Col(resultR, resultG, resultB));
        }
Ejemplo n.º 4
0
        public void AvgColors(QBitmap sourceImage, BackgroundWorker worker)
        {
            double _AVG_;
            double N = sourceImage.Width * sourceImage.Height;

            _R_ = 0;
            _B_ = 0;
            _G_ = 0;

            for (int i = 0; i < sourceImage.Width; i++)
            {
                for (int j = 0; j < sourceImage.Height; j++)
                {
                    (byte R, byte G, byte B) = sourceImage.GetPixel(i, j);

                    _R_ += R / N;
                    _G_ += G / N;
                    _B_ += B / N;
                }

                worker.ReportProgress((int)((float)i / sourceImage.Width * progress));
            }

            _AVG_ = (_R_ + _G_ + _B_) / 3.0;

            _R_ = _AVG_ / _R_;
            _G_ = _AVG_ / _G_;
            _B_ = _AVG_ / _B_;
        }
Ejemplo n.º 5
0
        protected override Color calculateNewPixelColor(QBitmap sourceImage, int x, int y)
        {
            int ImgsW  = sourceImage.Width;
            int ImgsH  = sourceImage.Height;
            int Radius = 2;

            double _R_ = 0;
            double _G_ = 0;
            double _B_ = 0;

            double Z = 1.0 / Math.Pow(Radius, 4);

            for (int i = QM.clamp(x - Radius, 0, ImgsW); i < QM.clamp(x + Radius, 0, ImgsW); i++)
            {
                double _R = 0;
                double _G = 0;
                double _B = 0;

                for (int j = QM.clamp(y - Radius, 0, ImgsH); j < QM.clamp(y + Radius, 0, ImgsH); j++)
                {
                    (byte R, byte G, byte B) = sourceImage.GetPixel(i, j);

                    _R += R;
                    _G += G;
                    _B += B;
                }

                _R_ += _R * Z;
                _G_ += _G * Z;
                _B_ += _B * Z;
            }

            return(QM.Col(_R_, _G_, _B_));
        }
Ejemplo n.º 6
0
        public override QBitmap processImage(QBitmap sourceImage, BackgroundWorker worker)
        {
            int percentage = 50 * progressPerc / 100;

            sourceImage = (new DilationFilter(percentage, progressOffs)).processImage(sourceImage, worker);
            sourceImage = (new ErosionFilter(percentage, progressOffs + percentage)).processImage(sourceImage, worker);

            return(sourceImage);
        }
Ejemplo n.º 7
0
        protected override Color calculateNewPixelColor(QBitmap sourceImage, int x, int y)
        {
            byte k = 15;

            //Получаем значения трех каналов пикселя с координатами (x,y)
            (byte R, byte G, byte B) = sourceImage.GetPixel(x, y);

            return(QM.Col(R + k, G + k, B + k));
        }
Ejemplo n.º 8
0
        public override QBitmap processImage(QBitmap sourceImage, BackgroundWorker worker)
        {
            int percentage = 50 * progressPerc / 100;

            SubstractionFilter Operator      = new SubstractionFilter(sourceImage, percentage, progressOffs);
            OpeningFilter      openingFilter = new OpeningFilter(percentage, progressOffs + percentage);
            QBitmap            openingImage  = openingFilter.processImage(sourceImage, worker);

            return(Operator.processImage(openingImage, worker));
        }
Ejemplo n.º 9
0
        protected override Color calculateNewPixelColor(QBitmap sourceImage, int x, int y)
        {
            (byte oR, byte oG, byte oB) = maskImage.GetPixel(QM.clamp(x, 0, maskImage.Width), QM.clamp(y, 0, maskImage.Height));
            (byte pR, byte pG, byte pB) = sourceImage.GetPixel(x, y);

            byte R = QM.clamp(oR - pR);
            byte G = QM.clamp(oG - pG);
            byte B = QM.clamp(oB - pB);

            return(QM.Col(R, G, B));
        }
Ejemplo n.º 10
0
        protected override Color calculateNewPixelColor(QBitmap sourceImage, int x, int y)
        {
            //Получаем значения трех каналов пикселя с координатами (x,y)
            (byte R, byte G, byte B) = sourceImage.GetPixel(x, y);

            R = QM.clamp(R * _R_);
            G = QM.clamp(G * _G_);
            B = QM.clamp(B * _B_);

            return(QM.Col(R, G, B));
        }
Ejemplo n.º 11
0
 public QBitmap(QBitmap OriginBitmap, bool fill = true)
 {
     if (fill)
     {
         Load(OriginBitmap._OriginBitmap);
     }
     else
     {
         _OriginBitmap = new Bitmap(OriginBitmap.Width, OriginBitmap.Height);
         update();
     }
 }
Ejemplo n.º 12
0
        protected override Color calculateNewPixelColor(QBitmap sourceImage, int x, int y)
        {
            byte k = 15;

            //Получаем значения трех каналов пикселя с координатами (x,y)
            (byte R, byte G, byte B) = sourceImage.GetPixel(x, y);

            double Intensity = (.299F * R + .587F * G + .113F * B);

            R = QM.clamp(Intensity + k * 2);
            G = QM.clamp(Intensity + k / 2);
            B = QM.clamp(Intensity - k * 1);

            return(QM.Col(R, G, B));
        }
Ejemplo n.º 13
0
        //общая для всех фильтров часть
        public virtual QBitmap processImage(QBitmap sourceImage, BackgroundWorker worker)
        {
            QBitmap resultImage = new QBitmap(sourceImage, false);

            for (int i = 0; i < sourceImage.Width; i++)
            {
                worker.ReportProgress(progressOffs + (int)((float)i / resultImage.Width * progressPerc));
                if (worker.CancellationPending)
                {
                    return(null);
                }

                for (int j = 0; j < sourceImage.Height; j++)
                {
                    resultImage.SetPixel(i, j, calculateNewPixelColor(sourceImage, i, j));
                }
            }

            return(resultImage);
        }
Ejemplo n.º 14
0
        public override QBitmap processImage(QBitmap sourceImage, BackgroundWorker worker)
        {
            AvgColors(sourceImage, worker);

            for (int i = 0; i < sourceImage.Width; i++)
            {
                worker.ReportProgress(50 + (int)((float)i / sourceImage.Width * progress));
                if (worker.CancellationPending)
                {
                    return(null);
                }

                for (int j = 0; j < sourceImage.Height; j++)
                {
                    sourceImage.SetPixel(i, j, calculateNewPixelColor(sourceImage, i, j));
                }
            }

            return(sourceImage);
        }
Ejemplo n.º 15
0
        public override QBitmap processImage(QBitmap sourceImage, BackgroundWorker worker)
        {
            int ImgsW = sourceImage.Width;
            int ImgsH = sourceImage.Height;

            for (int x = 0; x < ImgsW; x++)
            {
                worker.ReportProgress((int)((float)x / (ImgsW) * progressPerc));
                if (worker.CancellationPending)
                {
                    return(null);
                }

                for (int y = 0; y < ImgsH; y++)
                {
                    sourceImage.SetPixel(x, y, calculateNewPixelColor(sourceImage, x, y));
                }
            }

            return(sourceImage);
        }
Ejemplo n.º 16
0
        public override QBitmap processImage(QBitmap sourceImage, BackgroundWorker worker)
        {
            int percentage = 33 * progressPerc / 100;

            QBitmap SobelXImage = (new SobelXFilter(percentage, 0)).processImage(sourceImage, worker);
            QBitmap SobelYImage = (new SobelYFilter(percentage, percentage)).processImage(sourceImage, worker);

            QBitmap resultImage = new QBitmap(sourceImage, false);

            for (int i = 0; i < sourceImage.Width; i++)
            {
                worker.ReportProgress(2 * percentage + (int)((float)i / resultImage.Width * percentage));//сигнализирует элементу BackgroundWorker о текущем процессе
                if (worker.CancellationPending)
                {
                    return(null);
                }

                for (int j = 0; j < sourceImage.Height; j++)
                {
                    (byte xR, byte xG, byte xB) = SobelXImage.GetPixel(i, j);
                    (byte yR, byte yG, byte yB) = SobelYImage.GetPixel(i, j);

                    double dch = 0;

                    dch += xR * xR;
                    dch += xG * xG;
                    dch += xB * xB;

                    dch += yR * yR;
                    dch += yG * yG;
                    dch += yB * yB;

                    resultImage.SetPixel(i, j, Math.Sqrt(dch));
                }
            }

            return(resultImage);
        }
Ejemplo n.º 17
0
        protected override Color calculateNewPixelColor(QBitmap sourceImage, int x, int y)
        {
            int MaskW = Mask.SizeX;
            int MaskH = Mask.SizeY;

            byte maxR = 0;
            byte maxG = 0;
            byte maxB = 0;

            int MWHalf = MaskW / 2;
            int MHHalf = MaskH / 2;

            for (int j = -MHHalf; j <= MHHalf; j++)
            {
                for (int i = -MWHalf; i <= MWHalf; i++)
                {
                    (byte R, byte G, byte B) = sourceImage.GetPixel(x + i, y + j);

                    if ((Mask.map[MWHalf + i, MHHalf + j]) && (R > maxR))
                    {
                        maxR = R;
                    }

                    if ((Mask.map[MWHalf + i, MHHalf + j]) && (G > maxG))
                    {
                        maxG = G;
                    }

                    if ((Mask.map[MWHalf + i, MHHalf + j]) && (B > maxB))
                    {
                        maxB = B;
                    }
                }
            }

            return(QM.Col(maxR, maxG, maxB));
        }
Ejemplo n.º 18
0
        protected override Color calculateNewPixelColor(QBitmap sourceImage, int x, int y)
        {
            int MaskW = Mask.SizeX;
            int MaskH = Mask.SizeY;

            byte minR = 255;
            byte minG = 255;
            byte minB = 255;

            int MWHalf = MaskW / 2;
            int MHHalf = MaskH / 2;

            for (int j = -MHHalf; j <= MHHalf; j++)
            {
                for (int i = -MWHalf; i <= MWHalf; i++)
                {
                    (byte R, byte G, byte B) = sourceImage.GetPixel(x + i, y + j);

                    if ((Mask.map[i + MWHalf, j + MHHalf]) && (R < minR))
                    {
                        minR = R;
                    }

                    if ((Mask.map[i + MWHalf, j + MHHalf]) && (G < minG))
                    {
                        minG = G;
                    }

                    if ((Mask.map[i + MWHalf, j + MHHalf]) && (B < minB))
                    {
                        minB = B;
                    }
                }
            }

            return(QM.Col(minR, minG, minB));
        }
Ejemplo n.º 19
0
 protected override Color calculateNewPixelColor(QBitmap sourceImage, int x, int y)
 {
     (byte R, byte G, byte B) = sourceImage.GetPixel(x, y);  //Получаем значения трех каналов пикселя с координатами (x,y)
     return(QM.Col(.299F * R + .587F * G + .113F * B));      //Вычисляем значение трех каналов для градации серого
 }
Ejemplo n.º 20
0
 //переопред функцию
 protected override Color calculateNewPixelColor(QBitmap sourceImage, int x, int y)
 {
     (byte R, byte G, byte B) = sourceImage.GetPixel(x, y); //Получаем каналы цвет исходного пикселя
     return(QM.Col(255 - R, 255 - G, 255 - B));             //Вычисляем инверсию цвета
 }
Ejemplo n.º 21
0
 protected override Color calculateNewPixelColor(QBitmap sourceImage, int x, int y)
 {
     return(new Color());
 }
Ejemplo n.º 22
0
        private void Form1_Paint(object _sender, PaintEventArgs _e)
        {
            m_allEdges.Clear();
            for (var i = 0; i < Map.SIZE; ++i)
            {
                for (var j = 0; j < Map.SIZE; ++j)
                {
                    if (m_map[i, j] > 0)
                    {
                        var rectEdges = GetRectEdges(new Rectangle((int)(i * SZ), (int)(j * SZ), (int)SZ, (int)SZ), m_map[i, j]);
                        if (j > 0 && m_map[i, j - 1] == 0)
                        {
                            m_allEdges.Add(rectEdges[0]);
                        }
                        if (i < (Map.SIZE - 1) && m_map[i + 1, j] == 0)
                        {
                            m_allEdges.Add(rectEdges[1]);
                        }
                        if (j < (Map.SIZE - 1) && m_map[i, j + 1] == 0)
                        {
                            m_allEdges.Add(rectEdges[2]);
                        }
                        if (i > 0 && m_map[i - 1, j] == 0)
                        {
                            m_allEdges.Add(rectEdges[3]);
                        }
                    }
                }
            }

            #region зона видимости

            using (var g = Graphics.FromImage(m_buf3))
            {
                g.SmoothingMode = SmoothingMode.AntiAlias;
                g.Clear(Color.Empty);

                Draw(_e, new PointF(Map.SIZE * SZ / 2, Map.SIZE * SZ / 2), Color.White, 0, g);
            }

            #endregion


            using (var g = Graphics.FromImage(m_buf1))
            {
                //g.CompositingQuality = CompositingQuality.GammaCorrected;
                g.SmoothingMode = SmoothingMode.AntiAlias;
                g.Clear(Color.Empty);

                Draw(_e, new PointF(_mousePnt.X * SZ, _mousePnt.Y * SZ), Color.FromArgb(255, 255, 0, 0), 0, g);
            }
            using (var g = Graphics.FromImage(m_buf2))
            {
                //g.CompositingQuality = CompositingQuality.GammaCorrected;
                g.SmoothingMode = SmoothingMode.AntiAlias;
                g.Clear(Color.Empty);

                Draw(_e, new PointF(_mousePnt.Y * SZ, _mousePnt.X * SZ), Color.FromArgb(255, 0, 0, 255), 0, g);
            }
            using (var g = Graphics.FromImage(m_buf0))
            {
                //g.CompositingQuality = CompositingQuality.GammaCorrected;
                g.SmoothingMode = SmoothingMode.AntiAlias;
                g.Clear(Color.Empty);

                Draw(_e, new PointF(_mousePnt.Y * SZ, _mousePnt.Y * SZ), Color.FromArgb(255, 0, 255, 0), 0, g);
            }
            //DrawWalls(m_buf2);

            using (var t = new QBitmap(m_buf3))
            {
                t.ApplyLightMaps(new[] { m_buf0, m_buf1, m_buf2 });
            }

            //_e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            _e.Graphics.CompositingMode = CompositingMode.SourceCopy;
            //_e.Graphics.InterpolationMode = InterpolationMode.Bilinear;
            _e.Graphics.DrawImage(m_buf3, new RectangleF(0, 0, Map.SIZE, Map.SIZE), new RectangleF(0, 0, Map.SIZE * SZ, Map.SIZE * SZ), GraphicsUnit.Pixel);

            //Draw(_e, new PointF(_mousePnt.Y - m_offset.Y, _mousePnt.X - m_offset.X), Color.FromArgb(180, 255, 0), Map.SIZE);
            //Draw(_e, new PointF(_mousePnt.X - m_offset.X, _mousePnt.Y - m_offset.Y), Color.FromArgb(255, 180, 0), Map.SIZE * 2);
        }
Ejemplo n.º 23
0
 //вычисляет значение пикселя отфильтрованного изображения(уникальна для каждого фильтра)
 protected abstract Color calculateNewPixelColor(QBitmap sourceImage, int x, int y);