Example #1
0
        im)
    rango_busqueda = [float(i) / len(accum_i) for i in range(len(accum_i))]

    def w_dot(r):
        # La intensidad buscada es la de la acumulada.
        si = accum_s[side_by_side.search_not_exact(r[1], rango_busqueda)]
        return [r[0], si, r[2]]

    ret = im.copy()
    for i in range(ret.shape[0]):
        for j in range(ret.shape[1]):
            ret[i][j] = w_dot(ret[i][j])
    return ret


def transformacion_puntual(im, f):
    ret = im.copy()
    for i in range(ret.shape[0]):
        for j in range(ret.shape[1]):
            ret[i][j] = f(ret[i][j])
    return ret


im1 = np.asarray(Image.open(argv[1]).convert('RGB'))
im2 = utils.to_hsi(im1)
im3 = uniform_hist(im2)
# im3 = transformacion_puntual(im2, umbral05)
im4 = utils.to_rgb(im3)
side_by_side.sbys_histogram([im1, im2, im3, im4], ['rgb', 'hsi', 'hsi', 'rgb'],
                            argv=argv[2] if len(argv) > 2 else None)
            int(w * L - 0.5)) / (1.0 + lam) + lam * float(r) / (1.0 + lam)

    f = np.vectorize(w_dot)
    return f(im)


im2 = np.uint8(uniform_hist(im1))
im3 = np.uint8(uniform_hist(uniform_hist(im1)))
im4 = np.uint8(naive_hist(im1))
im5 = np.uint8(normal_hist(im1))
im6 = np.uint8(lambda_hist(im1, 2))
im7 = np.uint8(lambda_hist(im1, 5))
im8 = np.uint8(lambda_hist(im1, 10))

if argv[2] == '6':
    side_by_side.sbys_histogram([im1, im4], ['original', 'naive equalization'],
                                argv[3] if len(argv) > 3 else None)

if argv[2] == '7' or argv[2] == '8':
    side_by_side.sbys_histogram(
        [im1, im2, im3],
        ['original', 'uniform equalization', 'uniform^2 equalization'],
        argv[3] if len(argv) > 3 else None)
if argv[2] == '9':
    side_by_side.sbys_histogram([im1, im5],
                                ['original', 'normal equalization'],
                                argv[3] if len(argv) > 3 else None)

if argv[2] == 'lambda':
    side_by_side.sbys_histogram(
        [im1, im6, im7, im8],
        ['original', 'lambda = 2', 'lambda = 5', 'lambda = 10'],
Example #3
0
import numpy as np
from PIL import Image
from sys import argv
import side_by_side

im1 = np.asarray(Image.open(argv[1]).convert('RGB'))
side_by_side.sbys_histogram([im1], ['rgb'],argv=argv[2] if len(argv)>2 else None) 

Example #4
0
'''
Implementar una funcion que devuelva el histograma de niveles de gris de una
imagen.

Modo de uso:
  python3 ej05.py <img1>
'''

import numpy as np
from PIL import Image
from sys import argv
import side_by_side

im1 = np.asarray(Image.open(argv[1]).convert('L'))
side_by_side.sbys_histogram([im1], None, argv[2] if len(argv) > 2 else None) 
Example #5
0
import numpy as np
from PIL import Image
from sys import argv
import side_by_side

L = 256

def histogram(im):
	return side_by_side.histogram_rgb(im)


def uniform_hist(im):
    histogram_r, accum_r, histogram_g, accum_g, histogram_b, accum_b  = histogram(im)
    def w_dot(r):
        wr = accum_r[r[0]]
        wg = accum_g[r[1]]
        wb = accum_b[r[2]]
        return list(map(lambda w: int(w * L - 0.5), [wr, wg, wb]))
    ret = im.copy()
    for i in range(ret.shape[0]):
        for j in range(ret.shape[1]):
            print(i,j)
            ret[i][j] = w_dot(ret[i][j])
    return ret

im1 = np.asarray(Image.open(argv[1]).convert('RGB'))
side_by_side.sbys_histogram([im1, uniform_hist(im1)], ['rgb', 'rgb'],argv=argv[2] if len(argv)>2 else None)