views:

64

answers:

2

hello, i need some help with haar transformation, i have to apply it on an image. My math is bad, my english not all that awesome and i find it hard to understand from articles on the internet. I found this page http://www.cs.ucf.edu/~mali/haar/haar.cpp where the haar transformation is applied on 2d matrix. I suppose if i give image pixels matrix in there, it should work? im confused about this stuff, could someone enlighten me a bit please? Thank you!

+1  A: 

There is an example at the end of the URL you point to. Look inside the main() function.

  • the 2D variant takes a float** and two parameters, height and width
  • the float** points to rows of grayscale pixels
  • each row is a float*, a pointer to the first pixel in the row
  • each float value is the intensity value of the pixel
  • in the example code, the dimensions are 4x4.

This is where the memory is allocated:

float **mat = new float*[4];
for(int m=0;m<4;m++)
  mat[m] = new float[4];

This is where the pixel values are set:

mat[0][0] = 5; mat[0][1] = 6; mat[0][2] = 1; mat[0][3] = 2;
mat[1][0] = 4; mat[1][1] = 2; mat[1][2] = 5; mat[1][3] = 5;
mat[2][0] = 3; mat[2][1] = 1; mat[2][2] = 7; mat[2][3] = 1;
mat[3][0] = 6; mat[3][1] = 3; mat[3][2] = 5; mat[3][3] = 1;

This is where the haar2 function is called:

haar2(mat,4,4);

All you need to do is provide the data as needed by the function (float**) with the right dimensions. You probably want to store the results to an output file that you can open in an image viewing application.

Look for the PGM format for a really easy solution. Note that the results of the haar function will give you floating point values, which you may have to compress down to 8 bit to view the image.

BennyG
thank you very much, ill look into this!
kabatusuka
btw, im getting negative numbers in matrix, does this PGM work ok with negatives?
kabatusuka
PGM uses the byte range [0,255]. You'll have to map your float range to that anyway. Mapping -1234.56f to 0 could make sense for you (I don't know what the output domain of your Haar transform is)
MSalters
The easiest solution is to find the minimum and maximum values in the matrix, then scale each value linearly: x = (x - min) / (max - min) * 255. Depending on the histogram, you may end up with a very bright or very dark image. To improve the contrast, consider histogram equalization solutions: http://en.wikipedia.org/wiki/Histogram_equalization
BennyG
A: 

If you're trying to do object detection using Haar features, pay a look at OpenCV: http://opencv.willowgarage.com/documentation/cpp/object_detection.html

Virgil