简体   繁体   English

使用Opencv加载12位Raw GreyScale图像

[英]Loading 12-Bit Raw GreyScale Image using Opencv

I'm working with opencv 2.4.9. 我正在使用opencv 2.4.9。 I would like to load a 12-Bit grey scale raw(.raw) image stored as Y16(16-Bit) format.This format contains only a single, 16 bit Y plane for monochrome images. 我想加载以Y16(16位)格式存储的12位灰度原始(.raw)图像。此格式仅包含用于单色图像的单个16位Y平面。 Each pixel is represented by a 16 bit, little endian format. 每个像素都由16位Little Endian格式表示。

I used the following code for loading the image. 我使用以下代码加载图像。

Mat Img_Source16Bit_Gray(m_ImgWidth,m_ImgHeight,CV_16UC1);
Mat Img_Destination8Bit_Gray;

FILE * f; 
f=fopen(FileName_S.c_str(),"rb");
if ( !f )
{
    MessageBox(L"File Not Found");
    return;
}
uchar* Pixels_Char_16Bit;
Pixels_Char_16Bit = new uchar[m_ImgWidth * m_ImgHeight *2];

fread(Pixels_Char_16Bit,m_ImgWidth * m_ImgHeight*2,1,f);
fclose(f);

Img_Source16Bit_Gray.data= Pixels_Char_16Bit;

Img_Source16Bit_Gray.convertTo(Img_Destination8Bit_Gray,CV_8UC1,1);

imshow("Img_Source16Bit_Gray",Img_Source16Bit_Gray);
imshow("Img_Destination8Bit_Gray",Img_Destination8Bit_Gray);

Actual image is shown in the right side & the output left hand side I'm getting is not correct & the Result8 bit image is full of white pixels. 实际图像显示在右侧,而我得到的输出左侧显示不正确,并且Result8位图像充满白色像素。 Can anyone please provide me the steps to load a 16 Bit grey scale image? 谁能为我提供加载16位灰度图像的步骤?

在此处输入图片说明

Thank you for helping me to find the answer! 感谢您帮助我找到答案! Here is my updated code. 这是我更新的代码。

Mat Img_Source16Bit_Gray(m_ImgHeight,m_ImgWidth,CV_16UC1);
Mat Img_Destination8Bit_Gray(m_ImgHeight,m_ImgWidth,CV_8UC1);

FILE * f; 
f=fopen(FileName_S.c_str(),"rb");
if ( !f )
{
    MessageBox(L"File Not Found");
    return;
}

char16_t* pY16Pixels;//w-2592 h- 1944
pY16Pixels = new char16_t[m_ImgWidth * m_ImgHeight];

fread(pY16Pixels,m_ImgWidth*m_ImgHeight*2,1,f);
Img_Source16Bit_Gray.data= reinterpret_cast<uchar*>(pY16Pixels);

double minVal, maxVal;
minMaxLoc(Img_Source16Bit_Gray, &minVal, &maxVal); //find minimum and maximum intensities
Img_Source16Bit_Gray.convertTo(Img_Destination8Bit_Gray, CV_8U, 255.0/(maxVal - minVal), -minVal * 255.0/(maxVal - minVal));

namedWindow("Img_Source16Bit_Gray",WINDOW_NORMAL);
namedWindow("Img_Destination8Bit_Gray",WINDOW_NORMAL);
imshow("Img_Source16Bit_Gray",Img_Source16Bit_Gray);
imshow("Img_Destination8Bit_Gray",Img_Destination8Bit_Gray);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM