def rescale_intensity(image, in_range='image', out_range='dtype'):
 dtype = image.dtype.type
 (imin, imax) = intensity_range(image, in_range)
 (omin, omax) = intensity_range(image, out_range, clip_negative=(imin >= 0))
 image = np.clip(image, imin, imax)
 image = ((image - imin) / float((imax - imin)))
 return dtype(((image * (omax - omin)) + omin))

def rescale_intensity ( image , in_range = 'image' , out_range = 'dtype' ) : dtype = image . dtype . type ( imin , imax ) = intensity_range ( image , in_range ) ( omin , omax ) = intensity_range ( image , out_range , clip_negative = ( imin >= 0 ) ) image = np . clip ( image , imin , imax ) image = ( ( image - imin ) / float ( ( imax - imin ) ) ) return dtype ( ( ( image * ( omax - omin ) ) + omin ) )
return image after stretching or shrinking its intensity levels .