예제 #1
0
def superpixel(image_pk,test_pk,grid_size,distance,sigma):
    image_selected = Imagen.objects.get(pk=image_pk)
    image_for_pil = Image.open("."+image_selected.archivo.url)
    maxsize = (200, 200)
    thumbnail = grid.thumbnail("."+image_selected.archivo.url,(200,200))
    image_for_pil.thumbnail(maxsize, PIL.Image.ANTIALIAS)

    test = Prueba.objects.get(pk=test_pk)
    op = np.load(test.op_file)
    sp = np.load(test.sp_file)
    ca = np.load(test.ca_file)
    mean_shift_result = ms.MeanShiftResult(op,sp,ca)

    x_y_c = fe.cambia_formato(mean_shift_result)
    foreground_estimator = fe.foreground_estimation(x_y_c)
    classified = foreground_estimator.classify_points()
    print(classified)
    energy = eg.energy_generation(classified,np.shape(np.array(image_for_pil)),int(grid_size),nombre_salida="./imagenes/tmp/eg/transformacion_distancia_{}.png".format(image_selected.nombre),nombre_grid_interseccion_figura="grid_interseccion_figura.png",nombre_morfologia="morfologia.png")
    energy_map = energy.hacer_saliency_map()

    s = spx.superpixel(nombre_thumbnail=thumbnail,profundidad=energy_map,nombre_salida="./imagenes/tmp/spx/superpixel_{}.png".format(image_selected.nombre))
    s.hacer_superpixel()

    fil = open(s.nombre_salida, 'rb')
    rd = fil.read()
    content_file = ContentFile(rd)
    content_file.name="./edited/edited.png"
    image_edited = Imagen(nombre=energy.nombre_salida,archivo=content_file,formato="png",editada=True)
    image_edited.save()
    test.resultado=image_edited
    test.save()

    return image_edited.archivo.url
예제 #2
0
def adaptive_bokeh(image_pk,test_pk,grid_size,distance,sigma):
    image_selected = Imagen.objects.get(pk=image_pk)
    image_for_pil = Image.open("."+image_selected.archivo.url)
    maxsize = (200, 200)
    thumbnail = grid.thumbnail("."+image_selected.archivo.url,(200,200))
    image_for_pil.thumbnail(maxsize, PIL.Image.ANTIALIAS)

    test = Prueba.objects.get(pk=test_pk)

    d = bokeh.bokeh("."+image_selected.archivo.url,thumbnail,"./imagenes/tmp/spx/superpixel_{}.png".format(image_selected.nombre))
    d.difuminacion_gaussiana_fondo()

    fil = open("./imagenes/tmp/gauss/gauss_adaptativo.png", 'rb')
    rd = fil.read()
    content_file = ContentFile(rd)
    content_file.name="./edited/edited.png"
    image_edited = Imagen(nombre="gauss_adaptativo_{}.png".format(image_selected.nombre),archivo=content_file,formato="png",editada=True)
    image_edited.save()
    test.resultado=image_edited
    test.save()

    return image_edited.archivo.url
예제 #3
0
import foreground_estimation
from scipy.cluster.vq import kmeans,vq,whiten
import grid_utils as grid
#Extraer los puntos de la imagen que tienen intersección con el Grid
#ORIGINALMENTE ERAN 100
GAUSSIAN_KERNELS = [1, 3, 5]


nombre_imagen = "krapfen.jpg"

#RGB = np.array(io.imread("jakob-nielsen-thumbs-up.jpg"))

#RGB2 = PIL.Image.open("angel.jpg")
#RGB2 = RGB2.filter(ImageFilter.GaussianBlur(GAUSSIAN_KERNELS[1]))

thumbnail = grid.thumbnail(nombre_imagen,(200,200))

RGB = np.array(io.imread(thumbnail))
LISTA_PUNTOS = grid.puntos_interseccion(RGB, 19)
print(np.shape(RGB))
print("Numero de puntos: {}".format(len(LISTA_PUNTOS)))
import mean_shift_epanechnikov as ms
#Utilizar el algoritmo meanshift sobre la lista de puntos. 5 Dimensiones + 1 de la clasificación
mean_shifter = ms.MeanShift(kernel = 'epanechnikov_kernel')
#ORIGINALMENTE ERA [0.2,0.2]
mean_shift_result = mean_shifter.cluster(LISTA_PUNTOS,40, kernel_bandwidth = [100,128])

# Muestra las asignaciones de cada uno de los puntos
cluster_assignments = mean_shift_result.cluster_ids
print(cluster_assignments)
print(mean_shift_result.original_points)