cytometer/utils.py
def rescale_intensity(im, ignore_value=None):
    """
    Stretch the pixel intensities of a batch of images to cover the whole dynamic range of the dtype,
    excluding the black background pixels.

    The scaling is performed on the H-channel of the HSV transform of the RGB image.

    :param im: np.ndarray (batch, rows, cols, channel) RGB images.
    :param ignore_value: (def None). Once the image is converted from RGB to HSV, pixels with
    V=ignore_value will be ignored for the intensity scaling. This is useful e.g. when a regular image
    has areas that have been blacked out, and we want to scale the non-blacked-out intensities.
    :return: Array with the same size as im.
    """

    # indices for hue, saturation, value
    # H = 0
    # S = 1
    V = 2

    # loop images
    for i in range(im.shape[0]):

        if DEBUG:
            plt.clf()
            plt.imshow(im[i, :, :, :])

        # convert to Hue, Saturation, Value format
        im_hsv = rgb2hsv(im[i, :, :, :])

        # pixels that are not black background
        im_v = im_hsv[:, :, V]
        if ignore_value is None:
            im_v = minmax_scale(im_v, feature_range=(0.0, 1.0))
        else:
            # scale intensities of non-background area
            idx = im_v != ignore_value
            im_v[idx] = minmax_scale(im_v[idx], feature_range=(0.0, 1.0))

        # convert back to RGB
        im_hsv[:, :, V] = im_v
        im[i, :, :, :] = hsv2rgb(im_hsv)

        if DEBUG:
            plt.clf()
            plt.imshow(im[i, :, :, :])

            plt.clf()
            plt.hist(im[i, :, :, :].flatten())

    return im

    Stretch the pixel intensities of a batch of images to cover the whole dynamic range of the dtype,
    excluding the black background pixels.

    The scaling is performed on the H-channel of the HSV transform of the RGB image.

    :param im: np.ndarray (batch, rows, cols, channel) RGB images.
    :param ignore_value: (def None). Once the image is converted from RGB to HSV, pixels with
    V=ignore_value will be ignored for the intensity scaling. This is useful e.g. when a regular image
    has areas that have been blacked out, and we want to scale the non-blacked-out intensities.
    :return: Array with the same size as im.
    
Stretch the pixel intensities of a batch of images to cover the whole dynamic range of the dtype,
excluding the black background pixels.

The scaling is performed on the H-channel of the HSV transform of the RGB image.
Stretch the pixel intensities of a batch of images to cover the whole dynamic range of the dtype excluding the black background pixels . The scaling is performed on the H - channel of the HSV transform of the RGB image .
def rescale_intensity(im, ignore_value=None):
    V = 2
    for i in range(im.shape[0]):
        if DEBUG:
            plt.clf()
            plt.imshow(im[i, :, :, :])
        im_hsv = rgb2hsv(im[i, :, :, :])
        im_v = im_hsv[:, :, V]
        if ignore_value is None:
            im_v = minmax_scale(im_v, feature_range=(0.0, 1.0))
        else:
            idx = im_v != ignore_value
            im_v[idx] = minmax_scale(im_v[idx], feature_range=(0.0, 1.0))
        im_hsv[:, :, V] = im_v
        im[i, :, :, :] = hsv2rgb(im_hsv)
        if DEBUG:
            plt.clf()
            plt.imshow(im[i, :, :, :])
            plt.clf()
            plt.hist(im[i, :, :, :].flatten())
    return im
def rescale_intensity ( im , ignore_value = None ) : V = 2 for i in range ( im . shape [ 0 ] ) : if DEBUG : plt . clf ( ) plt . imshow ( im [ i , : , : , : ] ) im_hsv = rgb2hsv ( im [ i , : , : , : ] ) im_v = im_hsv [ : , : , V ] if ignore_value is None : im_v = minmax_scale ( im_v , feature_range = ( 0.0 , 1.0 ) ) else : idx = im_v != ignore_value im_v [ idx ] = minmax_scale ( im_v [ idx ] , feature_range = ( 0.0 , 1.0 ) ) im_hsv [ : , : , V ] = im_v im [ i , : , : , : ] = hsv2rgb ( im_hsv ) if DEBUG : plt . clf ( ) plt . imshow ( im [ i , : , : , : ] ) plt . clf ( ) plt . hist ( im [ i , : , : , : ] . flatten ( ) ) return im
Stretch the pixel intensities of a batch of images to cover the whole dynamic range of the dtype,
excluding the black background pixels.
Stretch the pixel intensities of a batch of images to cover the whole dynamic range of the dtype excluding the black background pixels .
"""
    Stretch the pixel intensities of a batch of images to cover the whole dynamic range of the dtype,
    excluding the black background pixels.

    The scaling is performed on the H-channel of the HSV transform of the RGB image.

    :param im: np.ndarray (batch, rows, cols, channel) RGB images.
    :param ignore_value: (def None). Once the image is converted from RGB to HSV, pixels with
    V=ignore_value will be ignored for the intensity scaling. This is useful e.g. when a regular image
    has areas that have been blacked out, and we want to scale the non-blacked-out intensities.
    :return: Array with the same size as im.
    """ # indices for hue, saturation, value # H = 0 # S = 1 # loop images # convert to Hue, Saturation, Value format # pixels that are not black background # scale intensities of non-background area # convert back to RGB
Array with the same size as im.
Array with the same size as im .
im
np.ndarray (batch, rows, cols, channel) RGB images.
np . ndarray ( batch rows cols channel ) RGB images .
ignore_value
(def None). Once the image is converted from RGB to HSV, pixels with
V=ignore_value will be ignored for the intensity scaling. This is useful e.g. when a regular image
has areas that have been blacked out, and we want to scale the non-blacked-out intensities.
( def None ) . Once the image is converted from RGB to HSV pixels with V = ignore_value will be ignored for the intensity scaling . This is useful e . g . when a regular image has areas that have been blacked out and we want to scale the non - blacked - out intensities .