DCMTK学习之利用RGB进行图像的输出时,图像反向的问题

来源:互联网 发布:怎么注册企业淘宝店铺 编辑:程序博客网 时间:2024/05/20 17:07

 前言

还是自己太年轻哦,代码明明写的时反向输出RGB文件,自己却要正向输出RGB信息,结果出问题了撒!!!/抓狂

具体表现以及原因

//代码是这样的//斜率        float fRescaleSlope = atoi(strRescaleSlope.c_str());        //截距        float fRescaleIntercept = atoi(strRescaleIntercept.c_str());        for(int temp = 0; temp < nCount; temp ++)        {            //使用的是公式Units = m*SV + b,m是斜率,b是截距,,,计算CT值            float CT_Value = (float)(pixdata[temp] * fRescaleSlope + fRescaleIntercept);            //正常的CT值在范围[nWindowCenter - nWindowWidth/2,  nWindowCenter + nWindowWidth/2]             //低于这个值的显示黑色,高于这个的显示白色            if(CT_Value < nWindowCenter - nWindowWidth/2)            {                pRgbData[temp] = 0;            }            else if (CT_Value > nWindowCenter + nWindowWidth/2)            {                pRgbData[temp] = 255;  // 也就是#ff            }            else            {                double value = (CT_Value + nWindowWidth/2.0f - nWindowCenter) * 255.0f / nWindowWidth;                if(value < 0) pRgbData[temp] = 0;                else if(value > 255) pRgbData[temp] = 255;                else pRgbData[temp] = pixdata[temp];            }        }//后面具体生成的代码就不显示出来了,我可以上传附件

表现就是:
这里写图片描述

然而这才是正常的图片(好像不大对哦,我用看图工具直接反向转的)
这里写图片描述

也就是某个人的头部的CT图像,应该认识哦!

出现这种情况的原因,是因为.bmp图,系统默认是从下往上,从左到右进行读取的,如果你直接按照源图像的顺训写入到bmp文件里面,写入的顺序是正确的,但是由于操作系统是反向读取bmp文件,所以呈现出来的是反向的图片;解决这个问题的办法只能是将图像信息反向存入到bmp文件中,这样系统读取的图像就是正向的。(抱歉之前误导大家,查过资料后才知道自己错的多么的离谱)

for(int y = 0, p_y = nHeight - 1; y < nHeight; y ++, p_y --)        {            for(int x = 0; x < nWidth; x ++)            {                int PT_x = p_y * nWidth * 4 + x * 4;                int RGB_x = y * nWidth + x;                pTemp[PT_x + 0] = pRgbData[RGB_x];    // B                pTemp[PT_x + 1] = pRgbData[RGB_x];    // G                pTemp[PT_x + 2] = pRgbData[RGB_x];    // R                pTemp[PT_x + 3] = 255;                // A            }        }

这里写图片描述

原创粉丝点击