1,有个raw数据,它里面存储着灰度级别大于1024个的像素数据,我想了想除了自己转换成256级灰度外没办法显示出来,不知道有没有其他意见?2,这个raw数据是16位的,但是灰度级别只用到了10位,于是我用下面的办法转成256灰度后,显示的总是不好看,好像每个象素间都有个黑色像素,有的地方也有杂色的感觉,还不如本来就是个8位的raw数据。是我转换方法有误么?for (int i = 0, nHeight = m_nRawdataHeight, nWidth = 0; i<m_nRawdataHeight*m_nRawdataWidth*2; )
{
UINT uTe1 = (m_nRawdataBuffer[i++])<<8;
UINT uTe2 = m_nRawdataBuffer[i++];
UINT nColor = uTe1 + uTe2;
         //nColor是从raw数据中取到的一个像素点,16位
int  colorTemp = nColor*256/1023;
if(nWidth<=m_nRawdataWidth && nHeight<=m_nRawdataHeight)
{
            //SetPixelColor是把这个点转化成一个rgb颜色存到位图里,准备用来显示
   image.SetPixelColor(nWidth++, nHeight, RGB(colorTemp,colorTemp,colorTemp));
}
if (nWidth == m_nRawdataWidth)
{
nWidth = 0;
nHeight--;
}
}

解决方案 »

  1.   

    UINT uTe1 = (m_nRawdataBuffer[i++])<<8;
    UINT uTe2 = m_nRawdataBuffer[i++];
    这个BUF在没有用到的位上都置0了吗?
      

  2.   

    UINT uTe1 = m_nRawdataBuffer[i++];
    UINT uTe2 = (m_nRawdataBuffer[i++])<<8;
    UINT nColor = uTe1 + uTe2;
             //nColor是从raw数据中取到的一个像素点,16位
    int  colorTemp = nColor*256/1023;
    或:
    int  colorTemp = (*((short *)&m_nRawdataBuffer[i]))>>2;
    i+=2;
      

  3.   

    to thisisll,因为这个raw数据本来是m_nRawdataWidth * m_nRawdataHeight这么大,所以
    m_nRawdataBuffer = new unsigned char[m_nRawdataWidth * m_nRawdataHeight * 2];nRawCount = fileRaw.Read(m_nRawdataBuffer, m_nRawdataWidth * m_nRawdataHeight * 2);应该不存在没有用到的问题to Mr_Ldh(V1971.4),
    我那样写还能看到图像是个什么样子,如果按照你说的方法,根本没法看到图像了。
      

  4.   

    医学图像中经常会遇到灰度级别大于256的图像,在DICOM标准中有一个窗宽(Window Width)和窗位(Window Center)的概念,这两个变量决定了原始灰度级的显示范围。在医学图像中是这样处理楼主的问题的:
    if (x <= c - 0.5 - (w-1)/2), then y = ymin
    else if (x > c - 0.5 + (w-1)/2), then y = ymax,
    else y = ((x - (c - 0.5)) / (w-1) + 0.5) * (ymax - ymin)+ ymin
    c就是window center,代表了原始灰度取值范围的中值,w就是window width,代表原始灰度取值范围的宽度。
    For example, for an output range 0 to 255:
    c=2048, w=4096 becomes:
    if (x <= 0) then y = 0
    else if (x > 4095) then y = 255
    else y = ((x - 2047.5) / 4095 + 0.5) * (255-0) + 0
    c=2048, w=1 becomes:
    if (x <= 2047.5) then y = 0
    else if (x > 2047.5) then y = 255
    else /* not reached */
    c=0, w=100 becomes:
    if (x <= -50) then y = 0
    else if (x > 49) then y = 255
    else y = ((x + 0.5) / 99 + 0.5) * (255-0) + 0c=0, w=1 becomes:
    if (x <= -0.5) then y = 0
    else if (x > -0.5) then y = 255
    else /* not reached */
    说了这些,不知道对楼主可有启发。