示例#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 __init__(self, I, radius=5, epsilon=0.4):
        I_32F = to32F(I)

        if _isGray(I):
            self._guided_filter = GuidedFilterGray(I_32F, radius, epsilon)
        else:
            self._guided_filter = GuidedFilterColor(I_32F, radius, epsilon)
示例#4
0
    def __init__(self, I, radius=5, epsilon=0.4):
        I_32F = to32F(I)

        if _isGray(I):
            self._guided_filter = GuidedFilterGray(I_32F, radius, epsilon)
        else:
            self._guided_filter = GuidedFilterColor(I_32F, radius, epsilon)
示例#5
0
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)
示例#6
0
    def filter(self, p):
        p_32F = to32F(p)
        if _isGray(p_32F):
            return self._filterGray(p_32F)

        cs = p.shape[2]
        q = np.array(p_32F)

        for ci in range(cs):
            q[:, :, ci] = self._filterGray(p_32F[:, :, ci])
        return q
示例#7
0
    def filter(self, p):
        p_32F = to32F(p)
        if _isGray(p_32F):
            return self._filterGray(p_32F)

        cs = p.shape[2]
        q = np.array(p_32F)

        for ci in range(cs):
            q[:, :, ci] = self._filterGray(p_32F[:, :, ci])
        return q
示例#8
0
    def __init__(self, I, radius=5, epsilon=0.4, scale=4):
        I_32F = to32F(I)
        self._I = I_32F
        h, w = I.shape[:2]

        I_sub = _downSample(I_32F, scale)

        self._I_sub = I_sub
        radius = int(radius / scale)

        if _isGray(I):
            self._guided_filter = GuidedFilterGray(I_sub, radius, epsilon)
        else:
            self._guided_filter = GuidedFilterColor(I_sub, radius, epsilon)
示例#9
0
    def __init__(self, I, radius=5, epsilon=0.4, scale=4):
        I_32F = to32F(I)
        self._I = I_32F
        h, w = I.shape[:2]

        I_sub = _downSample(I_32F, scale)

        self._I_sub = I_sub
        radius = int(radius / scale)

        if _isGray(I):
            self._guided_filter = GuidedFilterGray(I_sub, radius, epsilon)
        else:
            self._guided_filter = GuidedFilterColor(I_sub, radius, epsilon)
示例#10
0
    def filter(self, p):
        p_32F = to32F(p)
        shape_original = p.shape[:2]

        p_sub = _downSample(p_32F, shape=self._I_sub.shape[:2])

        if _isGray(p_sub):
            return self._filterGray(p_sub, shape_original)

        cs = p.shape[2]
        q = np.array(p_32F)

        for ci in range(cs):
            q[:, :, ci] = self._filterGray(p_sub[:, :, ci], shape_original)
        return q
示例#11
0
    def filter(self, p):
        p_32F = to32F(p)
        shape_original = p.shape[:2]

        p_sub = _downSample(p_32F, shape=self._I_sub.shape[:2])

        if _isGray(p_sub):
            return self._filterGray(p_sub, shape_original)

        cs = p.shape[2]
        q = np.array(p_32F)

        for ci in range(cs):
            q[:, :, ci] = self._filterGray(p_sub[:, :, ci], shape_original)
        return q
示例#12
0
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)
示例#13
0
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_8U = 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

    sigmas = [5, 10, 20]
    sigma = 20

    guided_filter = FastGuidedFilter(C_32F, radius=sigma, epsilon=0.02)
    C_smooth = guided_filter.filter(C_32F)
    C_smooth = np.clip(C_smooth, 0.0, 1.0)
    img_8U = to8U(C_smooth)
    return img_8U
示例#14
0
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)
示例#15
0
 def __init__(self, I, radius=5, epsilon=0.2):
     self._radius = 2 * radius + 1
     self._epsilon = epsilon
     self._I = to32F(I)
     self._initFilter()
     self._filter_common = GuidedFilterCommon(self)
示例#16
0
 def __init__(self, I, radius=5, epsilon=0.2):
     self._radius = 2 * radius + 1
     self._epsilon = epsilon
     self._I = to32F(I)
     self._initFilter()
     self._filter_common = GuidedFilterCommon(self)