Example #1
0
        public void FromGrayImage(GrayScaleImage gimage)
        {
            ImageMatrix[0] = new DenseMatrix(gimage.RowCount, gimage.ColumnCount);
            ImageMatrix[1] = new DenseMatrix(gimage.RowCount, gimage.ColumnCount);
            ImageMatrix[2] = new DenseMatrix(gimage.RowCount, gimage.ColumnCount);
            int x, y;

            for(x = 0; x < ColumnCount; ++x)
            {
                for(y = 0; y < RowCount; ++y)
                {
                    this[y, x, 0] = gimage[y, x];
                    this[y, x, 1] = gimage[y, x];
                    this[y, x, 2] = gimage[y, x];
                }
            }
        }
Example #2
0
 public void StretchHistogram(GrayScaleImage image)
 {
     HistogramOperations.StretchHistogram(image);
 }
Example #3
0
 public GrayImageDebugView(GrayScaleImage img)
 {
     _image = img;
 }
Example #4
0
 public void SaturateRatioHistogram(GrayScaleImage image)
 {
     HistogramOperations.SaturateRatioHistogram(image, SaturateRatioLow, SaturateRatioHigh);
 }
Example #5
0
 public void EqualizeHistogram(GrayScaleImage image)
 {
     HistogramOperations.EqualizeHistogram(image);
 }
Example #6
0
        public override bool Detect()
        {
            int ymax = Image.SizeY - _borderSize;
            int xmax = Image.SizeX - _borderSize;
            int x, y, dx, dy;
            double[,] usan = new double[7, 7];

            FeatureMap = new GrayScaleImage()
            {
                ImageMatrix = new DenseMatrix(Image.SizeY, Image.SizeX)
            };

            double response = 0.0f;
            // Look-up table for current threshold for fast assimiliance computing
            double[] assimilianceLUT = new double[512];
            for(int di = 0; di < 511; di++)
            {
                assimilianceLUT[di] = (double)Math.Exp(
                                -Math.Pow( (((double)(di-255))/255.0f) / _t_intensity, 6) );
            }
            int dymax;
            // For each point in image
            for (x = _borderSize; x < xmax; ++x)
            {
                for (y = _borderSize; y < ymax; ++y)
                {
                    response = 0.0f;
                    // For each point in usan mask
                    for(dx = -3; dx <= 3; dx++ )
                    {
                        dymax = _ybounds[dx + 3];
                        for (dy = -_ybounds[dx+3]; dy <= dymax; ++dy)
                        {
                            // Find its usan assimiliance coeff
                            // usan[dy + 3, dx + 3] = (double)Math.Exp(
                            //    -(double)Math.Pow(((Image[y,x] - Image[y+dy,x+dx]) / _t_intensity), 6) );
                           // usan[dy + 3, dx + 3] = assimilianceLUT[(int)(Math.Abs(Image[y, x] - Image[y + dy, x + dx]) * 255)];
                            response += assimilianceLUT[(int)((Image[y, x] - Image[y + dy, x + dx]) * 255) + 256];
                        }
                    }
                    // Response <= threshold -> no feature
                    FeatureMap[y, x] = (double)Math.Max(0.0, -_t_isFeature + response);
                }
            }

            if (_nonMaxSup)
            {
                Matrix<double> resp = FeatureMap.ImageMatrix.Clone();
                //Non max suppresion
                for (x = _borderSize; x < xmax; ++x)
                {
                    for (y = _borderSize; y < ymax; ++y)
                    {
                        if (FeatureMap[y, x] > 0.0f)
                            if(!IsMaximum(resp, y, x, 2))
                            {
                                FeatureMap[y, x] = 0.0f;
                            }
                    }
                }
            }

            return true;
        }
Example #7
0
        public override void Detect()
        {
            Terminate = false;
            int ymax = Image.RowCount - _borderSize;
            int xmax = Image.ColumnCount - _borderSize;
            int x, y, dx, dy;
            double[,] usan = new double[7, 7];

            FeatureMap = new GrayScaleImage()
            {
                ImageMatrix = new DenseMatrix(Image.RowCount, Image.ColumnCount)
            };
            FeaturePoints = new List<IntVector2>();

            double response = 0.0f;
            // Look-up table for current threshold for fast assimiliance computing
            double[] assimilianceLUT = new double[512];
            for(int di = 0; di < 511; di++)
            {
                assimilianceLUT[di] = Math.Exp(-Math.Pow(
                    ((di - 255.0) / 255.0) / _t_intensity, 6));
            }
            int dymax;
            // For each point in image
            for(x = _borderSize; x < xmax; ++x)
            {
                CurrentPixel.X = x;
                for(y = _borderSize; y < ymax; ++y)
                {
                    if(Terminate) return;
                    CurrentPixel.Y = y;
                    if(Image.HaveValueAt(y, x))
                    {
                        response = 0.0;
                        // For each point in usan mask
                        for(dx = -3; dx <= 3; dx++)
                        {
                            dymax = _ybounds[dx + 3];
                            for(dy = -_ybounds[dx + 3]; dy <= dymax; ++dy)
                            {
                                // Find its usan assimiliance coeff
                                // usan[dy + 3, dx + 3] = (double)Math.Exp(
                                //    -(double)Math.Pow(((Image[y,x] - Image[y+dy,x+dx]) / _t_intensity), 6) );
                                // usan[dy + 3, dx + 3] = assimilianceLUT[(int)(Math.Abs(Image[y, x] - Image[y + dy, x + dx]) * 255)];
                                response += assimilianceLUT[(int)((Image[y, x] - Image[y + dy, x + dx]) * 255) + 256];
                            }
                        }
                        // Response >= threshold -> no feature
                        FeatureMap[y, x] = Math.Max(0.0, _t_isFeature - response);
                        if(!_nonMaxSup)
                            FeaturePoints.Add(new IntVector2(x, y));
                    }
                }
            }

            if(_nonMaxSup)
            {
                Matrix<double> resp = FeatureMap.ImageMatrix.Clone();
                //Non max suppresion
                for(x = _borderSize; x < xmax; ++x)
                {
                    CurrentPixel.X = x;
                    for(y = _borderSize; y < ymax; ++y)
                    {
                        if(Terminate) return;
                        CurrentPixel.Y = y;
                        if(FeatureMap[y, x] > 0.0f)
                        {
                            //if(!IsMaximum(resp, y, x, 2))
                            //{
                            //    FeatureMap[y, x] = 0.0f;
                            //}
                            //else
                            //    FeaturePoints.Add(new IntVector2(x, y));
                            FloodFindMaximum(y, x);
                        }
                    }
                }

                for(x = 0; x < Image.ColumnCount; ++x)
                {
                    for(y = 0; y < Image.RowCount; ++y)
                    {
                        if(FeatureMap[y, x] > 0.0)
                        {
                            FeaturePoints.Add(new IntVector2(x, y));
                        }
                    }
                }
            }

            // Scale map so that max feature is 1
            FeatureMap.ImageMatrix.MultiplyThis(1.0 / FeatureMap.ImageMatrix.AbsoulteMaximum().Item3);

            return;
        }
        private void _butSegment_Click(object sender, RoutedEventArgs e)
        {
            if(_imageControl.ImageSource != null)
            {
                ColorImage img = new ColorImage();
                img.FromBitmapSource(_imageControl.ImageSource);

                var window = new ParametrizedProcessorsSelectionWindow();
                window.AddProcessorFamily("Segmentation");
                window.AddToFamily("Segmentation", new MeanShiftSegmentation());

                window.ShowDialog();
                if(window.Accepted)
                {
                    ImageSegmentation segmentation = (ImageSegmentation)window.GetSelectedProcessor("Segmentation");

                    GrayScaleImage imgGray = new GrayScaleImage();
                    imgGray.FromColorImage(img);

                    //segmentation.SegmentColor(img);
                    segmentation.SegmentGray(imgGray.ImageMatrix);

                    //var segments = segmentation.Segments_Color;
                    var segments = segmentation.Segments;
                    int[,] indices = segmentation.SegmentAssignments;

                    ColorImage imgFinal = new ColorImage();
                    imgFinal.ImageMatrix[0] = new DenseMatrix(img.RowCount, img.ColumnCount);
                    imgFinal.ImageMatrix[1] = new DenseMatrix(img.RowCount, img.ColumnCount);
                    imgFinal.ImageMatrix[2] = new DenseMatrix(img.RowCount, img.ColumnCount);

                    for(int r = 0; r < img.RowCount; ++r)
                    {
                        for(int c = 0; c < img.ColumnCount; ++c)
                        {
                            imgFinal[r, c, RGBChannel.Red] = ((ImageSegmentation.Segment_Gray)segments[indices[r, c]]).Value;
                            imgFinal[r, c, RGBChannel.Green] = ((ImageSegmentation.Segment_Gray)segments[indices[r, c]]).Value;
                            imgFinal[r, c, RGBChannel.Blue] = ((ImageSegmentation.Segment_Gray)segments[indices[r, c]]).Value;
                            //imgFinal[r, c, RGBChannel.Red] = segments[indices[r, c]].Red;
                            // imgFinal[r, c, RGBChannel.Green] = segments[indices[r, c]].Green;
                            //imgFinal[r, c, RGBChannel.Blue] = segments[indices[r, c]].Blue;
                        }
                    }

                    _imageControl.ImageSource = imgFinal.ToBitmapSource();
                }
            }
        }