X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmHeaderHelper.cxx;h=0898ed5d945f05a47b33dee7bbc5ad709e57fe92;hb=659604feaaaf9519d03d59d66711f6b4b8290804;hp=c6957de06f98114bf5b70d610feb55f90c76b7c2;hpb=a18a9f20d96301e1c91be637415599e5fdc1ca43;p=gdcm.git diff --git a/src/gdcmHeaderHelper.cxx b/src/gdcmHeaderHelper.cxx index c6957de0..0898ed5d 100644 --- a/src/gdcmHeaderHelper.cxx +++ b/src/gdcmHeaderHelper.cxx @@ -1,11 +1,11 @@ -// $Header: /cvs/public/gdcm/src/Attic/gdcmHeaderHelper.cxx,v 1.11 2003/10/03 15:27:44 malaterre Exp $ +// $Header: /cvs/public/gdcm/src/Attic/gdcmHeaderHelper.cxx,v 1.17 2003/11/12 14:06:35 malaterre Exp $ #include "gdcmHeaderHelper.h" #include "gdcmUtil.h" //for debug #include #include -#include //for bzero +//#include //for bzero //directory manipulation (os indep). //cygwin ???? -> _WIN32 ?? @@ -79,6 +79,12 @@ gdcmHeaderHelper::gdcmHeaderHelper(const char *InFilename, * */ int gdcmHeaderHelper::GetPixelSize() { + + // 0028 0100 US IMG Bits Allocated + // (in order no to be messed up by old RGB images) + if (gdcmHeader::GetPubElValByNumber(0x0028,0x0100) == "24") + return 3; + std::string PixelType = GetPixelType(); if (PixelType == "8U" || PixelType == "8S") return 1; @@ -93,24 +99,65 @@ int gdcmHeaderHelper::GetPixelSize() { //---------------------------------------------------------------------------- /** * \ingroup gdcmHeaderHelper - * \brief gets the info from 0028,0004 : Photometric Interp - * \ else 1. - * @return 1 if Gray level, 3 if Color + * \brief This function is intended to user who doesn't whan + * \ to have to manage a LUT and expects to get an RBG Pixel image + * \ (or a monochrome one ...) + * \warning to be used with GetImagePixels() + * @return 1 if Gray level, 3 if Color (RGB, YBR or PALETTE COLOR) */ int gdcmHeaderHelper::GetNumberOfScalarComponents() { - std::string PhotometricInterpretation = - gdcmHeader::GetPubElValByNumber(0x0028,0x0004); - -// The compiler will optimze, if it feels like ! + if (GetSamplesPerPixel() ==3) + return 3; + + // 0028 0100 US IMG Bits Allocated + // (in order no to be messed up by old RGB images) + if (gdcmHeader::GetPubElValByNumber(0x0028,0x0100) == "24") + return 3; + + std::string PhotometricInterpretation = + gdcmHeader::GetPubElValByNumber(0x0028,0x0004); - //beware of trailing space at end of string - if (PhotometricInterpretation.find(GDCM_UNFOUND) < PhotometricInterpretation.length() || - PhotometricInterpretation.find("MONOCHROME1") < PhotometricInterpretation.length() || - PhotometricInterpretation.find("MONOCHROME2") < PhotometricInterpretation.length() ) return 1; + if ( ( PhotometricInterpretation == "PALETTE COLOR ") ) { + if (HasLUT()) // PALETTE COLOR is NOT enough + return 3; + else + return 1; + } + + //beware of trailing space at end of string + if (PhotometricInterpretation.find(GDCM_UNFOUND) < + PhotometricInterpretation.length() || + PhotometricInterpretation.find("MONOCHROME1") < + PhotometricInterpretation.length() || + PhotometricInterpretation.find("MONOCHROME2") < + PhotometricInterpretation.length() ) + return 1; + else + // we assume that *all* kinds of YBR are dealt with + return 3; +} +//---------------------------------------------------------------------------- +/** + * \ingroup gdcmHeaderHelper + * \brief This function is intended to user that DOESN'T want + * \to get RGB pixels image when it's stored as a PALETTE COLOR image + * \ - the (vtk) user is supposed to know how deal with LUTs - + * \warning to be used with GetImagePixelsRaw() + * @return 1 if Gray level, 3 if Color (RGB or YBR - NOT 'PALETTE COLOR' -) + */ +int gdcmHeaderHelper::GetNumberOfScalarComponentsRaw() { + + // 0028 0100 US IMG Bits Allocated + // (in order no to be messed up by old RGB images) + if (gdcmHeader::GetPubElValByNumber(0x0028,0x0100) == "24") return 3; + + // we assume that *all* kinds of YBR are dealt with + return GetSamplesPerPixel(); } + //---------------------------------------------------------------------------- /** * \ingroup gdcmHeaderHelper @@ -123,6 +170,7 @@ int gdcmHeaderHelper::GetNumberOfScalarComponents() { * - 32U unsigned 32 bit, * - 32S signed 32 bit, * \warning 12 bit images appear as 16 bit. + * \ 24 bit images appear as 8 bit * @return */ std::string gdcmHeaderHelper::GetPixelType() { @@ -132,9 +180,11 @@ std::string gdcmHeaderHelper::GetPixelType() { dbg.Verbose(0, "gdcmHeader::GetPixelType: unfound Bits Allocated"); BitsAlloc = std::string("16"); } - if (BitsAlloc == "12") + if (BitsAlloc == "12") // It will be unpacked BitsAlloc = std::string("16"); - + else if (BitsAlloc == "24") // (in order no to be messed up + BitsAlloc = std::string("8"); // by old RGB images) + std::string Signed; Signed = GetElValByName("Pixel Representation"); if (Signed == GDCM_UNFOUND) { @@ -158,15 +208,19 @@ std::string gdcmHeaderHelper::GetPixelType() { float gdcmHeaderHelper::GetXSpacing() { float xspacing, yspacing; std::string StrSpacing = GetPubElValByNumber(0x0028,0x0030); - - if (StrSpacing == GDCM_UNFOUND) { - dbg.Verbose(0, "gdcmHeader::GetXSpacing: unfound Pixel Spacing (0028,0030)"); - return 1.; - } - if( sscanf( StrSpacing.c_str(), "%f\\%f", &xspacing, &yspacing) != 2) - return 0.; - //else - return xspacing; + + if (StrSpacing == GDCM_UNFOUND) { + dbg.Verbose(0, "gdcmHeader::GetXSpacing: unfound Pixel Spacing (0028,0030)"); + return 1.; + } + if( sscanf( StrSpacing.c_str(), "%f\\%f", &yspacing, &xspacing) != 2) + return 0.; + if (xspacing == 0.) { + dbg.Verbose(0, "gdcmHeader::GetYSpacing: gdcmData/CT-MONO2-8-abdo.dcm problem"); + // seems to be a bug in the header ... + sscanf( StrSpacing.c_str(), "%f\\0\\%f", &yspacing, &xspacing); + } + return xspacing; } //---------------------------------------------------------------------------- /** @@ -183,12 +237,12 @@ float gdcmHeaderHelper::GetYSpacing() { dbg.Verbose(0, "gdcmHeader::GetYSpacing: unfound Pixel Spacing (0028,0030)"); return 1.; } - if( sscanf( StrSpacing.c_str(), "%f\\%f", &xspacing, &yspacing) != 2) + if( sscanf( StrSpacing.c_str(), "%f\\%f", &yspacing, &xspacing) != 2) return 0.; - if (yspacing == 0.) { + if (xspacing == 0.) { dbg.Verbose(0, "gdcmHeader::GetYSpacing: gdcmData/CT-MONO2-8-abdo.dcm problem"); // seems to be a bug in the header ... - sscanf( StrSpacing.c_str(), "%f\\0\\%f", &xspacing, &yspacing); + sscanf( StrSpacing.c_str(), "%f\\0\\%f", &yspacing, &xspacing); } return yspacing; } @@ -443,6 +497,32 @@ std::string gdcmHeaderHelper::GetInstanceUID() { return GetPubElValByNumber(0x0008,0x0018); //0008 0018 UI ID SOP Instance UID } +//---------------------------------------------------------------------------- +float gdcmHeaderHelper::GetRescaleIntercept() +{ + float resInter = 0.; + std::string StrRescInter = GetPubElValByNumber(0x0028,0x1052); //0028 1052 DS IMG Rescale Intercept + if (StrRescInter != GDCM_UNFOUND) { + if( sscanf( StrRescInter.c_str(), "%f", &resInter) != 1) { + dbg.Verbose(0, "gdcmHeader::GetRescaleIntercept: Rescale Slope is empty"); + // bug in the element 0x0028,0x1052 + } + } + return resInter; +} +//---------------------------------------------------------------------------- +float gdcmHeaderHelper::GetRescaleSlope() +{ + float resSlope = 1.; + std::string StrRescSlope = GetPubElValByNumber(0x0028,0x1053); //0028 1053 DS IMG Rescale Slope + if (StrRescSlope != GDCM_UNFOUND) { + if( sscanf( StrRescSlope.c_str(), "%f", &resSlope) != 1) { + dbg.Verbose(0, "gdcmHeader::GetRescaleSlope: Rescale Slope is empty"); + // bug in the element 0x0028,0x1053 + } + } + return resSlope; +}