示例#1
0
def gaussian_noising(np_org_image, std_dev=0.05, mean=0, number_of_inters=1):
    """Applying gaussian noise on a given image with specified standar deviation and mean parameters

    Arguments:
        np_org_image {NumPy array} -- image for median filtering

    Keyword Arguments:
        std_dev {float} -- standard deviation of gaussian noise (default: {0.05})
        mean {int} --mean of gaussian noise (default: {0})
        number_of_inters {int} -- number of inter images generated by this function (minimum/default: {1})

    Returns:
         [list of NumPy arrays] -- list containing original image, specified number of inter images and final image
    """
    #arguments validation
    bs.validate_number_of_inters(number_of_inters,
                                 gaussian_noising.__defaults__[-1])

    images = []
    images.append(np_org_image)
    np_image_3D, isConverted = bs.ensure3D(np_org_image)

    np_final = ns.gaussianNoise(np_image_3D, std_dev, mean)

    if isConverted:
        np_final = np_final.reshape(np_final.shape[:2])

    images += bs.generateInterImages(images[-1], np_final, number_of_inters)
    return images
示例#2
0
def salt_pepper_noising(np_org_image,
                        propability=0.05,
                        saltPepperRatio=0.5,
                        number_of_inters=1):
    """Applying salt(white pixel)/pepper(black pixel) noise on a given image
    Arguments:
        np_org_image {NumPy array} -- image for median filtering

    Keyword Arguments:
        propability {float} -- propability of noising a single pixel (default: {0.05})
        saltPepperRatio {float} -- specified salt to pepper ratio (default: {0.5})
                1.0 -- only salt
                0.5 -- equal propability of salt and pepper
                0.0 -- only pepper

         number_of_inters {int} -- number of inter images generated by this function (minimum/default: {1})

    Returns:
        [list of NumPy arrays] -- list containing original image, specified number of inter images and final image
    """
    #arguments validation
    bs.validate_number_of_inters(number_of_inters,
                                 salt_pepper_noising.__defaults__[-1])

    images = []
    images.append(np_org_image)
    np_final = ns.saltPepperNoising(np_org_image, propability, saltPepperRatio)

    images += bs.generateInterImages(images[-1], np_final, number_of_inters)
    return images
示例#3
0
def gamma_correction(np_org_image, gamma, number_of_inters=1):
    """Gamma correction on given image using specified gamma coefficient

    Arguments:
        np_org_image {NumPy array} -- image for median filtering
        gamma {[float]} -- gamma coefficient. Should be greater than 0

    Keyword Arguments:
        number_of_inters {int} -- number of inter images generated by this function (minimum/default: {1})

    Returns:
        [list of NumPy arrays] -- list containing original image, specified number of inter images and final image
    """

    #arguments validation
    bs.validate_number_of_inters(number_of_inters,
                                 gamma_correction.__defaults__[-1])

    images = []
    images.append(np_org_image)
    np_final = np.empty(np_org_image.shape, dtype=np.uint8)

    if bs.isColorImage(np_org_image):
        np_final[:, :, 0] = fil.gammaCorrection(np_org_image[:, :, 0], gamma)
        np_final[:, :, 1] = fil.gammaCorrection(np_org_image[:, :, 1], gamma)
        np_final[:, :, 2] = fil.gammaCorrection(np_org_image[:, :, 2], gamma)
    else:
        np_final = fil.gammaCorrection(np_org_image, gamma)

    images += bs.generateInterImages(images[-1], np_final, number_of_inters)
    return images
示例#4
0
def filtering(np_org_image, np_mask, number_of_inters=1):
    """Filtering on a given image using specified mask.

    Arguments:
        np_org_image {NumPy array} -- image for filtering
        np_mask {[NumPy array]} -- filter mask. You could pass your own or use one from the predefinied:
            np_LP1-4 - low pass filter masks, where 1 means filter with the "strongest" low pass effect (size: {3x3})
            np_HP1-4 - high pass filter masks, where 1 means filter with the "strongest" high pass effect (size: {3x3})

    Keyword Arguments:
        number_of_inters {int} -- number of inter images generated by this function (minimum/default: {1})

    Returns:
         [list of NumPy arrays] -- list containing original image, specified number of inter images and final image
    """
    #arguments validation
    bs.validate_number_of_inters(number_of_inters, filtering.__defaults__[-1])

    images = []
    images.append(np_org_image)
    np_final = np.empty(np_org_image.shape, dtype=np.uint8)

    if bs.isColorImage(np_org_image):
        np_final[:, :, 0] = fil.matrixFilter(np_org_image[:, :, 0], np_mask)
        np_final[:, :, 1] = fil.matrixFilter(np_org_image[:, :, 1], np_mask)
        np_final[:, :, 2] = fil.matrixFilter(np_org_image[:, :, 2], np_mask)
    else:
        np_final = fil.matrixFilter(np_org_image, np_mask)

    images += bs.generateInterImages(images[-1], np_final, number_of_inters)
    return images
示例#5
0
def closely(np_org_image, number_of_inters=3, struct_elem='rect', size=3):
    """Execute closely (erosion on dilated image) on a given image 

    Arguments:
        np_org_image {NumPy array} -- image for erosion

    Keyword Arguments:
        struct_elem {str} -- stuctural element used during erosion  (default: {'rect'})
            rect - rectange
            cross - cross
        size {int} -- size of the structural element. Should be odd and greater than 2 (default: {3})
        number_of_inters {int} -- number of inter images generated by this function (minimum/default: {3})

    Returns:
        [list of NumPy arrays] -- list containing original image, specified number of inter images and final image
    """

    #arguments validation
    bs.validate_number_of_inters(number_of_inters, closely.__defaults__[-1])

    processed_inters = 0
    images = []
    images.append(np_org_image)

    #grayscale
    np_image_2D, isConverted = bs.ensureGrayscale(np_org_image, info=True)
    if isConverted:
        images.append(np_image_2D)
        processed_inters += 1

    #binarization
    np_image_bin = bn.otsuBinarization(images[-1], only_threshold=False)
    processed_inters += 1
    images.append(np_image_bin)

    #dilate part
    np_image_dil = bn.dilate(images[-1], struct_elem, size)
    #calculate number of inters to erode operation
    dilate_inters = math.floor((number_of_inters - processed_inters) / 2 - 1)
    if dilate_inters > 0:
        images += bs.generateInterImages(images[-1], np_image_dil,
                                         processed_inters + dilate_inters,
                                         processed_inters)
        processed_inters += dilate_inters
    else:
        images.append(np_image_dil)

    #one from final dilate image
    processed_inters += 1

    #erode part
    np_final = bn.erode(np_image_dil, struct_elem, size)
    images += bs.generateInterImages(images[-1], np_final, number_of_inters,
                                     processed_inters)
    return images
示例#6
0
def dilation(np_org_image, struct_elem='rect', size=3, number_of_inters=2):
    """Execute dilation on a given image

    Arguments:
        np_org_image {NumPy array} -- image for dilation

    Keyword Arguments:
        struct_elem {str} -- stuctural element used during dilation (default: {'rect'})
            rect - rectange
            cross - cross   
        size {int} -- size of the structural element. Should be odd and greater than 2 (default: {3})
        number_of_inters {int} -- number of inter images generated by this function (minimum/default: {2})

    Returns:
        [list of NumPy arrays] -- list containing original image, specified number of inter images and final image
    """

    #arguments validation
    bs.validate_number_of_inters(number_of_inters, dilation.__defaults__[-1])

    #variable initialization
    processed_inters = 0
    images = []
    images.append(np_org_image)

    #grayscale
    np_image_2D, isConverted = bs.ensureGrayscale(np_org_image, info=True)
    if isConverted:
        images.append(np_image_2D)
        processed_inters += 1

    #binarization
    np_image_bin = bn.otsuBinarization(images[-1], only_threshold=False)
    processed_inters += 1
    images.append(np_image_bin)

    #dilation
    np_final = bn.dilate(images[-1], struct_elem, size)
    images += bs.generateInterImages(images[-1], np_final, number_of_inters,
                                     processed_inters)
    return images
示例#7
0
def median_filtering(np_org_image,
                     struct_elem='rect',
                     size=3,
                     number_of_inters=1):
    """Median filtering on a given image .

    Arguments:
        np_org_image {NumPy array} -- image for median filtering

    Keyword Arguments:
        struct_elem {str} -- stuctural element from which median value will be calculated  (default: {'rect'})
            rect - rectange
            cross - cross
        size {int} -- size of the structural element. Should be odd and greater than 2 (default: {3})
        number_of_inters {int} -- number of inter images generated by this function (minimum/default: {1})

    Returns:
         [list of NumPy arrays] -- list containing original image, specified number of inter images and final image
    """
    #arguments validation
    bs.validate_number_of_inters(number_of_inters,
                                 median_filtering.__defaults__[-1])

    images = []
    images.append(np_org_image)
    np_final = np.empty(np_org_image.shape, dtype=np.uint8)

    if bs.isColorImage(np_org_image):
        np_final[:, :, 0] = fil.medianFilter(np_org_image[:, :, 0],
                                             struct_elem, size)
        np_final[:, :, 1] = fil.medianFilter(np_org_image[:, :, 1],
                                             struct_elem, size)
        np_final[:, :, 2] = fil.medianFilter(np_org_image[:, :, 2],
                                             struct_elem, size)
    else:
        np_final = fil.medianFilter(np_org_image, struct_elem, size)

    images += bs.generateInterImages(images[-1], np_final, number_of_inters)
    return images