def window_image(img, window_center, window_width, intercept, slope):
    """
    Given a CT scan img apply a windowing to the image
    Arguments:
        img {np.array} -- array of a dicom img processed by pydicom.dcmread()
        window_center,window_width,intercept,slope {floats} -- values provided by dicom file metadata
    Attribution: This code comes from Richard McKinley's Kaggle kernel
    """
    img = (img * slope + intercept)
    img_min = window_center - window_width // 2
    img_max = window_center + window_width // 2
    img[img < img_min] = img_min
    img[img > img_max] = img_max
    return img