Example #1
0
    def showimage(self, imageurl, _offsetx=0, _offsety=0, resize=True):
        imagetk = ImageTk.PhotoImage(Image.Open(imageurl))

        width   = imagetk.width()
        height  = imagetk.height()
        offsetx = _offsetx
        offsety = _offsety

        if resize: self.size(width, height, offsetx, offsety)

        imagepanel = tk.Label(self.root, image=imagetk)
        imagepanel.pack(side='top', fill='both', expand='yes')

        imagepanel.image = imagetk
Example #2
0
def test(model, image, zoom):
    img  = Image.Open(image).convert('YCbCr')
    img = img.resize((int(img.size[0]*zoom), int(img.size[1]*zoom)), Image.BICUBIC)

    y, cb, cr = img.split()
    img_tensor = transforms.ToTensor()
    input = img_tensor(y).view(1, -1, y.size[1], y.size[0])

    input = input.to(device)

    out = model(input)
    out_img_y = out[0].detach().numpy()
    out_img_y *= 255.0
    out_img_y = out_img_y.clip(0, 255)
    out_img_y = Image.fromarray(np.uint8(out_img_y[0]), mode='L')

    out_img = Image.merge('YCbCr', [out_img_y, cb, cr]).convert('RGB')
    out_img.save(f"zoomed_{args.image}")
Example #3
0
def load_and_preprocess_single_image(image_dir):
    image = Image.Open(image_dir)
    return self.image_resize(image)
Example #4
0
import os
from PIL import Image

files = os.listdir('/home/sitharth/quarantine/python_examples/images')
# print(files)
images = [file for file in files if file.endswith(('jpg', 'png'))]

print(images)

for image in images:
    im = Image.Open(os.path(image))
    print(im)
    # image_name = image.split('.')[0]
    # # print(image_name)
    # im.save(f"madiee-{image_name}.webp", 'webp')

# for image in images:
#     image_name = image.split('.')[0]
Example #5
0
    for _, _, files in os.walk(DataSet_Path):
        for filename in files:
            if filename.split('.')[1] != 'png':
                continue

            #获取原图像
            img_path = join(DataSet_Path, filename)
            img = cv2.imread(img_path)

            #祛除干扰线
            clearline_img_path = join(ClearLine_Path, filename)
            clearline_img = clear_line_auto(img)

            cv2.imwrite(clearline_img_path, clearline_img)

            #祛除背景色
            clearbackcolor_img_path = join(ClearBackColor_Path, filename)
            clearbackcolor_img = clear_backcolor_auto(clearline_img)
            cv2.imwrite(clearbackcolor_img_path, clearbackcolor_img)

            #降噪处理
            clearnoise_img_path = join(ClearNoise_Path, filename)
            clearnoise_img = clear_noise(clearbackcolor_img)
            cv2.imwrite(clearnoise_img_path, clearnoise_img)

            #转为二值化图像(PIL型)
            need_img_path = join(Captcha_Path, filename)
            need_img = Image.Open(need_img_path)
            need_img = need_img.convert('1')
            need_img.save()