Spaces:
Build error
Build error
add Ordered_Dithering
#1
by hankwuii - opened
12345624 unmodified lines313233343536127 unmodified lines164165166167168169import gradio as grimport cv2import numpy as npfrom skimage import segmentation, colorimport torchimport torch.nn as nn24 unmodified linesresult = cv2.inpaint(image, mask, inpaintRadius=3, flags=cv2.INPAINT_TELEA)return result# Super Resolution related functions'''class PositionalEncoding(nn.Module):def __init__(self, num_frequencies=10):127 unmodified linesinp_output = gr.Image(type="numpy", label="Output Image")inp_button.click(image_inpainting, inputs=[inp_input, inp_mask], outputs=inp_output)'''with gr.Tab("Super Resolution"):with gr.Row():with gr.Column():123456724 unmodified lines32333435363738394041424344454647484950515253545556575859606162636465666768127 unmodified lines196197198199200201202203204205206207208209210211import gradio as grimport cv2import numpy as npimport mathfrom skimage import segmentation, colorimport torchimport torch.nn as nn24 unmodified linesresult = cv2.inpaint(image, mask, inpaintRadius=3, flags=cv2.INPAINT_TELEA)return resultdef Ordered_Dithering(n, img):if n == 1:new_matrix = np.array([[0, 2], [3, 1]])else:smaller_matrix = generate_bayer_matrix(n - 1)size = 2 ** nnew_matrix = np.zeros((size, size), dtype=int)for i in range(2 ** (n - 1)):for j in range(2 ** (n - 1)):base_value = 4 * smaller_matrix[i, j]new_matrix[i, j] = base_valuenew_matrix[i, j + 2 ** (n - 1)] = base_value + 2new_matrix[i + 2 ** (n - 1), j] = base_value + 3new_matrix[i + 2 ** (n - 1), j + 2 ** (n - 1)] = base_value + 1N = new_matrix.shape[0]thresholds_matrix = np.zeros_like(new_matrix, int)for i in range(N):for j in range(N):thresholds_matrix[i, j] = int((255 * (new_matrix[i, j] + 0.5)) / (N * N))height, width = img.shapeN = thresholds_matrix.shape[0]Ordered_Dithering_img = np.zeros_like(img)for i in range(height):for j in range(width):threshold = thresholds_matrix[i % N, j % N]Ordered_Dithering_img[i, j] = 255 if img[i, j] > threshold else 0return Ordered_Dithering_img# Super Resolution related functions'''class PositionalEncoding(nn.Module):def __init__(self, num_frequencies=10):127 unmodified linesinp_output = gr.Image(type="numpy", label="Output Image")inp_button.click(image_inpainting, inputs=[inp_input, inp_mask], outputs=inp_output)with gr.Tab("Ordered_Dithering"):with gr.Row():with gr.Column():inp_input = gr.Image(type="numpy", label="Input Image")n_slider = gr.Slider(minimum=2, maximum=8, step=1, value=4, label="Bayer Matrix Size (n)")inp_button = gr.Button("Apply Ordered Dithering")with gr.Column():inp_output = gr.Image(type="numpy", label="Output Image")inp_button.click(Ordered_Dithering, inputs=[inp_input, n_slider], outputs=inp_output)'''with gr.Tab("Super Resolution"):with gr.Row():with gr.Column():
app.py+42