def without_color(): global clipboard_image try: img = LAYERS_DICT['image'] img = img.resize((root.winfo_screenwidth(), root.winfo_screenheight())) img = img.filter(ImageFilter.CONTOUR()) canvas.image_tk = ImageTk.PhotoImage(img) image_id = LAYERS_DICT['canvas'].create_image(0, 0, anchor=NW) LAYERS_DICT['canvas'].itemconfigure(image_id, image=canvas.image_tk) LAYERS_DICT['image'] = img LAYERS_DICT['img'] = image_id except: pass try: clipboard_image = ImageGrab.grabclipboard() clipboard_image = clipboard_image.resize( (root.winfo_screenwidth(), root.winfo_screenheight())) clipboard_image = clipboard_image.filter(ImageFilter.CONTOUR()) canvas.image_tk = ImageTk.PhotoImage(clipboard_image) image_id = LAYERS_DICT['canvas'].create_image(0, 0, anchor=NW) f = LAYERS_DICT['canvas'].itemconfigure(image_id, image=canvas.image_tk) LAYERS_DICT['image'] = clipboard_image LAYERS_DICT['img'] = image_id except: pass if SAVED == False: root.title('Shape Editor • Unsaved') else: root.title(f'Shape Editor • {str(root.filename)} •')
def _apply_filters(self, img): ''' ''' if self.color.get(): filt = ImageFilter.UnsharpMask(radius=25, percent=200, threshold=30) img = img.filter(filt) if self.edge.get(): #img = img.convert("LA") #filt = ImageFilter.SHARPEN() #img = img.filter(filt) #enh = ImageEnhance.Brightness(img) #img = enh.enhance(0.25) enh = ImageEnhance.Contrast(img) image = enh.enhance(1.5) #enh = ImageEnhance.Brightness(img) #img = enh.enhance(0.75) filt = ImageFilter.UnsharpMask(radius=50, percent=150, threshold=30) img = img.filter(filt) filt = ImageFilter.EDGE_ENHANCE_MORE() img = img.filter(filt) filt = ImageFilter.CONTOUR() img = img.filter(filt) return img
def update_image(original, blur, contrast, emboss, contour, flipx, flipy): global image image = original.filter(ImageFilter.GaussianBlur(blur)) image = image.filter(ImageFilter.UnsharpMask(contrast)) if emboss: image = image.filter(ImageFilter.EMBOSS()) if contour: image = image.filter(ImageFilter.CONTOUR()) if flipx: image = ImageOps.mirror(image) if flipy: image = ImageOps.flip(image) bio = BytesIO() image.save(bio, format='PNG') window['-IMAGE-'].update(data=bio.getvalue())
def applyFilter(imgObj, outpLoc, filterType, customArgs=[0]): """Aplly filter to an image, if arguments arr required use the list customArgs Help from: https://hhsprings.bitbucket.io/docs/programming/examples/python/PIL/ImageFilter.html""" # format the output dir: if it doesnt exist create it if os.path.isdir(outpLoc): pass else: os.makedirs(outpLoc) # check if the imgObj is a thumbnail already if "filtr" in imgObj.fileName: # don't do anything return False # apply filter based on filter type: # open image file im = Image.open(imgObj.fileLOC) # apply filter based on filterType argument if filterType == "BLUR": currImFltr = im.filter(ImageFilter.BoxBlur(customArgs[0])) elif filterType == "CONTOUR": currImFltr = im.filter(ImageFilter.CONTOUR()) elif filterType == "DETAIL": currImFltr = im.filter(ImageFilter.DETAIL()) elif filterType == "EDGE_ENHANCE": currImFltr = im.filter(ImageFilter.EDGE_ENHANCE_MORE()) elif filterType == "EMBOSS": currImFltr = im.filter(ImageFilter.EMBOSS()) elif filterType == "FIND_EDGES": currImFltr = im.filter(ImageFilter.FIND_EDGES()) elif filterType == "UNSHARP_MASK": currImFltr = im.filter( ImageFilter.UnsharpMask(radius=customArgs[0], percent=customArgs[1], threshold=customArgs[2])) else: print(f"no filter for filter type: {filterType}") return False # save filtered image currImFltr.save(outpLoc + "filtr-" + filterType + "-" + imgObj.fileName)
def process_image_contour(img_name): img = Image.open(pathlib.Path(img_name)) img = img.filter(ImageFilter.CONTOUR()) img.save(export_folder + "/Contour_" + format(Path(img_name).stem) + image_extension) print("Contour Filter added successfully")
def contour(image: Image.Image) -> Image.Image: return _apply_filter(image, ImageFilter.CONTOUR())