Ejemplo n.º 1
0
def find():
    global clipboard_image
    try:
        img = LAYERS_DICT['image']
        img = img.resize((root.winfo_screenwidth(), root.winfo_screenheight()))
        img = img.filter(ImageFilter.FIND_EDGES())
        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 NameError:
        pass
    try:
        clipboard_image = ImageGrab.grabclipboard()
        clipboard_image = clipboard_image.resize(
            (root.winfo_screenwidth(), root.winfo_screenheight()))
        clipboard_image = clipboard_image.filter(ImageFilter.FIND_EDGES())
        canvas.image_tk = ImageTk.PhotoImage(clipboard_image)
        image_id = LAYERS_DICT['canvas'].create_image(0, 0, anchor=NW)
        LAYERS_DICT['canvas'].itemconfigure(image_id, image=canvas.image_tk)
        LAYERS_DICT['image'] = clipboard_image
        LAYERS_DICT['img'] = image_id
    except Exception:
        pass
    if SAVED == False:
        root.title('Shape Editor • Unsaved')
    else:
        root.title(f'Shape Editor • {str(root.filename)} •')
Ejemplo n.º 2
0
def augment_data(label_path):
	label = label_path.split('/')[-1]
	if label == "0":
		files = os.listdir(label_path)
		for file in files:
			file_name = file.split(".")[0]
			file_ext = file.split(".")[1]
			img = Image.open(label_path + "/" + file)
			img_rotate_120 = img.rotate(120)
			img_rotate_120.save(label_path + "/" + file_name + "rotate_120." + file_ext)
			img_enhance = img.filter(ImageFilter.EDGE_ENHANCE())
			img_edge = img.filter(ImageFilter.FIND_EDGES())
			img_enhance.save(label_path + "/" + file_name + "enhance." + file_ext)
			img_edge.save(label_path + "/" + file_name + "edge." + file_ext)
	if label == "1":
		files = os.listdir(label_path)
		for file in files:
			file_name = file.split(".")[0]
			file_ext = file.split(".")[1]
			img = Image.open(label_path + "/" + file)
			img_rotate_120 = img.rotate(120)
			img_rotate_120.save(label_path + "/" + file_name + "rotate_120." + file_ext)
			img_enhance = img.filter(ImageFilter.EDGE_ENHANCE())
			img_edge = img.filter(ImageFilter.FIND_EDGES())
			img_enhance.save(label_path + "/" + file_name + "enhance." + file_ext)
			img_edge.save(label_path + "/" + file_name + "edge." + file_ext)
Ejemplo n.º 3
0
def edgestext():
    img = Image.open("lionimg.jpg")
    img.show()
    img = img.filter(ImageFilter.FIND_EDGES())  # [-1-1-1-18-1-1-1-1]
    img.save("edgesimg.jpg")
    img.show()
    pass
def augment_data(label_path):
	label = label_path.split('/')[-1]
	if label == "120":
		files = os.listdir(label_path)
		for file in files:
			file_name = file.split(".")[0]
			file_ext = file.split(".")[1]
			img = Image.open(label_path + "/" + file)
			img_rotate_90 = img.rotate(90)
			img_rotate_90.save(label_path + "/" + file_name + "rotate_90." + file_ext)
	if label == "Stop":
			files = os.listdir(label_path)
			for file in files:
				file_name = file.split(".")[0]
				file_ext = file.split(".")[1]
				img = Image.open(label_path + "/" + file)
				img_rotate_90 = img.rotate(90)
				img_rotate_120 = img.rotate(120)
				img_rotate_90.save(label_path + "/" + file_name + "rotate_90." + file_ext)
				img_rotate_120.save(label_path + "/" + file_name + "rotate_120." + file_ext)
	if label == "Right":
			files = os.listdir(label_path)
			for file in files:
				file_name = file.split(".")[0]
				file_ext = file.split(".")[1]
				img = Image.open(label_path + "/" + file)
				img_enhance = img.filter(ImageFilter.EDGE_ENHANCE())
				img_edge = img.filter(ImageFilter.FIND_EDGES())
				img_enhance.save(label_path + "/" + file_name + "enhance." + file_ext)
				img_edge.save(label_path + "/" + file_name + "edge." + file_ext)
	if label == "Left":
			files = os.listdir(label_path)
			for file in files:
				file_name = file.split(".")[0]
				file_ext = file.split(".")[1]
				img = Image.open(label_path + "/" + file)
				img_enhance = img.filter(ImageFilter.EDGE_ENHANCE())
				img_edge = img.filter(ImageFilter.FIND_EDGES())
				img_gaussian = img.filter(ImageFilter.GaussianBlur(radius = 3))
				img_invert = ImageChops.invert(img)
				img_enhance.save(label_path + "/" + file_name + "enhance." + file_ext)
				img_edge.save(label_path + "/" + file_name + "edge." + file_ext)
				img_gaussian.save(label_path + "/" + file_name + "gaussian." + file_ext)
				img_invert.save(label_path + "/" + file_name + "invert." + file_ext)
Ejemplo n.º 5
0
def edges():
    #img=Image.open("imgsayphoto.jpg")
    speak("may I get the image : ")
    img1 = takecommand().lower()
    if "photo" in img1:
        img = Image.open("photo.jpg")
        img.show()
        img = img.filter(ImageFilter.FIND_EDGES())  #[-1-1-1-18-1-1-1-1]
        img.save("edgesimg.jpg")
        img.show()
    else:
        speak("sorry")
    pass
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
def process_image_findedges(img_name):
    img = Image.open(pathlib.Path(img_name))
    img = img.filter(ImageFilter.FIND_EDGES())
    img.save(export_folder + "/FindEdges_" + format(Path(img_name).stem) +
             image_extension)
    print("FindEdges Filter added successfully")
Ejemplo n.º 8
0
import PIL
from PIL import Image, ImageStat, ImageFilter

im = Image.open('brain_enhanced_4.jpg')
im1 = im.filter(ImageFilter.FIND_EDGES())
im1.save('brain_sobel_enhanced.jpg')

Ejemplo n.º 9
0
#!/usr/python2.7.12
#-*-coding:Latin-1 -*
from PIL import Image
from PIL import ImageFilter
from PIL import ImageOps
import numpy as np
import matplotlib.pyplot as plt

img = Image.open('MissionU1.pbm')
#img.show()
img = img.filter(ImageFilter.FIND_EDGES())

for x in range(img.size[0]):
    for y in range(img.size[1]):
        pixel = img.getpixel((x, y))
        if pixel > 77.5:
            img.putpixel((x, y), 255)
        else:
            img.putpixel((x, y), 0)

img.save("u1Contour.pbm")
img = img.filter(ImageFilter.MaxFilter(
    3))  #remplace le pixel du milieu par la plus haute intensité
img.show()
img = img.filter(ImageFilter.SMOOTH)  #lisse l'image
#img.show()
img = img.filter(ImageFilter.MinFilter(3))  #inverse max
#img.show()
img = img.filter(ImageFilter.DETAIL)  #accentue les details
img.show()
img.save("finalimage.pbm")
Ejemplo n.º 10
0
 def export(self, r=10):
     sharp = Image.new('RGB', (self.w, self.h), (127, 127, 127))
     for name, pos1, pos2, scale in self.objects:
         if name == 'truck':
             ox, oy = pos2
             dist = ((pos1[0] - pos2[0])**2 + (pos1[1] - pos2[1])**2)**0.5
             for n in range(int(dist / scale), 0, -1):
                 x = int(pos1[0] + (pos2[0] - pos1[0]) / (dist / scale) * n)
                 y = int(pos1[1] + (pos2[1] - pos1[1]) / (dist / scale) * n)
                 dir = math.degrees(math.atan2(ox - x, oy - y))
                 figure = Image.open(
                     os.path.dirname(__file__) + '/samples/truck_gray.png')
                 sharp.paste(
                     figure.rotate(dir - 90,
                                   fillcolor=(127, 127, 127)).resize(
                                       (int(scale * 2), int(scale * 2))),
                     (int(x - scale), int(y - scale)))
                 ox, oy = x, y
         if name == 'footprints':
             foot = 0
             ox, oy = pos2
             dist = ((pos1[0] - pos2[0])**2 + (pos1[1] - pos2[1])**2)**0.5
             for n in range(int(dist / scale), 0, -1):
                 if foot == 1:
                     figure = Image.open(
                         os.path.dirname(__file__) +
                         '/samples/footprint1_gray.png')
                     foot = 0
                 else:
                     figure = Image.open(
                         os.path.dirname(__file__) +
                         '/samples/footprint2_gray.png')
                     foot = 1
                 x = int(pos1[0] + (pos2[0] - pos1[0]) / (dist / scale) * n)
                 y = int(pos1[1] + (pos2[1] - pos1[1]) / (dist / scale) * n)
                 dir = math.degrees(math.atan2(ox - x, oy - y))
                 sharp.paste(
                     figure.rotate(dir - 90,
                                   fillcolor=(127, 127, 127)).resize(
                                       (int(scale), int(scale))),
                     (int(x - scale / 2), int(y - scale / 2)))
                 ox, oy = x, y
     sharp = sharp.filter(ImageFilter.GaussianBlur(radius=int(r / 4)))
     guassian = sharp.filter(ImageFilter.GaussianBlur(radius=int(r / 2)))
     white = ImageEnhance.Brightness(
         sharp.filter(ImageFilter.GaussianBlur(radius=int(r * 2))).filter(
             ImageFilter.FIND_EDGES())).enhance(40)
     white = ImageEnhance.Brightness(
         white.filter(ImageFilter.GaussianBlur(radius=r))).enhance(2)
     out = Image.blend(Image.blend(sharp, guassian, 0.9), white, 0.25)
     b = Image.new('RGB', (self.w, self.h), (127, 127, 127))
     p = white.load()
     d = ImageDraw.Draw(b)
     for x in range(self.w):
         for y in range(self.h):
             if p[x, y][0] > 1 and random.randint(1, 500) == 10:
                 polygon = []
                 size = random.randint(r // 2, r * 2)
                 for f in range(3):
                     polygon.append((random.randint(x - size, x + size),
                                     random.randint(y - size, y + size)))
                 d.polygon(polygon, fill=(size * 40 - 250, ) * 4)
     b = b.filter(ImageFilter.GaussianBlur(radius=5))
     out = Image.blend(out, b, 0.25)
     out.save(os.path.dirname(__file__) + '/snowDisplacement.png')
Ejemplo n.º 11
0
def find_edges(image: Image.Image) -> Image.Image:
    return _apply_filter(image, ImageFilter.FIND_EDGES())
Ejemplo n.º 12
0
from PIL import Image
from PIL import ImageFilter
from PIL import ImageOps
import numpy as np
import matplotlib.pyplot as plt

U2_surface = Image.open('U2_surface.pbm')

U2_surface = U2_surface.filter(ImageFilter.FIND_EDGES())
nblines = U2_surface.size[1]
nbrows = U2_surface.size[0]

i = 0
j = 0

while i < nbrows:
    while j < nblines:
        pixels = U2_surface.getpixel((i, j))
        if pixels > 190:
            U2_surface.putpixel((i, j), 0)
        else:
            U2_surface.putpixel((i, j), 255)

        j += 1
    i += 1
    j = 0

#U2_surface = U2_surface.filter(ImageFilter.MedianFilter(3))

U2_surface.show()