Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

convert IPLImage to unsigned short

Hello,

I have converted an 8bit image from type IplImage to unsigned char as below :

unsigned char* pImageBuffer = (unsigned char)malloc(shtswd);

for (int j = 0; j < height; j++)
    for (int i = 0; i < width; i++)
    {
        pImageBuffer[j*swd + i] = (unsigned char)(pGrayImage->imageData[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(shtswd*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.

convert IPLImage to unsigned short

Hello,

I have converted an 8bit image from type IplImage to unsigned char as below :

unsigned char* pImageBuffer = (unsigned char)malloc(shtswd);

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->imageData[j*pGrayImage->widthStep char)(pGrayImage-mageData[j*pGrayImage->widthStep + i]);
 }

Mat inputImg = Mat(height, width, CV_8UC1, pImageBuffer);

imwrite("E:\Mat_inputImg_8bit.bmp", inputImg);

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(shtswd*sizeof(unsigned short));

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.