有没有办法显示一个灰度级别大于256的图。

yoogle 2006-05-15 10:26:15

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--;
}
}
...全文
259 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
thisisll 2006-05-15
  • 打赏
  • 举报
回复
那你还是跟跟看看数据有什么问题吧
单看代码没看出什么问题
yoogle 2006-05-15
  • 打赏
  • 举报
回复
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),
我那样写还能看到图像是个什么样子,如果按照你说的方法,根本没法看到图像了。
Mr_Ldh 2006-05-15
  • 打赏
  • 举报
回复
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;
thisisll 2006-05-15
  • 打赏
  • 举报
回复
UINT uTe1 = (m_nRawdataBuffer[i++])<<8;
UINT uTe2 = m_nRawdataBuffer[i++];
这个BUF在没有用到的位上都置0了吗?

yoogle 2006-05-15
  • 打赏
  • 举报
回复
是的,楼上对我的启发是我的做法应该是对的,到该跟客户沟通一下的时候了。
tjuzhangrui 2006-05-15
  • 打赏
  • 举报
回复
医学图像中经常会遇到灰度级别大于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) + 0

c=0, w=1 becomes:
if (x <= -0.5) then y = 0
else if (x > -0.5) then y = 255
else /* not reached */


说了这些,不知道对楼主可有启发。

19,469

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧