當前位置: 首頁>>代碼示例>>Python>>正文


Python ImageFilter.UnsharpMask方法代碼示例

本文整理匯總了Python中PIL.ImageFilter.UnsharpMask方法的典型用法代碼示例。如果您正苦於以下問題:Python ImageFilter.UnsharpMask方法的具體用法?Python ImageFilter.UnsharpMask怎麽用?Python ImageFilter.UnsharpMask使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PIL.ImageFilter的用法示例。


在下文中一共展示了ImageFilter.UnsharpMask方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: decoder_retraining_dataset

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import UnsharpMask [as 別名]
def decoder_retraining_dataset(self):
        """
        Generating the dataset for the decoder retraining technique with unsharp masking
        :return: training samples and labels for decoder retraining 
        """
        model = self.model
        data = self.data
        args = self.args
        x_recon = self.reconstructions
        (x_train, y_train), (x_test, y_test) = data 
        if not os.path.exists(args.save_dir+"/check"):
            os.makedirs(args.save_dir+"/check")
        if not os.path.exists(args.save_dir+"/check/x_decoder_retrain.npy"):
            for q in range(0,x_recon.shape[0]):
                save_img = Image.fromarray((x_recon[q]*255).reshape(28,28).astype(np.uint8))
                image_more_sharp = save_img.filter(ImageFilter.UnsharpMask(radius=1, percent=1000, threshold=1))
                img_arr = np.asarray(image_more_sharp)
                img_arr = img_arr.reshape(-1,28,28,1).astype('float32') / 255.
                if (q==0):
                    x_recon_sharped = np.concatenate([img_arr])
                else:
                    x_recon_sharped = np.concatenate([x_recon_sharped,img_arr])
            self.save_output_image(x_recon_sharped[:100],"sharpened reconstructions")
            x_decoder_retrain = self.masked_inst_parameter
            y_decoder_retrain = x_recon_sharped
            np.save(args.save_dir+"/check/x_decoder_retrain",x_decoder_retrain)
            np.save(args.save_dir+"/check/y_decoder_retrain",y_decoder_retrain)
        else:
            x_decoder_retrain = np.load(args.save_dir+"/check/x_decoder_retrain.npy")
            y_decoder_retrain = np.load(args.save_dir+"/check/y_decoder_retrain.npy")
        return x_decoder_retrain,y_decoder_retrain 
開發者ID:vinojjayasundara,項目名稱:textcaps,代碼行數:33,代碼來源:textcaps_emnist_bal.py

示例2: test_sanity

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import UnsharpMask [as 別名]
def test_sanity(self):

        def filter(filter):
            for mode in ["L", "RGB", "CMYK"]:
                im = hopper(mode)
                out = im.filter(filter)
                self.assertEqual(out.mode, im.mode)
                self.assertEqual(out.size, im.size)

        filter(ImageFilter.BLUR)
        filter(ImageFilter.CONTOUR)
        filter(ImageFilter.DETAIL)
        filter(ImageFilter.EDGE_ENHANCE)
        filter(ImageFilter.EDGE_ENHANCE_MORE)
        filter(ImageFilter.EMBOSS)
        filter(ImageFilter.FIND_EDGES)
        filter(ImageFilter.SMOOTH)
        filter(ImageFilter.SMOOTH_MORE)
        filter(ImageFilter.SHARPEN)
        filter(ImageFilter.MaxFilter)
        filter(ImageFilter.MedianFilter)
        filter(ImageFilter.MinFilter)
        filter(ImageFilter.ModeFilter)
        filter(ImageFilter.GaussianBlur)
        filter(ImageFilter.GaussianBlur(5))
        filter(ImageFilter.BoxBlur(5))
        filter(ImageFilter.UnsharpMask)
        filter(ImageFilter.UnsharpMask(10))

        self.assertRaises(TypeError, filter, "hello") 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:32,代碼來源:test_image_filter.py

示例3: test_filter_api

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import UnsharpMask [as 別名]
def test_filter_api(self):

        test_filter = ImageFilter.GaussianBlur(2.0)
        i = im.filter(test_filter)
        self.assertEqual(i.mode, "RGB")
        self.assertEqual(i.size, (128, 128))

        test_filter = ImageFilter.UnsharpMask(2.0, 125, 8)
        i = im.filter(test_filter)
        self.assertEqual(i.mode, "RGB")
        self.assertEqual(i.size, (128, 128)) 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:13,代碼來源:test_imageops_usm.py

示例4: test_usm_formats

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import UnsharpMask [as 別名]
def test_usm_formats(self):

        usm = ImageFilter.UnsharpMask
        self.assertRaises(ValueError, im.convert("1").filter, usm)
        im.convert("L").filter(usm)
        self.assertRaises(ValueError, im.convert("I").filter, usm)
        self.assertRaises(ValueError, im.convert("F").filter, usm)
        im.convert("RGB").filter(usm)
        im.convert("RGBA").filter(usm)
        im.convert("CMYK").filter(usm)
        self.assertRaises(ValueError, im.convert("YCbCr").filter, usm) 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:13,代碼來源:test_imageops_usm.py

示例5: test_usm_accuracy

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import UnsharpMask [as 別名]
def test_usm_accuracy(self):

        src = snakes.convert('RGB')
        i = src.filter(ImageFilter.UnsharpMask(5, 1024, 0))
        # Image should not be changed because it have only 0 and 255 levels.
        self.assertEqual(i.tobytes(), src.tobytes()) 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:8,代碼來源:test_imageops_usm.py

示例6: unsharp_mask

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import UnsharpMask [as 別名]
def unsharp_mask(src, p):
    if np.random.uniform() < p:
        tmp = Image.fromarray(src)
        percent = random.randint(10, 90)
        threshold = random.randint(0, 5)
        mask = ImageFilter.UnsharpMask(percent=percent, threshold=threshold)
        dst = np.array(tmp.filter(mask), dtype=np.uint8)
        return dst
    else:
        return src 
開發者ID:tsurumeso,項目名稱:waifu2x-chainer,代碼行數:12,代碼來源:data_augmentation.py


注:本文中的PIL.ImageFilter.UnsharpMask方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。