Skip to content

Applying rescale slope and intercept in _dicom.py #348

Closed

Description

@krishnaanandk

Hello,

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:

                    # Unsigned integer type
                    if maxReq < 2**8:
                        dtype = np.int8
                    elif maxReq < 2**16:
                        dtype = np.int16
                    elif maxReq < 2**32:
                        dtype = np.int32
                    else:
                        dtype = np.float32

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.

Thanks
Krishna

Activity

  1. almarklein commented on May 25, 2018

    @almarklein
    Member

    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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions