def labelview(labels, filename=None): """ VisualizaciĆ³n de labels asignados con colores. Args: labels (Numpy nd Array): arreglo en formato de imagen con labels indicados filename (string): string con el nombre del archivo a guardar Returns: VisualizaciĆ³n (plot.imgview): imagen con los colores asignados en lugar de las etiquetas """ nueva = np.zeros((len(labels), len(labels[0])), dtype=int).astype(np.uint8) if len(nueva.shape) == 2: nueva = cv.cvtColor(nueva, cv.COLOR_GRAY2RGB) colores = [[], []] for i in range(len(labels)): for j in range(len(labels[i])): valor = labels[i, j] if valor != 0: if valor in colores[0]: indice = colores[0].index(valor) color = colores[1][indice] else: color = [ random.randint(0, 255), random.randint(0, 255), random.randint(0, 255) ] colores[0].append(valor) colores[1].append(color) nueva[i, j] = color plot.imgview(nueva, None, None, filename)
def labelview(labels): if len(labels.shape) == 2: labels = cv.cvtColor(labels, cv.COLOR_GRAY2RGB) colores = [[], []] for i in range(len(labels)): for j in range(len(labels[i])): valor = labels[i, j][0] if valor != 0: if valor in colores[0]: indice = colores[0].index(valor) color = colores[1][indice] else: color = [ random.randint(0, 255), random.randint(0, 255), random.randint(0, 255) ] colores[0].append(valor) colores[1].append(color) labels[i, j] = color plot.imgview(labels)
import math get_ipython().run_line_magic('matplotlib', 'inline') # In[15]: img = cv.imread("./wikipedia.png", cv.IMREAD_GRAYSCALE) # In[16]: print(img.shape) plot.imgview(img) normalizada = plot.imgnorm(img) # In[17]: hello = plot.hist(img) print(normalizada.shape) # In[18]: plot.hist(normalizada) plot.imgview(normalizada)
else: color = [ random.randint(0, 255), random.randint(0, 255), random.randint(0, 255) ] colores[0].append(valor) colores[1].append(color) labels[i, j] = color plot.imgview(labels) # In[82]: huella = cv.imread('./intentar_wiki.pgm', cv.IMREAD_GRAYSCALE) plot.imgview(huella) # In[83]: import sys np.set_printoptions(threshold=sys.maxsize) # In[118]: img = cv.imread('./fprint3.pgm', cv.IMREAD_GRAYSCALE) img = img[300:500, 300:500] plot.imgview(img) print(len(img)) print(len(img[0])) # In[119]:
def hit_miss(img, kernel_hit, kernel_miss): img2 = cv.bitwise_not(img) erode_1 = cv.erode(img, kernel_hit, iterations=1) erode_2 = cv.erode(img2, kernel_miss, iterations=1) return cv.bitwise_and(erode_1, erode_2) # In[4]: imagen = cv.imread('./intentar.pgm', cv.IMREAD_GRAYSCALE) # In[5]: plot.imgview(imagen, True) # In[6]: kernel_hit = np.array([[0, 255, 0], [0, 255, 0], [0, 255, 0]], np.uint8) kernel_miss = np.array([[255, 0, 255], [255, 0, 255], [255, 0, 255]], np.uint8) # In[7]: plot.imgcmp(kernel_hit, kernel_miss, True) # In[8]: plot.imgview(hit_miss(imagen, kernel_hit, kernel_miss), True) # In[9]:
# In[1]: import cv2 as cv import matplotlib.pyplot as plt import numpy as np import plot get_ipython().run_line_magic('matplotlib', 'inline') # In[43]: img = cv.imread('./ufmlogo.png', 0) #img = cv.blur(img, (8, 8)) #ret,img = cv.threshold(img,100,255,cv.THRESH_BINARY) img = cv.Canny(img, 50, 200) plot.imgview(img) # In[4]: img2 = cv.imread('./encontrar.png', cv.IMREAD_GRAYSCALE) img3 = cv.imread('./encontrar.png') img3 = cv.cvtColor(img3, cv.COLOR_BGR2RGB) plot.imgview(img3) # In[5]: template = img2[250:450, 420:600] plot.imgview(template) # In[57]:
import plot from mpl_toolkits.mplot3d import axes3d plt.style.use('dark_background') get_ipython().run_line_magic('matplotlib', 'inline') # In[3]: img = cv.imread("./wikipedia.png", cv.IMREAD_GRAYSCALE) img = plot.equalizar(img) plot.imgview(img) # In[4]: thresh_val = 80 ret, thresh = cv.threshold(img, thresh_val, 255, cv.THRESH_BINARY) # In[5]: print(ret)
b_y = convolve(b, gy) # In[169]: mag1 = float64_to_uint8(gradient2magnitude(r_x, r_y)) mag2 = float64_to_uint8(gradient2magnitude(g_x, g_y)) mag3 = float64_to_uint8(gradient2magnitude(b_x, b_y)) # In[170]: final = cv.merge((mag1, mag2, mag3)) plot.imgview(final, None, None, "rgb_magnitudes") # In[216]: ang1 = float64_to_uint8(gradient2angle(r_x, r_y)) ang2 = float64_to_uint8(gradient2angle(g_x, g_y)) ang3 = float64_to_uint8(gradient2angle(b_x, b_y)) # In[217]: final = cv.merge((ang1, ang2, ang3)) plot.imgview(final, None, None, "rgb_angles")