-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tratamiento (suavizado de imágenes) con Numpy
- Loading branch information
Showing
6 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Sun Aug 26 13:16:20 2018 | ||
@author: FamiliaHogar | ||
""" | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
import PIL | ||
from skimage import io | ||
|
||
colorGirl=io.imread("imaTestColor.jpg")/255.0 | ||
|
||
print("- Dimensiones de la imagen:") | ||
print(colorGirl.shape) | ||
plt.imshow(colorGirl,vmin=0,vmax=1) | ||
plt.title("RGB") | ||
plt.figure() | ||
|
||
plt.imshow(colorGirl[:,:,0],vmin=0,vmax=1) | ||
plt.title("Canal Rojo") | ||
plt.figure() | ||
plt.imshow(colorGirl[:,:,1],vmin=0,vmax=1) | ||
plt.title("Canal Verde") | ||
plt.figure() | ||
plt.imshow(colorGirl[:,:,2],vmin=0,vmax=1) | ||
plt.title("Canal Azul") | ||
|
||
plt.figure() | ||
colorGirlRed=np.copy(colorGirl) # creo una copia de la imagen para preservar la original | ||
colorGirlRed[:,:,1]=0 # quito el canal azul | ||
colorGirlRed[:,:,2]=0 # quito el canal verde | ||
plt.title("ColorGirl Canal Rojo") | ||
plt.imshow(colorGirlRed) | ||
|
||
#Suavizar imagen gris | ||
|
||
plt.figure() | ||
grayGirl=io.imread("imaTestGris.jpg")/255.0 | ||
|
||
print("- Dimensiones de la imagen:") | ||
print(grayGirl.shape) | ||
plt.imshow(grayGirl,vmin=0,vmax=1) | ||
plt.title("Sin suavizar") | ||
|
||
imagen = PIL.Image.open("imaTestGris.jpg").convert("L") | ||
imaMatriz = np.array(imagen) | ||
imaMatrizSuav = np.zeros(imaMatriz.shape) | ||
print(imaMatriz.shape) | ||
|
||
for x in range(410): | ||
for y in range(730): | ||
imaMatrizSuav[x,y] = ((imaMatriz[(x+1)%410,y] + imaMatriz[(x+1)%410,(y+1)%730] | ||
+ imaMatriz[x,(y+1)%730] + imaMatriz[x-1,(y+1)%730] + imaMatriz[x-1,y] | ||
+ imaMatriz[x-1,y-1] + imaMatriz[x,y-1] + imaMatriz[(x+1)%410,y-1] | ||
+ imaMatriz[x,y])/10) | ||
|
||
plt.figure() | ||
plt.imshow(imaMatrizSuav) | ||
plt.title("Suavizada") | ||
|
||
|
||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Sun Aug 26 12:58:20 2018 | ||
@author: FamiliaHogar | ||
""" | ||
import matplotlib.pyplot as plt | ||
from skimage import io | ||
|
||
#Carga de imagenes en escala de grises: | ||
|
||
grayGirl=io.imread("imaTestGris.jpg")/255.0 | ||
|
||
print("- Dimensiones de la imagen:") | ||
print(grayGirl.shape) | ||
plt.imshow(grayGirl,vmin=0,vmax=1) | ||
|
||
#Carga de imagenes a color: | ||
plt.figure() | ||
|
||
colorGirl=io.imread("imaTestColor.jpg")/255.0 | ||
|
||
print("- Dimensiones de la imagen:") | ||
print(colorGirl.shape) | ||
plt.imshow(colorGirl,vmin=0,vmax=1) | ||
|
||
|
||
plt.imshow(lena_rgb[:,:,0],vmin=0,vmax=1) | ||
plt.title("Canal Rojo") | ||
plt.figure() | ||
plt.imshow(lena_rgb[:,:,1],vmin=0,vmax=1) | ||
plt.title("Canal Verde") | ||
plt.figure() | ||
plt.imshow(lena_rgb[:,:,2],vmin=0,vmax=1) | ||
plt.title("Canal Azul") | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Sun Aug 26 12:58:20 2018 | ||
@author: FamiliaHogar | ||
""" | ||
import numpy as np | ||
|
||
matrizOriginal = np.random.randint(0, 99, (30,30)) | ||
matrizSuavizada = np.zeros((30,30)) | ||
#print(matrizOriginal) | ||
|
||
for x in range(30): | ||
for y in range(30): | ||
matrizSuavizada[x,y] = ((matrizOriginal[(x+1)%10,y] + matrizOriginal[(x+1)%10,(y+1)%10] | ||
+ matrizOriginal[x,(y+1)%10] + matrizOriginal[x-1,(y+1)%10] + matrizOriginal[x-1,y] | ||
+ matrizOriginal[x-1,y-1] + matrizOriginal[x,y-1] + matrizOriginal[(x+1)%10,y-1] | ||
+ matrizOriginal[x,y])/10) | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Sun Aug 26 12:32:52 2018 | ||
@author: FamiliaHogar | ||
""" | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
plt.rcParams['image.cmap'] = 'gray' | ||
size=(20,30) | ||
|
||
imagen_negra = np.zeros(size) | ||
imagen_blanca = np.ones(size) | ||
imagen_gris = np.ones(size)*0.5 | ||
imagen_aleatoria = np.random.rand(size[0],size[1]) | ||
imagen_gradiente = np.linspace(0, 1, 600).reshape(20,30) | ||
|
||
#Test: | ||
matrizOriginal = np.random.randint(0, 99, (100,100)) | ||
matrizSuavizada = np.zeros((100,100)) | ||
|
||
for x in range(100): | ||
for y in range(100): | ||
matrizSuavizada[x,y] = ((matrizOriginal[(x+1)%10,y] + matrizOriginal[(x+1)%10,(y+1)%10] | ||
+ matrizOriginal[x,(y+1)%10] + matrizOriginal[x-1,(y+1)%10] + matrizOriginal[x-1,y] | ||
+ matrizOriginal[x-1,y-1] + matrizOriginal[x,y-1] + matrizOriginal[(x+1)%10,y-1] | ||
+ matrizOriginal[x,y])/10) | ||
|
||
#plt.imshow(imagen_negra,vmin=0,vmax=1) | ||
#plt.figure() | ||
#plt.imshow(imagen_blanca,vmin=0,vmax=1) | ||
#plt.figure() | ||
#plt.imshow(imagen_gris,vmin=0,vmax=1) | ||
#plt.figure() | ||
plt.imshow(imagen_aleatoria,vmin=0,vmax=1) | ||
plt.figure() | ||
plt.imshow(imagen_gradiente,vmin=0,vmax=1) | ||
plt.figure() | ||
plt.imshow(matrizOriginal,vmin=0,vmax=99) | ||
plt.figure() | ||
plt.imshow(matrizSuavizada,vmin=0,vmax=99) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.