Serialized/helper/myio.py
def dcm_window(dcm,pixel_array,window = None):
    '''
    return a windowed image.
    if now window is provided, use the DICOM first window data
    if window length ==3, use window data
    '''
    ymin=0
    ymax=255
    if window is None:
        c = int(dcm.WindowCenter[0] if type(dcm.WindowCenter) == pydicom.multival.MultiValue else dcm.WindowCenter)
        w = int(dcm.WindowWidth[0] if type(dcm.WindowWidth) == pydicom.multival.MultiValue else dcm.WindowWidth)
    else:
        c , w = window
    b = dcm.RescaleIntercept
    m = dcm.RescaleSlope
    x = m * pixel_array + b
    # windowing C.11.2.1.2.1 Default LINEAR Function
    y = np.zeros_like(x)
    y[x <= (c - 0.5 - (w - 1) / 2)] = ymin
#        ymin + np.tanh(((x[x <= (c - 0.5 - (w - 1) / 2)] - (c - 0.5)) / (w - 1) + 0.5))* (ymax - ymin)  
    y[x > (c - 0.5 + (w - 1) / 2)] = ymax
#        ymax + np.tanh(((x[x > (c - 0.5 + (w - 1) / 2)] - (c - 0.5)) / (w - 1) + 0.5))* (ymax - ymin)   
    y[(x > (c - 0.5 - (w - 1) / 2)) & (x <= (c - 0.5 + (w - 1) / 2))] = \
      ((x[(x > (c - 0.5 - (w - 1) / 2)) & (x <= (c - 0.5 + (w - 1) / 2))] - (c - 0.5)) / (w - 1) + 0.5) * (ymax - ymin) + ymin
#    y = ((x - (c - 0.5)) / (w - 1) + 0.5) * (ymax - ymin) + ymin
    return y/255.0

    return a windowed image.
    if now window is provided, use the DICOM first window data
    if window length ==3, use window data
    
return a windowed image.
if now window is provided, use the DICOM first window data
if window length ==3, use window data
return a windowed image . if now window is provided use the DICOM first window data if window length == 3 use window data
def dcm_window(dcm,pixel_array,window = None):
    ymin=0
    ymax=255
    if window is None:
        c = int(dcm.WindowCenter[0] if type(dcm.WindowCenter) == pydicom.multival.MultiValue else dcm.WindowCenter)
        w = int(dcm.WindowWidth[0] if type(dcm.WindowWidth) == pydicom.multival.MultiValue else dcm.WindowWidth)
    else:
        c , w = window
    b = dcm.RescaleIntercept
    m = dcm.RescaleSlope
    x = m * pixel_array + b
    y = np.zeros_like(x)
    y[x <= (c - 0.5 - (w - 1) / 2)] = ymin
    y[x > (c - 0.5 + (w - 1) / 2)] = ymax
    y[(x > (c - 0.5 - (w - 1) / 2)) & (x <= (c - 0.5 + (w - 1) / 2))] = \
      ((x[(x > (c - 0.5 - (w - 1) / 2)) & (x <= (c - 0.5 + (w - 1) / 2))] - (c - 0.5)) / (w - 1) + 0.5) * (ymax - ymin) + ymin
    return y/255.0
def dcm_window ( dcm , pixel_array , window = None ) : ymin = 0 ymax = 255 if window is None : c = int ( dcm . WindowCenter [ 0 ] if type ( dcm . WindowCenter ) == pydicom . multival . MultiValue else dcm . WindowCenter ) w = int ( dcm . WindowWidth [ 0 ] if type ( dcm . WindowWidth ) == pydicom . multival . MultiValue else dcm . WindowWidth ) else : c , w = window b = dcm . RescaleIntercept m = dcm . RescaleSlope x = m * pixel_array + b y = np . zeros_like ( x ) y [ x <= ( c - 0.5 - ( w - 1 ) / 2 ) ] = ymin y [ x > ( c - 0.5 + ( w - 1 ) / 2 ) ] = ymax y [ ( x > ( c - 0.5 - ( w - 1 ) / 2 ) ) & ( x <= ( c - 0.5 + ( w - 1 ) / 2 ) ) ] = ( ( x [ ( x > ( c - 0.5 - ( w - 1 ) / 2 ) ) & ( x <= ( c - 0.5 + ( w - 1 ) / 2 ) ) ] - ( c - 0.5 ) ) / ( w - 1 ) + 0.5 ) * ( ymax - ymin ) + ymin return y / 255.0
return a windowed image.
return a windowed image .
'''
    return a windowed image.
    if now window is provided, use the DICOM first window data
    if window length ==3, use window data
    ''' # windowing C.11.2.1.2.1 Default LINEAR Function #        ymin + np.tanh(((x[x <= (c - 0.5 - (w - 1) / 2)] - (c - 0.5)) / (w - 1) + 0.5))* (ymax - ymin)   #        ymax + np.tanh(((x[x > (c - 0.5 + (w - 1) / 2)] - (c - 0.5)) / (w - 1) + 0.5))* (ymax - ymin)    #    y = ((x - (c - 0.5)) / (w - 1) + 0.5) * (ymax - ymin) + ymin
dcm
pixel_array
window