示例#1
0
        /// <summary>
        /// Check if two descriptor are matching, using this criterion
        /// </summary>
        /// <param name="descriptorToFind">The original descriptor</param>
        /// <param name="descriptorTest">The descriptor to test</param>
        /// <returns>true if within tolerance for this criterion, false otherwise</returns>
        public override bool Pass(IDescriptor descriptorToFind, IDescriptor descriptorTest)
        {
            double dist = 0.0;

            DescriptorSquareMatrix silhouetteToFind = (DescriptorSquareMatrix)GetDependendObjects(descriptorToFind, "silhouette");
            DescriptorSquareMatrix silhouetteTest   = (DescriptorSquareMatrix)GetDependendObjects(descriptorTest, "silhouette");

            //

            for (int x = 0; x < DescriptorSquareMatrix.Length; x++)
            {
                for (int y = 0; y < DescriptorSquareMatrix.Length; y++)
                {
                    dist += (double)Math.Abs(silhouetteToFind[x, y] - silhouetteTest[x, y]);
                }
            }

/*
 *              //
 *
 *
 *
 *
 *
 *
 *
 *
 */
            DistanceBetweenDescriptors = dist;
            return(dist > (double)Value ? false : true);
        }
示例#2
0
        /// <summary>
        /// Create a new instance of this type -- constructor defined for serializatiom
        /// </summary>
        /// <param name="info">The SerializationInfo member</param>
        /// <param name="context">The StreamingContext member</param>
        protected MomentDescriptorBase(SerializationInfo info, StreamingContext context) : base(info, context)
        {
            xMin              = (int)info.GetInt32("xMin");
            yMin              = (int)info.GetInt32("yMin");
            xMax              = (int)info.GetInt32("xMax");
            yMax              = (int)info.GetInt32("yMax");
            xMedian           = (float)info.GetDouble("xMedian");
            yMedian           = (float)info.GetDouble("yMedian");
            xMedianSilhouette = (float)info.GetDouble("xMedianSilhouette");
            yMedianSilhouette = (float)info.GetDouble("yMedianSilhouette");
            DescriptorSquareMatrix silhouette             = (DescriptorSquareMatrix)info.GetValue("Silhouette", typeof(DescriptorSquareMatrix));
            DescriptorSquareMatrix shape                  = (DescriptorSquareMatrix)info.GetValue("Shape", typeof(DescriptorSquareMatrix));
            DescriptorSquareMatrix texture                = (DescriptorSquareMatrix)info.GetValue("Texture", typeof(DescriptorSquareMatrix));
            ColorDouble            shapeColorAverage      = (ColorDouble)info.GetValue("ShapeColorAverage", typeof(ColorDouble));
            ColorDouble            silhouetteColorAverage = (ColorDouble)info.GetValue("SilhouetteColorAverage", typeof(ColorDouble));

            DescriptorDependentObjects.Add("silhouette", silhouette);
            DescriptorDependentObjects.Add("shape", shape);
            DescriptorDependentObjects.Add("texture", texture);
            DescriptorDependentObjects.Add("shapecoloraverage", shapeColorAverage);
            DescriptorDependentObjects.Add("silhouettecoloraverage", silhouetteColorAverage);
        }
        /// <summary>
        /// Compute all Descriptors for the bitmap.
        /// </summary>
        /// <param name="silhouetteExtraPixels">The pixels participating in the silhouette</param>
        public override void ComputeDescriptor(Pixel[] silhouetteExtraPixels)
        {
            base.ComputeDescriptor(silhouetteExtraPixels);
            float dist           = GetMaxDistance(xMedian, yMedian);
            float distSilhouette = GetMaxDistance(xMedianSilhouette, yMedianSilhouette);

            DescriptorSquareMatrix silhouette = (DescriptorSquareMatrix)DescriptorDependentObjects["silhouette"];
            DescriptorSquareMatrix shape      = (DescriptorSquareMatrix)DescriptorDependentObjects["shape"];
            DescriptorSquareMatrix texture    = (DescriptorSquareMatrix)DescriptorDependentObjects["texture"];

            foreach (Pixel pixel in ParticipatingPixels)
            {
                // compute shape
                float xOffset           = ((float)pixel.X - xMedian) / dist;
                float yOffset           = ((float)pixel.Y - yMedian) / dist;
                float xOffsetSilhouette = ((float)pixel.X - xMedianSilhouette) / distSilhouette;
                float yOffsetSilhouette = ((float)pixel.Y - yMedianSilhouette) / distSilhouette;

                // WARNING: we add an offest of 1.0f to distinguish black from background
                // otherwise info is lost and black objects have the same ExtDescriptors : a null matrix
                float luminance = (float)((pixel.Color.ExtendedBlue + pixel.Color.ExtendedRed + pixel.Color.ExtendedGreen) / 3.0) + 1.0f;

                float yterm           = 1.0f;
                float ytermSilhouette = 1.0f;
                for (int l = 0; l < DescriptorSquareMatrix.Length; l++)
                {
                    float xterm           = 1.0f;
                    float xtermSilhouette = 1.0f;
                    for (int m = 0; m < DescriptorSquareMatrix.Length; m++)
                    {
                        float xyprod = xterm * yterm;
                        silhouette[l, m] += xtermSilhouette * ytermSilhouette;
                        shape[l, m]      += xyprod;
                        texture[l, m]    += luminance * xyprod;
                        xterm            *= xOffset;
                        xtermSilhouette  *= xOffsetSilhouette;
                    }
                    yterm           *= yOffset;
                    ytermSilhouette *= yOffsetSilhouette;
                }
            }
            if (silhouetteExtraPixels != null)
            {
                foreach (Pixel pixel in silhouetteExtraPixels)
                {
                    // compute silhouette (add extra pixels)
                    float xOffsetSilhouette = ((float)pixel.X - xMedianSilhouette) / distSilhouette;
                    float yOffsetSilhouette = ((float)pixel.Y - yMedianSilhouette) / distSilhouette;

                    float ytermSilhouette = 1.0f;
                    for (int l = 0; l < DescriptorSquareMatrix.Length; l++)
                    {
                        float xtermSilhouette = 1.0f;
                        for (int m = 0; m < DescriptorSquareMatrix.Length; m++)
                        {
                            silhouette[l, m] += xtermSilhouette * ytermSilhouette;
                            xtermSilhouette  *= xOffsetSilhouette;
                        }
                        ytermSilhouette *= yOffsetSilhouette;
                    }
                }
            }

            // Normalize the matrices
            for (int y = 0; y < DescriptorSquareMatrix.Length; y++)
            {
                for (int x = 0; x < DescriptorSquareMatrix.Length; x++)
                {
                    silhouette[x, y] /= BoundingBoxArea;
                    shape[x, y]      /= BoundingBoxArea;
                    texture[x, y]    /= BoundingBoxArea;
                }
            }
        }