Exemple #1
0
 /// <summary>
 /// Buid an Histogram for a bitmap
 /// </summary>
 /// <param name="bmp">The bitmap to be analyzed</param>
 /// <returns>an array of float containing the frequency found for each luminance</returns>
 internal static float[] getFHistogram(Bitmap bmp)
 {
     float[] hist = new float[256];
     if (bmp != null && bmp.Width * bmp.Height != 0)
     {
         for (int i = 0; i < bmp.Width; i++)
         {
             for (int j = 0; j < bmp.Height; j++)
             {
                 int lum = IPUtil.RGB2Yint(bmp.GetPixel(i, j));
                 hist[lum] += 1.0f;
             }
         }
         float nbp = bmp.Width * bmp.Height;
         for (int j = 0; j < hist.Length; j++)
         {
             hist[j] /= nbp;
         }
     }
     return(hist);
 }
Exemple #2
0
 /// <summary>
 /// Retrieve the histogram of 2 Bitmap
 /// </summary>
 /// <param name="bmp1">the first bitmap</param>
 /// <param name="bmp2">the second bitmap</param>
 /// <returns>the bihistogram of the bitmap</returns>
 internal static float[,] getFBiHistogram(Bitmap bmp1, Bitmap bmp2)
 {
     float[,] hist = new float[256, 256];
     if (bmp1 != null && bmp1.Width * bmp1.Height != 0)
     {
         if (bmp2 != null && bmp2.Width * bmp2.Height != 0)
         {
             if (bmp1.Width == bmp2.Width && bmp1.Height == bmp2.Height)
             {
                 int wi = bmp1.Width;
                 int he = bmp1.Height;
                 for (int i = 0; i < wi; i++)
                 {
                     for (int j = 0; j < he; j++)
                     {
                         int lum1 = IPUtil.RGB2Yint(bmp1.GetPixel(i, j));
                         int lum2 = IPUtil.RGB2Yint(bmp2.GetPixel(i, j));
                         hist[lum1, lum2] += 1.0f;
                     }
                 }
                 float nbp = wi * he;
                 nbp *= nbp;
                 int w = hist.GetUpperBound(0);
                 int h = hist.GetUpperBound(1);
                 for (int i = 0; i < w; i++)
                 {
                     for (int j = 0; j < h; j++)
                     {
                         hist[i, j] /= nbp;
                     }
                 }
             }
         }
     }
     return(hist);
 }