converting 16 bit signed to 8 bit unsigned problem

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

converting 16 bit signed to 8 bit unsigned problem

Ed Elston
I'm have a struggle with converting my 16 bit signed data to a format
that I can display.  Can someone help?  This is the code . . .

IplImage *pImg = cvCreateImage(cvSize(rows, cols), IPL_DEPTH_16S, 3);
memcpy(pImg->imageData, m_clsDP300.GetImageData(DP300TYPE_Z), iSize);
IplImage *pImg8B = cvCreateImage(cvSize(rows, cols), IPL_DEPTH_8U, 3);
cvConvertScale(pImg, pImg8Bit, 1/256, 0);

The data is range information, never negative so should be unsigned
but it isn't.  Is there something wrong?

Ed

Reply | Threaded
Open this post in threaded view
|

Re: converting 16 bit signed to 8 bit unsigned problem

Peter Eisenlohr
Ed Elston schrieb:
> I'm have a struggle with converting my 16 bit signed data to a format
> that I can display. Can someone help? This is the code . . .
>
> IplImage *pImg = cvCreateImage(cvSize(rows, cols), IPL_DEPTH_16S, 3);
> memcpy(pImg->imageData, m_clsDP300.GetImageData(DP300TYPE_Z), iSize);
> IplImage *pImg8B = cvCreateImage(cvSize(rows, cols), IPL_DEPTH_8U, 3);
> cvConvertScale(pImg, pImg8Bit, 1/256, 0);

Change "1/256" to "1.0/256" and it should work. You are doing an integer
division here, which results in the value 0.

  Peter
Reply | Threaded
Open this post in threaded view
|

Re: converting 16 bit signed to 8 bit unsigned problem

Ed Elston
Oops, I see it now.  Thanks for the correction in my foolish
mistake.  I was searching for the wrong problem.

Ed

--- In [hidden email], Peter Eisenlohr <p.eisenlohr@...>
wrote:
>
> Ed Elston schrieb:
> > I'm have a struggle with converting my 16 bit signed data to a
format
> > that I can display. Can someone help? This is the code . . .
> >
> > IplImage *pImg = cvCreateImage(cvSize(rows, cols),
IPL_DEPTH_16S, 3);
> > memcpy(pImg->imageData, m_clsDP300.GetImageData(DP300TYPE_Z),
iSize);
> > IplImage *pImg8B = cvCreateImage(cvSize(rows, cols),
IPL_DEPTH_8U, 3);
> > cvConvertScale(pImg, pImg8Bit, 1/256, 0);
>
> Change "1/256" to "1.0/256" and it should work. You are doing an
integer
> division here, which results in the value 0.
>
>   Peter
>