Python PIL.ImageFilter.UnsharpMask() Examples
The following are 6
code examples of PIL.ImageFilter.UnsharpMask().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
PIL.ImageFilter
, or try the search function
.
Example #1
Source File: test_image_filter.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
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")
Example #2
Source File: textcaps_emnist_bal.py From textcaps with MIT License | 5 votes |
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
Example #3
Source File: test_imageops_usm.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
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))
Example #4
Source File: test_imageops_usm.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #5
Source File: test_imageops_usm.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
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())
Example #6
Source File: data_augmentation.py From waifu2x-chainer with MIT License | 5 votes |
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