From ba9fab5436ca65aaefca03995de855d05db4e85a Mon Sep 17 00:00:00 2001 From: bpinsard Date: Thu, 27 Sep 2012 10:13:09 +0200 Subject: [PATCH 1/2] attempt for RealWorldValueMapping rescale support in Wrapper --- nibabel/nicom/dicomwrappers.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/nibabel/nicom/dicomwrappers.py b/nibabel/nicom/dicomwrappers.py index 329a12b8c4..abd7b97bb3 100644 --- a/nibabel/nicom/dicomwrappers.py +++ b/nibabel/nicom/dicomwrappers.py @@ -356,6 +356,16 @@ def _scale_data(self, data): # depending on pydicom and dicom files, values might need casting from Decimal to float scale = float(self.get('RescaleSlope', 1)) offset = float(self.get('RescaleIntercept', 0)) + if scale == 1 and offset == 0: + mpseq = self.get('RealWorldValueMappingSequence',None) + if mpseq == None: # compatibility with pydicom < 0.9.7 ???? + mpseq = self.get('RealWorldValueMappings',None) + if mpseq != None and len(mpseq)>0: + mpseq = mpseq[0] + if mpseq.has_key('RealWorldValueSlope'): + scale = mpseq.RealWorldValueSlope + if mpseq.has_key('RealWorldValueIntercept'): + offset = mpseq.RealWorldValueIntercept # a little optimization. If we are applying either the scale or # the offset, we need to allow upcasting to float. if scale != 1: From 242ae838988e8d5a53f74c473c75df0a0129c686 Mon Sep 17 00:00:00 2001 From: bpinsard Date: Tue, 26 Mar 2013 15:32:17 +0100 Subject: [PATCH 2/2] has_key not working???, workaround --- nibabel/nicom/dicomwrappers.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/nibabel/nicom/dicomwrappers.py b/nibabel/nicom/dicomwrappers.py index abd7b97bb3..505d8446e5 100644 --- a/nibabel/nicom/dicomwrappers.py +++ b/nibabel/nicom/dicomwrappers.py @@ -362,10 +362,8 @@ def _scale_data(self, data): mpseq = self.get('RealWorldValueMappings',None) if mpseq != None and len(mpseq)>0: mpseq = mpseq[0] - if mpseq.has_key('RealWorldValueSlope'): - scale = mpseq.RealWorldValueSlope - if mpseq.has_key('RealWorldValueIntercept'): - offset = mpseq.RealWorldValueIntercept + scale = mpseq.get('RealWorldValueSlope',1) + offset = mpseq.get('RealWorldValueIntercept',0) # a little optimization. If we are applying either the scale or # the offset, we need to allow upcasting to float. if scale != 1: