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: Sam Mason
Subject: Re: [Help-gsl] using histogram fuctions - not getting expected result.
Date: Fri, 29 Jun 2012 17:13:30 +0100

On 29 June 2012 16:16, Calvin Morrison <address@hidden> wrote:
> https://github.com/mutantturkey/FlyTracking/blob/master/fly-tools/derive-background/pixel.c

You really don't need the GSL histogram routines for that; just something like:

int
findmax (uint8_t *p, int n)
{
  int mx = 0, v = p[0];
  for (int i = 1; i < n; i++) {
    if (p[i] > v) {
      v = p[i];
      mx = i;
    }
  }
  return mx;
}

  uint8_t histr[256] = { 0 }, histg[256] = { 0 }, histb[256] = { 0 };

  for (int i = 0; i < nImages; i++) {
    histr[array[i][j][k][0]] += 1;
    histg[array[i][j][k][1]] += 1;
    histb[array[i][j][k][2]] += 1;
  }

  output[j][k][0] = findmax(histr, 256);
  output[j][k][1] = findmax(histg, 256);
  output[j][k][2] = findmax(histb, 256);

I'd also recommend against storing the "array" as you are.  Traversing
lots of pointers is particularly inefficient (probably important if
you're in CS; chasing down four pointers is going to kill performance
as this is in the inner loop).  It's much easier to allocate a big
block of memory; i.e:

  uint8_t * array = calloc(nImages * width * height * 3);

and use the following to access an arbitrary pixel:

  // return a pointer rgb pixel triplet
  static inline uint8_t *getpixel(int image, int x, int y) { return
&array[((image * width + x) * height + y) * 3]; }

But for cases like where you're running along going over the same
pixel for many images, you can do something like:

  uint8_t *px = (j * height + k) * 3;
  const size_t step = width * height * 3;
  for (int i = 0; i < nImages; i++) {
    histr[px[0]] += 1;
    histg[px[1]] += 1;
    histb[px[2]] += 1;
    px += step;
  }

Also, just thought that if you've got more than about 500 images
you're better off (i.e. your "working set" will be smaller) storing
all the histograms (i.e. width*height*3 histograms) in memory and
streaming through the images.  A

Hope that helps!

  Sam




reply via email to

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