help-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-gsl] using histogram fuctions - not getting expected result.


From: Calvin Morrison
Subject: [Help-gsl] using histogram fuctions - not getting expected result.
Date: Thu, 28 Jun 2012 22:27:15 -0400

Hi,

I'm working on a project which requires us to generate the statistical mode
of each pixel across many images. We would be comparing pixel (1,1) across
images 1,2,3,4 and so on. I thought the best way to do this would be to
create a histogram and grab the element with the highest frequency. I am
having some trouble with getting the correct output from this program, and
so here I am asking for help. my google searches were seemingly devoid of
any histogram examples other than the one included in the manual.

Here is a small portion of my code. The array is full of elements that look
like this array[image_number][x][y][ {red, green, blue} ]. I have removed
the excess code, but basically here we are iterating through j and k
already, and i is being looped through for that same pixel.

Unfortunately I am getting a segfault because my red_index, blue_index, and
green_index. I want to return the value of the higest frequency. Am I doing
this correctly?

  // Add red, green, and blue, values to their respective histogram
  for (i = 0; i < nImages; i++) {

        gsl_histogram_increment (r, array[i][j][k][0]);
        gsl_histogram_increment (g, array[i][j][k][1]);
        gsl_histogram_increment (b, array[i][j][k][2]);

      }

      size_t red = gsl_histogram_max_bin(r);
      size_t green = gsl_histogram_max_bin(g);
      size_t blue = gsl_histogram_max_bin(b);

      int red_index = gsl_histogram_get(r, red);
      int green_index = gsl_histogram_get(g, green);
      int blue_index = gsl_histogram_get(b, blue);

      // My code segfaults here because it is trying to access
array[red_index]  which is greater than the value of array[nImages]
      output[j][k][0] = array[red_index][j][k][0];
      output[j][k][1] = array[green_index][j][k][1];
      output[j][k][2] = array[blue_index][j][k][2];

      printf("out (%d,%d,%d,%d,%d) \n ", j, k, output[j][k][0],
output[j][k][1], output[j][k][2]);

I think I am not correctly getting the information from the histogram.
Again, I am looking to find which number in the array is most frequent. If
I am doing this properly, then the problem must be elsewhere!

Thank you,
Calvin Morrison


reply via email to

[Prev in Thread] Current Thread [Next in Thread]