help-gsl
[Top][All Lists]
Advanced

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

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


From: Juan Pablo Amorocho D.
Subject: Re: [Help-gsl] using histogram fuctions - not getting expected result.
Date: Fri, 29 Jun 2012 06:54:29 +0200

Hi Calvin,

If I understood it right you are asking two questions, one regarding the
segfault and the other about the correctness of your result. Though I don't
get how you could get any results if your code breaks down, but anyway...
You can use Valgrind to help you find the cause of the segfault. Take a
look here:

http://www.cprogramming.com/debugging/segfaults.html

Hope this helps,

Juan Pablo
 On Jun 29, 2012 4:27 AM, "Calvin Morrison" <address@hidden> wrote:

> 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]