/**Each row of img is projected onto the vertical axis. Resulting data length will be equal to the height of img. The profile is a summation of the grayscale values in each row. If fNormalize is true, then each value is divided by img.width() so it is the average grayscale value for the row instead of the sum. If fNormalize is true, the resulting profile values are divided by the image width. */ void DProfile::getImageVerticalProfile(const DImage &img, bool fNormalize){ int w, h; w = img.width(); h = img.height(); // allocate the rgProf array if(NULL == rgProf){ rgProf = (double*)malloc(h * sizeof(double)); D_CHECKPTR(rgProf); len = h; } else{ if(len != h){ rgProf = (double*)realloc(rgProf,h*sizeof(double)); D_CHECKPTR(rgProf); len = h; } } switch(img.getImageType()){ case DImage::DImage_u8: { D_uint8 *pu8; pu8=img.dataPointer_u8(); for(int y = 0, idx=0; y < h; ++y){ rgProf[y] = 0.; for(int x = 0; x < w; ++x, ++idx){ rgProf[y] += pu8[idx]; } if(fNormalize) rgProf[y] /= w; } } break; case DImage::DImage_flt_multi: { float *pflt; if(img.numChannels() > 1){ fprintf(stderr,"DProfile::getImageVerticalProfile() floats only " "supported with a single channel\n"); abort(); } pflt=img.dataPointer_flt(0); for(int y = 0, idx=0; y < h; ++y){ rgProf[y] = 0.; for(int x = 0; x < w; ++x, ++idx){ rgProf[y] += pflt[idx]; } if(fNormalize) rgProf[y] /= w; } } break; default: fprintf(stderr, "Not yet implemented!\n"); abort(); }//end switch(img.getImageType()) }