Ejemplo n.º 1
0
def thresholding(image, threshold, flag=1):
    image = rgb2gray(image)
    height, width = image.shape
    output = np.zeros_like(image, dtype=np.uint8)

    # 0 or 255
    if flag == 1:
        for row in range(height):
            for col in range(width):
                if image[row, col] > threshold:
                    output[row, col] = 255
                else:
                    output[row, col] = 0

    # change pixels > threshold
    elif flag == 2:
        for row in range(height):
            for col in range(width):
                if image[row, col] > threshold:
                    output[row, col] = 255

    # pixels between 0 and threshold
    elif flag == 3:
        for row in range(height):
            for col in range(width):
                if image[row, col] > threshold:
                    output[row, col] = threshold

    return output
Ejemplo n.º 2
0
def laplacian_filter_test():
    i = imageio.imread('images/moon.jpeg')
    i = colors.rgb2gray(i)
    img = cv2.imread('images/moon.jpeg', 0)
    it1 = cv2.Laplacian(img, cv2.CV_64F)
    it2 = bk.laplacian_filter(i)
    util.subplot_img(it1, it2)
Ejemplo n.º 3
0
def histogram_test_gray():
    i = imageio.imread('images/hamster.jpeg')
    i = colors.rgb2gray(i)
    img = cv2.imread('images/hamster.jpeg', 0)
    hist1 = cv2.calcHist([img], [0], None, [256], [0, 256])
    hist2 = bk.histogram(i)
    print(hist1.ravel())
    print(hist2)
    util.subplot_hist(hist1.ravel(), hist2)
Ejemplo n.º 4
0
def negative_filter_test():
    i = imageio.imread('images/breast.jpeg')
    i = colors.rgb2gray(i)
    it1 = cv2.bitwise_not(i)
    it2 = bk.negative_filter(i)
    util.subplot_img(it1, it2)
Ejemplo n.º 5
0
def sobel_filter_test():
    i = imageio.imread('images/lens.jpeg')
    i = colors.rgb2gray(i)
    it = bk.sobel_filter(i)
    util.subplot_img(i, it)
Ejemplo n.º 6
0
def median_filter_test():
    i = imageio.imread('images/salt_pepper.jpeg')
    i = colors.rgb2gray(i)
    it1 = cv2.medianBlur(i, 3)
    it2 = bk.median_filter(i, 3)
    util.subplot_img(it1, it2)
Ejemplo n.º 7
0
def mean_filter_test():
    i = imageio.imread('images/blurring.jpeg')
    i = colors.rgb2gray(i)
    it1 = cv2.blur(i, (5, 5))
    it2 = bk.mean_filter(i, 5)
    util.subplot_img(it1, it2)
Ejemplo n.º 8
0
def gamma_filter_test():
    i = imageio.imread('images/aerial.jpeg')
    i = colors.rgb2gray(i)
    it = bk.gamma_filter(i, 1, 5)
    util.subplot_img(i, it)
Ejemplo n.º 9
0
def logarithm_filter_test():
    i = imageio.imread('images/dft.jpeg')
    i = colors.rgb2gray(i)
    it = bk.logarithm_filter(i, 1)
    util.subplot_img(i, it)
Ejemplo n.º 10
0
    for x in range(width):
        for y in range(height):
            xp = int((x - center_x) * np.cos(angle) -
                     (y - center_y) * np.sin(angle) + center_x)
            yp = int((x - center_x) * np.sin(angle) +
                     (y - center_y) * np.cos(angle) + center_y)
            if 0 <= xp < width and 0 <= yp < height:
                output[x, y] = image[xp, yp]

    return output


if __name__ == '__main__':
    filename = 'einstein'
    path = 'images/' + filename + '.jpeg'
    i = imageio.imread(path)
    i = rgb2gray(i)
    print('Shape: ', i.shape)
    #it = bilinearRotate(i, 30)
    #it = nnscale(i, i.shape[0]*1.5, i.shape[1]*1.5)
    it = nnrotate(i, 30)
    print('New shape: ', it.shape)
    #imshow(it)
    #it2 = image.rotate(30)
    #it = resizeBilinearInterpolation(i, i.shape[0]+50, i.shape[1]+50)
    #cv2.imshow('ImageWindow', cv2.cvtColor(it, cv2.COLOR_BGR2RGB))
    #cv2.waitKey()
    #cv2.imshow('ImageWindow', cv2.cvtColor(i, cv2.COLOR_BGR2RGB))
    #cv2.waitKey()
    subplot_img(i, it)