Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Secondary capture image spatial metadata #167

Merged
merged 4 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions Source/MediaStorageAndFileFormat/gdcmImageHelper.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace gdcm
bool ImageHelper::ForceRescaleInterceptSlope = false;
bool ImageHelper::PMSRescaleInterceptSlope = true;
bool ImageHelper::ForcePixelSpacing = false;
bool ImageHelper::SecondaryCaptureImagePlaneModule = false;

static bool GetOriginValueFromSequence(const DataSet& ds, const Tag& tfgs, std::vector<double> &ori)
{
Expand Down Expand Up @@ -578,7 +579,7 @@ std::vector<double> ImageHelper::GetOriginValue(File const & f)

// else
const Tag timagepositionpatient(0x0020, 0x0032);
if( ms != MediaStorage::SecondaryCaptureImageStorage && ds.FindDataElement( timagepositionpatient ) )
if( (ms != MediaStorage::SecondaryCaptureImageStorage || SecondaryCaptureImagePlaneModule) && ds.FindDataElement( timagepositionpatient ) )
{
const DataElement& de = ds.GetDataElement( timagepositionpatient );
Attribute<0x0020,0x0032> at = {{0,0,0}}; // default value if empty
Expand Down Expand Up @@ -730,7 +731,7 @@ std::vector<double> ImageHelper::GetDirectionCosinesValue(File const & f)
}

dircos.resize( 6 );
if( ms == MediaStorage::SecondaryCaptureImageStorage || !GetDirectionCosinesFromDataSet(ds, dircos) )
if( (ms == MediaStorage::SecondaryCaptureImageStorage && !SecondaryCaptureImagePlaneModule) || !GetDirectionCosinesFromDataSet(ds, dircos) )
{
dircos[0] = 1;
dircos[1] = 0;
Expand Down Expand Up @@ -774,6 +775,16 @@ bool ImageHelper::GetForcePixelSpacing()
return ForcePixelSpacing;
}

void ImageHelper::SetSecondaryCaptureImagePlaneModule(bool b)
{
SecondaryCaptureImagePlaneModule = b;
}

bool ImageHelper::GetSecondaryCaptureImagePlaneModule()
{
return SecondaryCaptureImagePlaneModule;
}

bool GetRescaleInterceptSlopeValueFromDataSet(const DataSet& ds, std::vector<double> & interceptslope)
{
Attribute<0x0028,0x1052> at1;
Expand Down Expand Up @@ -1389,6 +1400,7 @@ std::vector<double> ImageHelper::GetSpacingValue(File const & f)
MediaStorage ms;
ms.SetFromFile(f);
const DataSet& ds = f.GetDataSet();
Tag spacingtag(0xffff,0xffff);

if( ms == MediaStorage::EnhancedCTImageStorage
|| ms == MediaStorage::EnhancedMRImageStorage
Expand Down Expand Up @@ -1451,8 +1463,24 @@ std::vector<double> ImageHelper::GetSpacingValue(File const & f)
return sp;
}
}
else if( ms == MediaStorage::SecondaryCaptureImageStorage )
{
if( ds.FindDataElement( Tag(0x0028,0x0030) ) )
{
// Type 1C in 'SC Image' (for calibrated images)
spacingtag = Tag(0x0028,0x0030);
}
else if( ds.FindDataElement( Tag(0x0018,0x2010) ) )
{
// Type 3 in 'SC Image'
spacingtag = Tag(0x0018,0x2010);
}
}
else
{
spacingtag = GetSpacingTagFromMediaStorage(ms);
}

Tag spacingtag = GetSpacingTagFromMediaStorage(ms);
malaterre marked this conversation as resolved.
Show resolved Hide resolved
if( spacingtag != Tag(0xffff,0xffff) && ds.FindDataElement( spacingtag ) && !ds.GetDataElement( spacingtag ).IsEmpty() )
{
const DataElement& de = ds.GetDataElement( spacingtag );
Expand Down
7 changes: 7 additions & 0 deletions Source/MediaStorageAndFileFormat/gdcmImageHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ class GDCM_EXPORT ImageHelper
static void SetForcePixelSpacing(bool);
static bool GetForcePixelSpacing();

/// Opt into Image Plane Module for Secondary Capture Image Storage
/// Enable reading Image Position Patient (IPP) and Image Orientation Patient (IOP)
/// for Secondary Capture Image Storage.
malaterre marked this conversation as resolved.
Show resolved Hide resolved
static void SetSecondaryCaptureImagePlaneModule(bool);
static bool GetSecondaryCaptureImagePlaneModule();

/// This function checks tags (0x0028, 0x0010) and (0x0028, 0x0011) for the
/// rows and columns of the image in pixels (as opposed to actual distances).
/// The output is {col , row}
Expand Down Expand Up @@ -156,6 +162,7 @@ class GDCM_EXPORT ImageHelper
static bool ForceRescaleInterceptSlope;
static bool PMSRescaleInterceptSlope;
static bool ForcePixelSpacing;
static bool SecondaryCaptureImagePlaneModule;
};

} // end namespace gdcm
Expand Down
Loading