예제 #1
0
        /// <summary>
        /// does this polygon overlap with the other, within the given screen dimensions
        /// </summary>
        /// <param name="other">other polygon object</param>
        /// <param name="image_width">image width</param>
        /// <param name="image_height">image height</param>
        /// <returns></returns>
        public bool overlaps(polygon2D other, int image_width, int image_height)
        {
            int i;
            bool retval = false;

            i = 0;
            while ((i < x_points.Count) && (retval == false))
            {
                if (other.isInside(x_points[i] * 1000 / image_width, y_points[i] * 1000 / image_height)) retval = true;
                i++;
            }

            i = 0;
            while ((i < other.x_points.Count) && (retval == false))
            {
                if (isInside((float)other.x_points[i] * image_width / 1000, (float)other.y_points[i] * image_height / 1000)) retval = true;
                i++;
            }
            return (retval);
예제 #2
0
파일: image.cs 프로젝트: kasertim/sentience
        /// <summary>
        /// returns a grey scale histogram for the given image within the given perimeter region
        /// </summary>
        /// <param name="bmp">image data</param>
        /// <param name="wdth">width of the image</param>
        /// <param name="hght">height of the image</param>
        /// <param name="bytes_per_pixel">number of bytes per pixel</param>
        /// <param name="levels">histogram levels</param>
        /// <param name="perimeter">perimeter region inside which to calculate the histogram</param>
        /// <returns></returns>
        public static float[] GetGreyHistogram(byte[] bmp,
                                int wdth, int hght,
                                int bytes_per_pixel,
                                int levels,
                                polygon2D perimeter)
        {
            float[] hist = new float[levels];

            int tx = (int)perimeter.left();
            int ty = (int)perimeter.top();
            int bx = (int)perimeter.right();
            int by = (int)perimeter.bottom();

            for (int y = ty; y <= by; y++)
            {
                if ((y > -1) && (y < hght))
                {
                    for (int x = tx; x <= bx; x++)
                    {
                        if ((x > -1) && (x < wdth))
                        {
                            if (perimeter.isInside(x, y))
                            {
                                int n = ((y * wdth) + x) * bytes_per_pixel;
                                float intensity = 0;
                                for (int col = 0; col < bytes_per_pixel; col++)
                                    intensity += bmp[n + col];
                                intensity /= bytes_per_pixel;

                                int bucket = (int)Math.Round(intensity * levels / 255);
                                if (bucket >= levels) bucket = levels - 1;
                                hist[bucket]++;
                            }
                        }
                    }
                }
            }

            // normalise the histogram
            float max = 1;
            for (int level = 0; level < levels; level++)
                if (hist[level] > max) max = hist[level];

            for (int level = 0; level < levels; level++)
                hist[level] = hist[level] / max;

            return (hist);
        }
예제 #3
0
        /// <summary>
        /// return true if this polygon overlaps with another
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public bool overlaps(polygon2D other)
        {
            int i;
            bool retval = false;

            i = 0;
            while ((i < x_points.Count) && (retval == false))
            {
                if (other.isInside(x_points[i],y_points[i])) retval=true;
                i++;
            }

            i = 0;
            while ((i < other.x_points.Count) && (retval == false))
            {
                if (isInside((float)other.x_points[i], (float)other.y_points[i])) retval = true;
                i++;
            }
            return (retval);