コード例 #1
0
        public static ImageProjection ProjectAndFindVarianceOnVerticalLine(GrayImage image)
        {
            int             lineIdx            = 0;
            float           meanAccumlator     = 0;
            float           mean               = 0;
            int             lineCrossingPoints = 0;
            int             width              = image.Width;
            ImageProjection vertical           = new ImageProjection {
                Vtheta = 0, Density = new uint[image.Height]
            };

            for (int index = 1; index < image.Pixels.Length; index++)
            {
                lineCrossingPoints = 0;
                uint lineProject = 0;
                for (int j = 1; j < width; j++)
                {
                    if (image.Pixels[index] > 0)
                    {
                        lineProject++;
                    }

                    if (image.Pixels[index - 1] < image.Pixels[index])
                    {
                        lineCrossingPoints++;
                    }
                    index++;
                }
                lineIdx++;
                float delta = lineCrossingPoints - mean;
                mean += delta / lineIdx;
                float delta2 = lineCrossingPoints - mean;
                meanAccumlator += delta * delta2;
                vertical.Density[lineIdx - 1] = lineProject;
            }
            vertical.Vtheta = meanAccumlator / lineIdx;
            return(vertical);
        }
コード例 #2
0
        public static ImageProjection ProjectAndFindVarianceOnHorizontalLine(GrayImage image)
        {
            int             lineIdx            = 0;
            float           meanAccumlator     = 0;
            float           mean               = 0;
            int             lineCrossingPoints = 0;
            int             width              = image.Width;
            ImageProjection horizontal         = new ImageProjection {
                Vtheta = 0, Density = new uint[width]
            };

            for (int j = 0; j < width; j++)
            {
                lineCrossingPoints = 0;
                uint lineProject = 0;
                for (int index = j + width; index < image.Pixels.Length; index += width)
                {
                    if (image.Pixels[index] > 0)
                    {
                        lineProject++;
                    }

                    if (image.Pixels[index - width] < image.Pixels[index])
                    {
                        lineCrossingPoints++;
                    }
                }
                lineIdx++;
                float delta = lineCrossingPoints - mean;
                mean += delta / lineIdx;
                float delta2 = lineCrossingPoints - mean;
                meanAccumlator += delta * delta2;
                horizontal.Density[lineIdx - 1] = lineProject;
            }
            horizontal.Vtheta = meanAccumlator / lineIdx;
            return(horizontal);
        }