LUT Help please

LUT Help please

I am trying to use one of the LUT calls and can get it to compile but it throws an exception on execution. Simplified code is below to try to get it to work but no luck yet. Any pointers :) would be appreciated. The problem is with my pValues and pLevels settings (same for this test) but I don't see where.

Ipp32s lutval[3];
const Ipp32s *p_lutval = lutval;
int redvals [256];
int grnvals [256];
int bluvals [256];

int *p_reds = redvals;
int *p_grns = grnvals;
int *p_blus = bluvals;
lutval[0]= *p_reds;//set array to pointer to buffer
lutval[1]= *p_grns;
lutval[2]= *p_blus;

int i;
for ( i = 0; i <= 255; i++ )
{
redvals[i]=i;
grnvals[i]=i;
bluvals[i]=i;
}

int numblevel[3];
numblevel[0] = 256;
numblevel[1] = 256 ;
numblevel[2] = 256 ;

rslt = ippiLUT_8u_C3R( p_mem, p_stepbyte,
(Ipp8u*) thisimg->DataPtr(), thisimg->Step(), imgsz ,
&p_lutval, &p_lutval, numblevel);

6 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hi,

it seems you are using wrong initialization. Could you please look at code below:

int redvals [256];
int grnvals [256];
int bluvals [256];

int i;

for ( i = 0; i <= 255; i++ )
{
redvals[i] = i;
grnvals[i] = i;
bluvals[i] = i;
}

const Ipp32s* lutval[3];

lutval[0] = redvals;
lutval[1] = grnvals;
lutval[2] = bluvals;

int numblevel[3];

numblevel[0] = 256;
numblevel[1] = 256;
numblevel[2] = 256;

rslt = ippiLUT_8u_C3R(p_mem, p_stepbyte, (Ipp8u*) thisimg->DataPtr(), thisimg->Step(), imgsz , lutval, lutval, numblevel);

Regards,
Vladimir

Vladimir,
Thanks once again for the assistance. Very simple solution once the fog lifted! LUT now working nicely. I use it to turn off color channels as needed for an anaglyph stereo vision application.
Rick

Hi Rick,

I'm glad if we can help you. You are welcome:)

Regards,
Vladimir

Hey Vladimir,

I'm wondering if the LUT function prototype (& usage) have changed since you posted this solution. From the 5.1 IPPI reference manual:

This function performs intensity transformation of the source image pSrc using the lookup table (LUT) specified by the arrays pLevels and pValues. Every source pixel pSrc(x,y) from the range [pLevels[k], pLevels[k+1]) is mapped to the destination pixel pDst(x,y) whose value is equal to the intensity pValues[k].

Length of the pLevels and pValues arrays is defined by the nLevels parameter. Number of level and intensity values is less than nLevels by one. Pixels in the pSrc image that are not in the range [pLevels[0], pLevels[nLevels-1]) are copied to the pDst image without any transformation.

Note that the pLevel ranges are inclusive [ at the bottom end and exclusive ) at the top end; of particular note is the statement that Pixels in the pSrc image that are not in the range [pLevels[0], Levels[nLevels-1]) are copied to the pDst image without any transformation. In the case of the code fragment, pLevels[nLevels-1] = 255, and thus the transformation will only take place for pixels in the range of [0, 255), which excludes the value of 255 from being transformed (in this case, it isnt a problem since the transformation is the identity function, but it would be a problem in some non-linear problems, such as classification which just happens to be my problem ;)

Also, I dont understand why the documentation states that both the number of levels and values should be nLevels-1. According to this statement in the manual: Every source pixel pSrc(x,y) from the range [pLevels[k], pLevels[k+1]) is mapped to the destination pixel pDst(x,y) whose value is equal to the intensity pValues[k] it would seem like nLevels-1 of values and nLevels of Levels would be appropriate I cant see how those two arrays should be the same length, given the need to index pLevels by k+1, but pValues by only k.

Thanks for any clarification that you can provide,
-todd

Todd Kelman, Engineering Consultant
Volcano Corporation
2870 Kilgore Rd.
Rancho Cordova, CA 95670
tkelman@volcanocorp.com

Hello Todd,

there is answer from our expert:

The manual states - "number of levels and values should be nLevels-1". But actually pLevels are boundaries so number of elements of pLevel must be nLevel.

May be short example will explain more clearly.

Ipp32s values[4], boundaries[5];
const Ipp32s* pVal[3], pLev[3];
int numblevel[3];

values[0] = 11; values[1] = 44; values[2] = 88; values[3] = 222;

boundaries[0] = 0; boundaries[1] = 30; boundaries[2] = 60; boundaries[3] = 120; boundaries[4] = 256;

pVal[0] = pVal[1<
FONT face="Arial CYR" color=#0000ff size=2>] = pVal[2] = values;
pLev[0] = pLev[1] = pLev[2] = boundaries;
numblevel[0] = numblevel[1] = numblevel[2] = 5;

rslt = ippiLUT_8u_C3R( p_mem, p_stepbyte, (Ipp8u*) thisimg->DataPtr(), thisimg->Step(), imgsz , pVal, pLev, numblevel);

In this example
if src value lies in [0; 30) than correspondend dst will have value 11;
if src value lies in [30; 60) than correspondend dst will have value 44;
if src value lies in [60; 120) than correspondend dst will have value 88;
if src value lies in [120; 256) than correspondend dst will have value 222;

We have 4 levels, 4 values but 5 boundaries

11 44 88 222
|------|------|------|------|
03060120256

Regards,
Vladimir

Leave a Comment

Please sign in to add a comment. Not a member? Join today