2015年8月11日火曜日

GDCM 覚書2 YBR_FULL_422

GDCM memo 2

YBR_FULL_422の画像

string photometricInterpretation = ds.GetDataElement(new gdcm.Tag(0x00280004)).GetValue().toString();
byte* pBmpData = (byte*)_bmpData.Scan0;
if (photometricInterpretation == "YBR_FULL_422")
{
    fixed (byte* pData = _pixelData)
    {
        byte* ybr = pData;
        for (int y = 0; y < _rows; y++)
        {
            for (int x = 0; x < _columns; x++)
            {
                int Y = ybr[0] - 16;
                int Cb = ybr[1] - 128;
                int Cr = ybr[2] - 128;
                int r = ((298 * Y + 409 * Cr + 128) / 256);
                int g = ((298 * Y - 100 * Cb - 208 * Cr + 128) / 256);
                int b = ((298 * Y + 516 * Cb + 128) / 256);
                pBmpData[2] = (byte)(r < 0 ? 0 : (r > 255 ? 255 : r));
                pBmpData[1] = (byte)(g < 0 ? 0 : (g > 255 ? 255 : g));
                pBmpData[0] = (byte)(b < 0 ? 0 : (b > 255 ? 255 : b));
                pBmpData += 3;
                ybr += 3;
            }
            pBmpData += padding;
        }
    }
}

0 件のコメント :

コメントを投稿