예제 #1
0
파일: filter.py 프로젝트: 1989Ryan/hw4
def high_pass_filter_process(imagename):
    image_name1 = "../../homework4/project4/" + imagename
    result = "../../homework4/result2" + imagename[:5] + ".png"
    result2 = "../../homework4/result3" + imagename[:5] + "1.png"
    tool = basic_cv_tool(image_name1)
    img = tool.ImageRead(image_name1)
    img1 = tool.laplace_filter(img)
    img2 = tool.sobel_filter(img)
    img3 = tool.unsharp_mask_filter(img, 0.5)
    img4 = tool.canny(img)
    plt.figure(figsize=(16, 4))
    p1 = plt.subplot(141)
    p1.set_title('laplace', fontsize=11)
    p1.imshow(img1, cmap='gray')
    p2 = plt.subplot(142)
    p2.set_title('sobel', fontsize=11)
    p2.imshow(img2, cmap='gray')
    p3 = plt.subplot(143)
    p3.set_title('unsharp', fontsize=11)
    p3.imshow(img3, cmap='gray')
    p3 = plt.subplot(144)
    p3.set_title('canny', fontsize=11)
    p3.imshow(img4, cmap='gray')
    plt.savefig(result)
    res = np.hstack((img1, img2, img3, img4))
    cv2.imwrite(result2, res)
예제 #2
0
def task1(imagename, filtername):
    image_name1 = "../../homework5/project5/" + imagename
    result = "../../homework5/result1" + filtername + imagename[:5] + ".png"
    tool = basic_cv_tool(image_name1)
    img = tool.ImageRead(image_name1)
    f = np.fft.fftshift(np.fft.fft2(img))
    s = np.log(np.abs(f))
    if filtername == 'butterworth':
        img1 = tool.BLPF(img, 25, 2)
        f1 = np.fft.fftshift(np.fft.fft2(img1))
        s1 = np.log(np.abs(f1))
        img2 = tool.BLPF(img, 50, 2)
        f2 = np.fft.fftshift(np.fft.fft2(img2))
        s2 = np.log(np.abs(f2))
        img3 = tool.BLPF(img, 75, 2)
        f3 = np.fft.fftshift(np.fft.fft2(img3))
        s3 = np.log(np.abs(f3))
    else:
        img1 = tool.GLPF(img, 25, 2)
        f1 = np.fft.fftshift(np.fft.fft2(img1))
        s1 = np.log(np.abs(f1))
        img2 = tool.GLPF(img, 50, 2)
        f2 = np.fft.fftshift(np.fft.fft2(img2))
        s2 = np.log(np.abs(f2))
        img3 = tool.GLPF(img, 75, 2)
        f3 = np.fft.fftshift(np.fft.fft2(img3))
        s3 = np.log(np.abs(f3))
    plt.figure(figsize=(16, 8))
    p = plt.subplot(241)
    p.set_title('original image', fontsize=11)
    p.imshow(img, cmap='gray')
    p1 = plt.subplot(242)
    p1.set_title(filtername + ' filter, 25', fontsize=11)
    p1.imshow(img1, cmap='gray')
    p2 = plt.subplot(243)
    p2.set_title(filtername + ' filter, 50', fontsize=11)
    p2.imshow(img2, cmap='gray')
    p3 = plt.subplot(244)
    p3.set_title(filtername + ' filter, 75', fontsize=11)
    p3.imshow(img3, cmap='gray')
    pp = plt.subplot(245)
    pp.set_title('original image', fontsize=11)
    pp.imshow(s, cmap='gray')
    p4 = plt.subplot(246)
    p4.set_title(filtername + ' filter, 25', fontsize=11)
    plt.imshow(s1, cmap='gray')
    p5 = plt.subplot(247)
    p5.set_title(filtername + ' filter, 50', fontsize=11)
    p5.imshow(s2, cmap='gray')
    p6 = plt.subplot(248)
    p6.set_title(filtername + ' filter, 75', fontsize=11)
    p6.imshow(s3, cmap='gray')
    plt.savefig(result)
    print(filtername, " 25: ", tool.Power_spectrum_ratio(img, img1))
    print(filtername, " 25: ", tool.Power_spectrum_ratio(img, img2))
    print(filtername, " 25: ", tool.Power_spectrum_ratio(img, img3))
예제 #3
0
def task3(imagename, k):
    image_name1 = "../../homework5/project5/" + imagename
    result = "../../homework5/result3" + imagename[:5] + ".png"
    result2 = "../../homework5/result3" + imagename[:5] + "enhance.png"
    tool = basic_cv_tool(image_name1)
    img = tool.ImageRead(image_name1)
    f = np.fft.fftshift(np.fft.fft2(img))
    s = np.log(np.abs(f))
    img1 = tool.LHPF(img, 25, 2)
    f1 = np.fft.fftshift(np.fft.fft2(img1))
    s1 = np.log(np.abs(f1))
    img2 = tool.Unsharp_Masking(img, 25, 2, k)
    f2 = np.fft.fftshift(np.fft.fft2(img2))
    s2 = np.log(np.abs(f2))
    plt.figure(figsize=(12, 8))
    p = plt.subplot(231)
    p.set_title('original image', fontsize=11)
    p.imshow(img, cmap='gray')
    p1 = plt.subplot(232)
    p1.set_title('Laplacian', fontsize=11)
    p1.imshow(img1, cmap='gray')
    p2 = plt.subplot(233)
    p2.set_title('Unsharp Masking', fontsize=11)
    p2.imshow(img2, cmap='gray')
    p3 = plt.subplot(234)
    p3.set_title('original image', fontsize=11)
    p3.imshow(s, cmap='gray')
    pp = plt.subplot(235)
    pp.set_title('Laplacian', fontsize=11)
    pp.imshow(s1, cmap='gray')
    p4 = plt.subplot(236)
    p4.set_title('Unsharp Masking', fontsize=11)
    plt.imshow(s2, cmap='gray')
    plt.savefig(result)
    plt.figure(figsize=(12, 4))
    p = plt.subplot(131)
    p.set_title('original image', fontsize=11)
    p.imshow(img, cmap='gray')
    p1 = plt.subplot(132)
    p1.set_title('Laplacian enhance', fontsize=11)
    p1.imshow(img + 0.5 * img1, cmap='gray')
    print(img1)
    p2 = plt.subplot(133)
    p2.set_title('Unsharp Masking enhance', fontsize=11)
    p2.imshow(img2, cmap='gray')
    plt.savefig(result2)
예제 #4
0
파일: filter.py 프로젝트: 1989Ryan/hw4
def mid(imagename):
    image_name1 = "../../homework4/project4/" + imagename
    result = "../../homework4/result2" + imagename[:5] + ".png"
    result2 = "../../homework4/result2" + imagename[:5] + "1.png"
    tool = basic_cv_tool(image_name1)
    img = tool.ImageRead(image_name1)
    img1 = tool.MediumFilter(img, 3)
    img2 = tool.MediumFilter(img, 5)
    img3 = tool.MediumFilter(img, 7)
    plt.figure(figsize=(16, 5))
    p1 = plt.subplot(131)
    p1.set_title('midfilter, 3x3', fontsize=11)
    p1.imshow(img1, cmap='gray')
    p2 = plt.subplot(132)
    p2.set_title('midfilter, 5x5', fontsize=11)
    p2.imshow(img2, cmap='gray')
    p3 = plt.subplot(133)
    p3.set_title('midfilter, 7x7', fontsize=11)
    p3.imshow(img3, cmap='gray')
    plt.savefig(result)
    res = np.hstack((img1, img2, img3))
    cv2.imwrite(result2, res)
예제 #5
0
import sys
import os
sys.path.remove('/opt/ros/kinetic/lib/python2.7/dist-packages')
lib_path = os.path.abspath(os.path.join(sys.path[0], '..'))
sys.path.append(lib_path)
from src.basic_cv_tool import *

image_2_name = '../../homework1/elain1.bmp'

tool = basic_cv_tool(image_2_name)
img = tool.ImageRead(image_2_name)
mean = tool.image_average(img)
var = tool.image_variance(img)
print(mean)
print(var)