Ben Peleg | 2018 |

LinkedIn_logo_initials.png

Coding Overview

Manus was written in Python and makes use of the following external libraries -

General libraries

sys

collections

os

time

datetime

math

numpy

operator

random

langdetect

Visual libraries

PIL

turtle

Metadata libraries

exifread

MS Office libraries

docx

docx.shared

 --> Inches

 --> Pt

 --> Length

 --> RGBColor

csv

Web libraries

urllib

requests

json

utilizes Google Maps API

Analytical Function - Example

def FindBrightnessInFolder(path, PhotoAmount=1500, ColorLimit=3):

    """ Receives a path for a folder of images, a top limit for the amount of images for analysis and a top limit
    for the amount of colors for analysis in each image. Returns a list of the different brightness levels in it
    graded 0-9. The list is sorted in ascending order.
    """

    # Consts
    counter = 1
    MostDominantList = []
    BrightnessDic = {}
    # Load images
    images = LoadImages(path)
    # Limit run to the chosen amount of images for analysis
    images = ReduceListToAmount(images, PhotoAmount)
    # Find most dominant colors for each image
    for image in images:
        print("Image", image[0], " - ", counter)
        MostDominant = MostDominantColors(image[1], ColorLimit, False)
        MostDominantList.append(MostDominant)
        counter += 1
    # Find brightness levels based on found dominant colors
    for image in MostDominantList:
        brightness = DetermineBrightness(image)
        if brightness in BrightnessDic.keys():
            BrightnessDic[brightness] += 1
        else:
            BrightnessDic[brightness] = 1
    # Percentagize results
    for key in BrightnessDic.keys():
        BrightnessDic[key] = (BrightnessDic[key]*100)/len(images)
    # Sort dictionary
    BrightnessDic = collections.OrderedDict(sorted(BrightnessDic.items(), key = lambda i: i[1], reverse = True))

‚Äč

    return BrightnessDic

>>> FindBrightnessInFolder("C:\\Users\\Ben\\Pictures\\Example_Batch_-_bpeleg_IG_account\\", 20, 3)

OrderedDict([(1, 5.0), (2, 25.0), (3, 10.0), (4, 15.0), (5, 10.0), (6, 15.0), (7, 15.0), (8, 5.0)])

Visual Function - Example

def VisBrighterOrDarker(path, PhotoAmount=1500, ColorLimit=3):

    """ Receives a path for a folder of images, a top limit for the amount of images for analysis and a top limit
    for the amount of colors for analysis in each image. Then, it creates a diagram that visualizes the analysis
    according to the 10 levels of brightness in predetermined colors.
    """

    # Consts
    ColorDic = {0:"101040", 1:"2b2b4e", 2:"45455c", 3:"60606b", 4:"7a7a79",\
                       5:"959587", 6:"afaf95", 7:"cacaa4", 8:"e4e4b2", 9:"ffffc0"}
    filename = "Brightness Diagram"
    # Turtle set-up
    T = turtle.Turtle()
    turtle.colormode(255)
    window = turtle.Screen()
    # Circles location and size
    radius = 250
    TempRadius = radius
    x = 0
    y = 0
    CircleCount = 0
    # Find brightness levels     
    BrightnessDic = FindBrightnessInFolder(path, PhotoAmount, ColorLimit)
    # Draw brightness diagram
    for level in range(10):
        if level in BrightnessDic.keys():
            print("Drawing brightness level", level)
            T.penup
            T.pencolor("")
            T.goto(x,y+TempRadius)
            T.pendown()
            T.begin_fill()
            T.circle(-TempRadius)
            for i in range(3):
                Red = int(ColorDic[level][0:2], 16)
                Green = int(ColorDic[level][2:4], 16)
                Blue = int(ColorDic[level][4:6], 16)
            T.color(Red, Green, Blue)
            T.end_fill()
            T.penup
            T.hideturtle
            TempRadius -= radius*BrightnessDic[level]/100
            print("New radius:",TempRadius,"\n")
    # Save diagram to origin folder
    print("Filename: ", filename, ".eps\n")
    print("Saving image to ", path, "\n")
    os.chdir(path)
    Screenshot = turtle.getscreen()
    Screenshot.getcanvas().postscript(file=filename)
    print("Saved!")

>>> VisBrighterOrDarker("C:\\Users\\Ben\\Pictures\\Example_Batch_-_bpeleg_IG_account\\", 20, 3)

For full portfolio work please contact through the "Contact" page or at bpeleg@gmail.com