Skip to content

Instantly share code, notes, and snippets.

View guissalustiano's full-sized avatar
🧙‍♂️
wizard trainee

Guilherme Salustiano guissalustiano

🧙‍♂️
wizard trainee
View GitHub Profile
def convolution(img: np.ndarray, filt: np.ndarray):
iw, ih = img.shape
kw, kh = filt.shape
assert(kw % 2 == 1 and kh % 2 == 1) # Garante que o filtro tenha um centro
kcx, kcy = kw//2, kh//2 # Calcula a posição central
out = np.zeros(img.shape)
for x, y in np.ndindex(*out.shape):
#Pega os pixels que serão usados na operação com o filtro
sub_img = img[max(0, x-kcx): min(iw, x-kcx + (kw)),
max(0, y-kcy): min(ih, y-kcy + (kh))]
def gaussian_kernel(size, sigma=1):
center = size//2
x, y = np.mgrid[-center:center+1, -center:center+1]
return np.exp(-((x**2 + y**2) / (2*sigma**2)))
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
def rgbToGray(img):
# Baseado em https://pillow.readthedocs.io/en/3.2.x/reference/Image.html#PIL.Image.Image.convert
return np.matmul(img, [0.2989, 0.5870, 0.1140]).astype(np.uint())
def convolution(img: np.ndarray, filt: np.ndarray):
iw, ih = img.shape
import cv2 as cv
import matplotlib.pyplot as plt
import numpy as np
img = cv.imread('passarinho.jpg',0)
sobel = cv.Sobel(img, -1, 1, 1)
fig, ax = plt.subplots(ncols=2,figsize=(15,5))
ax[0].imshow(img, cmap = 'gray')
ax[0].set_title('Original')
@guissalustiano
guissalustiano / exp2.jl
Last active June 30, 2021 15:43
Calculo do experimento 2 do laboratorio de PME3033
######################################################
# Por: Guilherme S Salustiano #
# Eng da Computação 2020 #
######################################################
using Measurements
temperatura_da_agua_graus = 30 ± 0.5
distancia_tubos_pilot_centros = 5.4e-3
distancia_tubos_pilot_parede_centro = distancia_tubos_pilot_centros/2
@guissalustiano
guissalustiano / moodle_redicect_replace.py
Created September 11, 2021 02:58
Replace moodle redirects
import requests
import re
from functools import cache
MOODLE_SESSION = ''
FILENAME = 'readme.md'
@cache
def file_content():
@guissalustiano
guissalustiano / util.py
Created November 21, 2021 04:27
Exemplo medium Debugando aplicações em python
from typing import Dict, Any
def flatten_dict(root: Dict[str, Any], separator: str = '.') -> Dict[str, Any]:
"""
Tranforma dicionarios aninhados em um dicionario plano
Exemplo:
>>> flatten_dict({'a': 1, 'b': {'c': 2, 'd': 3}})
>>> {'a': 1, 'b.c': 2, 'b.d': 3}
"""
flatten_root = {}
for root_key, root_value in root.items():
from util import flatten_dict
def test_flatten_dict_nivel_1():
assert flatten_dict({'a': 1, 'b': 2}) == {'a': 1, 'b': 2}
def test_flatten_dict_nivel_3():
assert flatten_dict({'a': 1, 'b': {'c': 2, 'd': 3}}) == \
{'a': 1, 'b.c': 2, 'b.d': 3}
def test_flatten_dict_nivel_4():
$ pytest
========================= test session starts =========================
platform linux -- Python 3.9.7, pytest-6.2.5, py-1.10.0, pluggy-0.13.1
rootdir: /home/guiss/Projetos/Turing/Talks/Logs
collected 4 items
util_test.py .... [100%]
======================== 4 passed in 0.01s ============================
- flatten_root_key = separator.join([root_key, item_key])
+ flatten_root_key = '.'.join([root_key, item_key])