This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###################################################### | |
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import re | |
from functools import cache | |
MOODLE_SESSION = '' | |
FILENAME = 'readme.md' | |
@cache | |
def file_content(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 ============================ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- flatten_root_key = separator.join([root_key, item_key]) | |
+ flatten_root_key = '.'.join([root_key, item_key]) |
OlderNewer