コード例 #1
0
def run(src_path, label_path, sigmas, epsilon=0.02, same=False):
    src_name = os.path.basename(src_path)
    src_name = os.path.splitext(src_name)[0]
    label_name = os.path.basename(label_path)
    label_name = os.path.splitext(label_name)[0]

    src_C_8U = loadRGB(src_path)
    src_C_32F = to32F(src_C_8U)

    label_C_8U = loadRGB(label_path)
    label_C_32F = to32F(label_C_8U)

    os.makedirs('./output/', exist_ok=True)

    for sigma in sigmas:
        print(sigma)
        for eps in epsilon:
            if same:
                guided_filter = GuidedFilter(label_C_32F,
                                             radius=sigma,
                                             epsilon=eps)
            else:
                guided_filter = GuidedFilter(src_C_32F,
                                             radius=sigma,
                                             epsilon=eps)
            result = guided_filter.filter(label_C_32F)
            cv2.imwrite(
                './output/{}_radius{}_eps{:.03f}.png'.format(
                    label_name, sigma, eps),
                cv2.cvtColor(result * 255, cv2.COLOR_RGB2GRAY))
コード例 #2
0
def GuidedFilter(input_imagefile, guidance_imgfile):
    image_name = os.path.basename(input_imagefile)
    image_name = os.path.splitext(image_name)[0]

    C_Input_8U = loadRGB(input_imagefile)
    C_Input_32F = to32F(C_Input_8U)

    C_Guidnace_8U = loadRGB(guidance_imgfile)
    C_Guidnace_32F = to32F(C_Guidnace_8U)

    aspect = C_Input_32F.shape[0] / float(C_Input_32F.shape[1])

    fig_width = 10
    fig_height = int(2 * fig_width * aspect / 3) + 2
    fig = plt.figure(figsize=(fig_width, fig_height))
    fig.subplots_adjust(left=0.05,
                        bottom=0.05,
                        right=0.95,
                        top=0.82,
                        wspace=0.02,
                        hspace=0.3)
    h, w = C_Input_32F.shape[:2]
    image_size_str = "Image size: %s x %s" % (w, h)
    fig.suptitle("Filtering noise image\n%s" % image_size_str)

    # plt.subplot(231)
    # plt.title("Original")
    # plt.imshow(C_Input_32F)
    # plt.axis('off')

    h, w, cs = C_Input_32F.shape

    plt.subplot(232)
    plt.title("input img")
    plt.imshow(C_Input_32F)
    plt.axis('off')

    sigmas = [5, 10, 20]

    plot_id = 234
    for sigma in sigmas:
        guided_filter = FastGuidedFilter(C_Guidnace_32F,
                                         radius=sigma,
                                         epsilon=0.02)
        C_smooth = guided_filter.filter(C_Input_32F)
        C_smooth = np.clip(C_smooth, 0.0, 1.0)

        plt.subplot(plot_id)
        plt.title("Filtered ($r$=%s)" % sigma)
        plt.imshow(C_smooth)
        plt.axis('off')
        plot_id += 1

    result_file = resultFile(image_name)
    plt.savefig(result_file)
コード例 #3
0
def loadData(data_name, data_id):
    data_file = dataFile(data_name, data_id)

    if data_file is None:
        return None

    return loadRGB(data_file)
コード例 #4
0
    def postResize(self):
        print("  Post resize")
        data_name = self._keyword
        data_files = dataFiles(data_name)

        for data_file in data_files:
            data_filename = os.path.basename(data_file)
            C_8U = loadRGB(data_file)

            if C_8U is None:
                os.remove(data_file)
                print("  - Delete: {}").format(data_filename)
                continue
            h, w = C_8U.shape[0:2]

            opt_scale = 800.0 / float(h)
            opt_scale = max(opt_scale, 800.0 / float(w))
            opt_scale = min(opt_scale, 1.0)

            h_opt = int(opt_scale * h)
            w_opt = int(opt_scale * w)

            C_8U_small = cv2.resize(C_8U, (w_opt, h_opt))
            saveRGB(data_file, C_8U_small)
            print("  - Resized: {}").format(data_filename)
コード例 #5
0
ファイル: google_image.py プロジェクト: tody411/GuidedFilter
def loadData(data_name, data_id):
    data_file = dataFile(data_name, data_id)

    if data_file is None:
        return None

    return loadRGB(data_file)
コード例 #6
0
ファイル: google_image.py プロジェクト: tody411/GuidedFilter
    def postResize(self):
        print "  Post resize"
        data_name = self._keyword
        data_files = dataFiles(data_name)

        for data_file in data_files:
            data_filename = os.path.basename(data_file)
            C_8U = loadRGB(data_file)

            if C_8U is None:
                os.remove(data_file)
                print "  - Delete: %s" % data_filename
                continue
            h, w = C_8U.shape[0:2]

            opt_scale = 800.0 / float(h)
            opt_scale = max(opt_scale, 800.0 / float(w))
            opt_scale = min(opt_scale, 1.0)

            h_opt = int(opt_scale * h)
            w_opt = int(opt_scale * w)

            C_8U_small = cv2.resize(C_8U, (w_opt, h_opt))
            saveRGB(data_file, C_8U_small)
            print "  - Resized: %s" % data_filename
コード例 #7
0
ファイル: performance.py プロジェクト: abolger/GuidedFilter
def performanceTest(image_file):
    C_8U = loadRGB(image_file)
    C_32F = to32F(C_8U)

    h, w = C_32F.shape[:2]
    image_size_str = "Image size: %s x %s" %(w, h)

    fig, axes = plt.subplots(nrows=2, ncols=1, figsize=(8, 8))
    fig.subplots_adjust(left=0.1, right=0.7, top=0.86, hspace=0.4)

    fig.suptitle("Peformance of guided filter\n%s" % image_size_str)

    filter_types = {"Bilateral Filter": (BilateralFilter, "r"),
                    "Guided Filter": (GuidedFilter, "g"),
                    "Fast Guided Filter": (FastGuidedFilter, "b")}

    sigmas = range(3, 31, 2)
    axes[0].set_title('For small radius $r$')

    performanceTestSigmas(C_32F, sigmas, filter_types, axes[0])

    sigmas = range(10, 100, 5)

    filter_types = {"Guided Filter": (GuidedFilter, "g"),
                    "Fast Guided Filter": (FastGuidedFilter, "b")}

    axes[1].set_title('For large radius $r$')
    performanceTestSigmas(C_32F, sigmas, filter_types, axes[1])

    result_name = "performance"
    result_file = resultFile(result_name)
    plt.savefig(result_file)
コード例 #8
0
ファイル: smooth_noise.py プロジェクト: abolger/GuidedFilter
def runSmoothNoiseResult(image_file):
    image_name = os.path.basename(image_file)
    image_name = os.path.splitext(image_name)[0]

    C_8U = loadRGB(image_file)
    C_32F = to32F(C_8U)

    aspect = C_32F.shape[0] / float(C_32F.shape[1])

    fig_width = 10
    fig_height = int(2 * fig_width * aspect / 3) + 2
    fig = plt.figure(figsize=(fig_width, fig_height))
    fig.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.82, wspace=0.02, hspace=0.3)
    h, w = C_32F.shape[:2]
    image_size_str = "Image size: %s x %s" %(w, h)
    fig.suptitle("Filtering noise image\n%s" % image_size_str)

    plt.subplot(231)
    plt.title("Original")
    plt.imshow(C_32F)
    plt.axis('off')

    h, w, cs = C_32F.shape

    C_noise = np.float32(C_32F + 0.3 * np.random.rand(h, w, cs))
    C_noise = np.clip(C_noise, 0.0, 1.0)

    plt.subplot(232)
    plt.title("Noise")
    plt.imshow(C_noise)
    plt.axis('off')

    sigmas = [5, 10, 20]

    plot_id = 234
    for sigma in sigmas:
        guided_filter = FastGuidedFilter(C_noise, radius=sigma, epsilon=0.02)
        C_smooth = guided_filter.filter(C_noise)
        C_smooth = np.clip(C_smooth, 0.0, 1.0)

        plt.subplot(plot_id)
        plt.title("Filtered ($r$=%s)" %sigma)
        plt.imshow(C_smooth)
        plt.axis('off')
        plot_id +=1

    result_file = resultFile(image_name)
    plt.savefig(result_file)
コード例 #9
0
ファイル: performance.py プロジェクト: 14es93/check-filter
def performanceTest(image_file):
    C_8U = loadRGB(image_file)
    C_32F = to32F(C_8U)

    h, w = C_32F.shape[:2]
    image_size_str = "Image size: %s x %s" % (w, h)

    fig, axes = plt.subplots(nrows=2, ncols=1, figsize=(8, 8))
    fig.subplots_adjust(left=0.1, right=0.7, top=0.86, hspace=0.4)

    fig.suptitle("Peformance of guided filter\n%s" % image_size_str)

    filter_types = {
        "Bilateral Filter": (BilateralFilter, "r"),
        "Guided Filter": (GuidedFilter, "g"),
        "Fast Guided Filter": (FastGuidedFilter, "b")
    }

    sigmas = range(3, 31, 2)
    axes[0].set_title('For small radius $r$')

    performanceTestSigmas(C_32F, sigmas, filter_types, axes[0])

    sigmas = range(10, 100, 5)

    filter_types = {
        "Guided Filter": (GuidedFilter, "g"),
        "Fast Guided Filter": (FastGuidedFilter, "b")
    }

    axes[1].set_title('For large radius $r$')
    performanceTestSigmas(C_32F, sigmas, filter_types, axes[1])

    result_name = "performance"
    result_file = resultFile(result_name)
    plt.savefig(result_file)