convert IPLImage to unsigned short [closed]
Hello,
I have converted an 8bit image from type IplImage to unsigned char as below :
unsigned char* pImageBuffer = (unsigned char*)malloc(sht*swd);
for (int j = 0; j < height; j++)
for (int i = 0; i < width; i++)
{
pImageBuffer[j*swd + i] = (unsigned char)(pGrayImage-mageData[j*pGrayImage->widthStep + i]);
}
Mat inputImg = Mat(height, width, CV_8UC1, pImageBuffer);
imwrite("E:\\Mat_inputImg_8bit.bmp", inputImg);
I got the 'inputImg' image same as the original one.
But when I tried same for 16bit image I am not getting 'inputImg' image the same as the original one.
unsigned short* pImageBuffer = (unsigned short*)malloc(sht*swd*sizeof(unsigned short));
for (int j = 0; j < sht; j++)
for (int i = 0; i < swd; i++)
{
pImageBuffer[j*swd + i] = (unsigned short)(pGrayImage->imageData[j*pGrayImage->widthStep + i]);
}
Mat inputImg = Mat(sht, swd, CV_16UC1, pImageBuffer);
imwrite("E:\\Mat_inputImg_16bit.png", inputImg);
please give me any suggestions.
opencv's c-api is deprecated, and will get removed entirely in the next major release, so please
DO NOT USE
IPLImage*
you have to use cv::Mat and the c++ api, like:
Thank you.