Skip to content

Instantly share code, notes, and snippets.

@ramonesteban
ramonesteban / image_compression.py
Created May 29, 2013 05:56
Uso de PyWavelets para la compresión de imágenes
import sys, os, time, numpy, Image, pywt
import matplotlib.pyplot as plt
def wavelet_transform(data, threshold):
wavelet_type = 'haar'
clean_coef = list()
compose = list()
cA2, cD2, cD1 = pywt.wavedec2(data, wavelet_type, level=2)
clean_coef.append(cA2)
@ramonesteban
ramonesteban / wavelet_edges.py
Created May 24, 2013 16:15
Obtener los bordes de una imagen usando PyWavelets
import sys, pylab, numpy, Image, pywt
def edges(path):
im = Image.open(path).convert('L')
arr = numpy.fromstring(im.tostring(), numpy.uint8)
arr.shape = (im.size[1], im.size[0])
data = pywt.swt2(arr, 'haar', level=3, start_level=0)
LL, (LH, HL, HH) = data[2]
pylab.imshow(LH, interpolation='nearest', cmap=pylab.cm.gray)
@ramonesteban
ramonesteban / blendtwoimages.py
Created May 24, 2013 14:50
Mezclar dos imágenes usando PyWavelets
import sys, time, Image, numpy, pywt
def load_image(image, effect, size=None):
im = Image.open(image)
if size is not None and im.size != size:
im = im.resize(size, Image.ANTIALIAS)
im = im.convert('RGB')
if effect == 'sepia':
im = sepia(im)
return im
@ramonesteban
ramonesteban / geolocalization.py
Created May 14, 2013 15:42
Código para ubicación por trilateración
from Tkinter import *
import math, Image, ImageTk
SIZE = 5
class Interface:
def __init__(self, root):
self.root = root
self.root.title('Geolocalization')
self.root.resizable(width=False, height=False)
@ramonesteban
ramonesteban / corners.py
Created May 9, 2013 16:41
Fragmentos de código para la detección de esquinas
def bfs(self, image, start_pixel_pos, color):
pixels = image.load()
width, height = get_image_size(image)
queue = []
copy = []
count = 0
queue.append(start_pixel_pos)
original = pixels[start_pixel_pos]
while 0 < len(queue):
@ramonesteban
ramonesteban / hamming_code.py
Created May 9, 2013 14:21
Programa para obtener los códigos Hamming
import sys, random, numpy
def binary_matrix(matrix):
for element in numpy.nditer(matrix, op_flags=['readwrite']):
if element > 1 and element%2 == 0:
element[...] = 0
if element > 1 and element%2 != 0:
element[...] = 1
return matrix
@ramonesteban
ramonesteban / polygons.py
Created May 2, 2013 16:27
Fragmento del código para la detección de polígonos
def draw_polygons_detected(self, image, polygons_found):
draw = ImageDraw.Draw(image)
max_w, max_h = get_image_size(image)
counter = 0
for polygon in polygons_found:
center, sides = polygon
x, y = center
r = random.randint(100, 255)
g = random.randint(100, 255)
@ramonesteban
ramonesteban / topology_traffic.tcl
Created April 30, 2013 17:12
Prueba para diferentes topologías y modos de tráfico en NS-2
set ns [new Simulator]
$ns namtrace-all [open out.nam w]
set topology [lindex $argv 0]
set traffic_app [lindex $argv 1]
proc finish {} {
exec nam out.nam &
exit 0
}
@ramonesteban
ramonesteban / holes.py
Created April 25, 2013 15:05
Fragmento de código para el preprocesamiento de la detección de agujeros
def minimums_in_histogram(self, hist):
minimums = list()
for i, value in enumerate(hist):
try:
if hist[i-2] > value and hist[i-1] > value and value <= hist[i+1]:
minimums.append(i)
except:
pass
return minimums
@ramonesteban
ramonesteban / adaptive_coding.py
Created April 25, 2013 14:39
Código creado para una codificación adaptativa
import sys, random
class Node:
def __init__(self, char, freq, left=None, right=None):
self.char = char
self.freq = freq
self.left = left
self.right = right
self.father = None
self.bit = None