Skip to content

Instantly share code, notes, and snippets.

@ramonesteban
ramonesteban / tautologia.py
Created August 19, 2012 07:27
Programa para verificar si una fórmula lógica es una tautología
#!/usr/bin/python
def conjuncion(V1, V2):
return (V1 and V2)
def disyuncion(V1, V2):
return (V1 or V2)
def negacion(V):
return not(V)
@ramonesteban
ramonesteban / semaforo.pde
Created May 20, 2012 03:11
Código para un semáforo con Arduino Uno
/*
Programa para un par de semaforos que cambian de uno
a otro, y la implementacin de un boton para terminar
el tiempo de la luz verde y pasar al otro.
*/
// Declaramos la variable para el pin del boton
const int button = 8;
void setup() {
// Con un ciclo activamos los pines del 2 al 7 como salidas
@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
}