You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Applying rescale slope and intercept in _dicom.py #348
I am trying to understand the code in the _apply_slope_and_offset() function in _dicom.py. Any comments or documents on the various things being done in the function would be very helpful for a newcomer (in particular, starting from line 520: # Determine required range).
I have a specific question about determining the data type in the following piece of code starting from line 540: else:
I see that the piece of code is trying to get the right data type for the numpy array. But the part that is confusing to me is the unsigned part. Here the code checks the ranges and assigns the data type. But why is the data type "np.int8" and not "np.uint8"? I might be missing something here. Any explanation or comments would be helpful for a newcomer like me.
I just studied that code a bit. It seems to me that this is a bug/typo. The code is a bit odd at least.
As it is now the minReq and maxReq seem to include the current data range as well as the range after applying slope/offset. The dtype is determed to thus fit both ranges, then the data array is cast to this dtype, and then the scale/offset are applied.
I think it makes more sense to determine the dtype for the final range (after applying scale/offset), cast the data to float, apply scale/offset, and then cast to the final dtype.
Imageio could use someone taking some care to the dicom plugin (I don't use it a lot myself anymore). Would you be interested in creating a pull request for this issue? I'd off course help (with the process of creating a PR, as well as the code, as needed).
Activity
almarklein commentedon May 25, 2018
I just studied that code a bit. It seems to me that this is a bug/typo. The code is a bit odd at least.
As it is now the
minReqandmaxReqseem to include the current data range as well as the range after applying slope/offset. The dtype is determed to thus fit both ranges, then the data array is cast to this dtype, and then the scale/offset are applied.I think it makes more sense to determine the dtype for the final range (after applying scale/offset), cast the data to float, apply scale/offset, and then cast to the final dtype.
Imageio could use someone taking some care to the dicom plugin (I don't use it a lot myself anymore). Would you be interested in creating a pull request for this issue? I'd off course help (with the process of creating a PR, as well as the code, as needed).