Пример #1
0
def init_api(app):
    """
    Helper for initialization of api.
    :param app: Flask
    :return: None
    """
    locations.create(app)
    records.create(app)
    users.create(app)
    image.create(app)
    ratings.create(app)
Пример #2
0
def mult(img, s):
    w, h = len(img[0]), len(img)
    imgRed = red(img,s)
    wr, hr = len(imgRed[0]), len(imgRed)
    im.create(w, h,(0,0,0))
    x, y = 0, 0
    for xx in range(s):
        y = 0
        for yy in range(s):
            img = rectCopy(img, imgRed, x, y)
            y = y + hr
        x = x + wr
    return img
Пример #3
0
def red(img, s):
    w, h = len(img[0]), len(img)
    wr = round(w/s)
    hr = round(h/s)
    imgR = im.create(wr, hr, (0,0,0))
    newColor = [0, 0, 0]

    # PER OGNI PIXEL RIDOTTO DELLA RIGA
    for x in range(wr):
        #PER OGNI PIXEL RIDOTTO DELLA COLONNA
        for y in range(hr):
            #CREO UN COLORE CHE E' IL COLORE MEDIO DI S^2 PIXELS
            newColor = [0, 0, 0]
            #PER LE RIGHE DI X DELL'IMMAGINE ORIGINALE
            for px in range(s):
                    #PER LE RIGHE DI Y DELL'IMMAGINE ORIGINALE
                    for py in range(s):
                        #SOMMO TUTTI I VALORI DEI TRE CANALI RGB
                        for k in range(3):
                            newColor[k] += img[y*s+py][x*s+px][k]

            #CALCOLO IL VALORE MEDIO
            for k in range(3):
                newColor[k] = min(max(round(newColor[k]/(s*s)), 0), 255)
            #print(newColor)
            #COMPRIMO S^2 PIXELS IN UN SOLO PIXEL!
            imgR[y][x] = tuple(newColor)

    return imgR
Пример #4
0
def edge(img, t, bg):
    w, h = len(img[0]), len(img)
    imgR = im.create(w, h, (0,0,0))
    def isContour(x, y):
        #GET THE PIXEL SUM OF COLORS
        pixelVal = (sum(img[y][x]) / 765)
        for dy in range(-1, 2):
            for dx in range(-1, 2):
                xx = x + dx
                yy = y + dy
                #same pixel check skip, could also be left
                if xx == x and yy == y:
                    continue
                #if index is negative skip this instruction
                if not (0 <= xx < w) or not (0 <= yy < h):
                    continue

                pixelVal2 = (sum(img[yy][xx]) / 765)
                if pixelVal2 < pixelVal:
                    if abs(pixelVal - pixelVal2) >= t:
                        return True
        return False



    for x in range(0, w, 1):
        for y in range(0, h, 1):
            if isContour(x, y):
                imgR[y][x] = (0,0,0)
            elif bg is not None:
                imgR[y][x] = bg
            else:
                imgR[y][x] = img[y][x]

    return imgR
Пример #5
0
def rot90(img):
    w, h = len(img[0]), len(img)
    imgR = im.create(h, w, (0,0,0))
    for y in range(h):
        for x in range(w):
            imgR[-1*x][y] = img[y][x]
    return imgR
Пример #6
0
def copyPiece(img, s, dx, dy):
    w, h = len(img[0]), len(img)
    wr = round(w/s)
    hr = round(h/s)
    imgR = im.create(wr, hr, (0,0,0))
    # PER OGNI PIXEL RIDOTTO DELLA RIGA
    for x in range(wr):
        #PER OGNI PIXEL RIDOTTO DELLA COLONNA
        for y in range(hr):
            imgR[y][x] = img[dy+y][dx+x]
    return imgR
Пример #7
0
def contrast(img, c):
    '''Ritorna una nuova immagine che e' l'immagine img con contrasto modificato in base al parametro c: 
    se c = 1.0, non c'e' modifica, se c < 1.0 il contrasto e' diminuito tanto piu' c e' vicino a 0,
    se c > 1.0 il contrasto e' aumentato tanto piu' c e' grande'''
    w, h = len(img[0]), len(img)
    ret = im.create(w, h, (0,0,0))
    for y in range(h):
        for x in range(w):
            r, g, b = img[y][x]
            ret[y][x] = (_c(r,c), _c(g,c), _c(b,c))
    return ret
Пример #8
0
def patchwork(img, s):
    w, h = len(img[0]), len(img)
    random.seed(0)
    wr, hr = round(w/s), round(h/s)
    im.create(w, h,(0,0,0))
    x, y = 0, 0
    for xx in range(s):
        y = 0
        for yy in range(s):
            imgRed = copyPiece(img, s, x, y)
            sample = random.sample([1,2,3,4,5], 1)
            if sample[0] == 2:
                imgRed = contrast(imgRed, 0.5)
            if sample[0] == 3:
                imgRed = contrast(imgRed, 2.0)
            if sample[0] == 4:
                imgRed = invert(imgRed)
            if sample[0] == 5:
                imgRed = gray(imgRed)                
            img = rectCopy(img, imgRed, x, y)
            y = y + hr
        x = x + wr
    return img
Пример #9
0
def mosaic_average(fname_in, fname_out, s):
    '''Ritorna una nuova immagine ottenuta dividendo
    l'immagine img in quadrati di lato s e riempendo
    ogni quadratino con la media dei suoi colori.'''
    img = image.load(fname_in)
    w, h = len(img[0]), len(img)
    ret = image.create(w, h, (0,0,0))
    # itera sui possibili quadrati
    for jj in range(h//s):
        for ii in range(w//s):
            # colore medio dell'immagine
            c = average(img,ii*s,jj*s,s,s)
            draw_quad(ret, ii*s, jj*s, s, s, c)
    image.save(fname_out, ret)
Пример #10
0
def mosaic_nearest(fname_in, fname_out, s):
    """Ritorna una nuova immagine ottenuta dividendo
    l'immagine img in quadrati di lato s e riempendo
    ogni quadrato con il colore del suo angolo in
    alto a sinistra"""
    img = image.load(fname_in)
    w, h = len(img[0]), len(img)
    ret = image.create(w, h, (0,0,0))
    # itera sui possibili quadrati
    for jj in range(h//s):
        for ii in range(w//s):
            # colore dell'angolo in alto-sinistra
            c = img[jj*s][ii*s]
            draw_quad(ret, ii*s, jj*s, s, s, c)
    image.save(fname_out, ret)
Пример #11
0
def upload():
    galleries = sqlite_interface.getCurrentGalleries()
    if request.method == "GET":
        return render_template("upload.html",
                               galleryNames = galleries,
                               galleries = galleries)
    else:
        print "PROCESSING IMAGE"
        processedProperly = image.create(request.form,
                                         galleries,
                                         request.files['file'],
                                         date.today().year)
        print "FINISHED PROCESSING"
        if processedProperly != True:
            render_template("error.html",
                            error = processedProperly,
                            galleryNames = galleries)
        return redirect(url_for("currentGallery", galleryName = request.form['Gallery']))
Пример #12
0
def backfill(year):
    galleries = sqlite_interface.getVisibleByYear(year)
    print "YEAR: " + year
    if request.method == "GET":
        return render_template("upload.html",
                               gallerynames = galleries,
                               galleries = galleries,
                               yr = year)
    else:
        processedProperly = image.create(request.form,
                                     galleries,
                                     request.files['file'],
                                     year)
        if processedProperly != True:
            render_template("error.html",
                            error = processedProperly,
                            galleryNames = galleries)
        return redirect(url_for("previousGallery",
                                galleryName = request.form['Gallery'],
                                year = year))
Пример #13
0
def mosaic_size(fname_in, fname_out, s):
    '''Ritorna una nuova immagine ottenuta dividendo
    l'immagine img in quadratini di lato s e
    disegnando all'interno di ognuno di essi,
    su sfondo nero, un quadratino centrale bianco di
    lato proporzionale alla luminosità media del
    corrispondente quadratino'''
    img = image.load(fname_in)
    w, h = len(img[0]), len(img)
    ret = image.create(w, h, (0,0,0))
    # itera sui possibili quadrati
    for jj in range(h//s):
        for ii in range(w//s):
            # colore medio dell'immagine
            c = average(img,ii*s,jj*s,s,s)
            # lato del quadratino bianco
            r = round(s*(c[0]+c[1]+c[2])/(3*255))
            draw_quad(ret, ii*s+(s-r)//2,
                jj*s+(s-r)//2, r, r, (255,255,255))
    image.save(fname_out, ret)
Пример #14
0
def edging(fname_in, fname_out, n_iter):
    img = image.load(fname_in)
    width, height = len(img[0]), len(img)
    img_out = image.create(width, height, (0, 0, 0))
    pix_hood = ((-1, -1), (0, -1), (1, -1), (1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0))
    for _ in range(n_iter):
        for row in range(height):
            for col in range(width):
                color = img[row][col]
                max_distance = 0
                max_color = color
                for x, y in pix_hood:
                    row_hood = y + row
                    col_hood = x + col
                    if not (0 <= col_hood < width and 0 <= row_hood < height):
                        continue
                    color_hood = img[row_hood][col_hood]
                    distance = calc_dist(color, color_hood)
                    if distance > max_distance:
                        max_distance = distance
                        max_color = color_hood
                img_out[row][col] = max_color
        img, img_out = img_out, img
    image.save(fname_out, img)
Пример #15
0
import cv2

import image
import paint
import seismic
from data import *

if __name__ == '__main__':
    _seismic = image.load("SeismicScaled.jpg")
    _transformation = seismic.parse_transformation(_seismic, 15 * 1000, int(2.5 * 1000), 10)

    _geo = Geo(Well.generate_left(), Well.generate_right(), _transformation.width, _transformation.left_well_intent, _transformation.right_well_intent)
    _match = Match.generate()
    _image = image.create(_geo.height, _geo.width)

    # image.show(_seismic)

    paint.wells(_image, _geo)
    paint.lines(_image, _geo, _match)
    paint.fill(_image, _geo, _match)

    # _image1 = _image.copy()
    # paint.fill(_image1, _geo, _match)
    # paint.wells(_image1, _geo)
    #
    # _, _image2 = cv2.threshold(_image1, 127, 255, cv2.THRESH_BINARY)
    #
    # print("Showing ...")
    # image.show(_image, _image1, _image2)

    _result = image.create(_transformation.height, _transformation.width)