Commit 38d9e819 authored by Rafael Andrei Vinasco Soler's avatar Rafael Andrei Vinasco Soler
Browse files

archivo . md

parent 8e983313
```python
import numpy as np
import matplotlib.pyplot as plt
##import cv2
import matplotlib.image as mpimg
from matplotlib.pyplot import figure
import scipy.optimize as opt
from scipy.optimize import curve_fit
```
```python
images_path = 'data/zapatocaImage.jpeg'
img = mpimg.imread(images_path)
figure(num=None, figsize=(9, 7), dpi=80, facecolor='w', edgecolor='k')
plt.imshow(img[300:400,400:600])
plt.show()
```
![png](output_1_0.png)
```python
##lena = plt.imread('data/zapatocaImage.jpeg')
print(type(img))
print(img.shape)
size = img.shape
```
<class 'numpy.ndarray'>
(789, 1184, 3)
```python
R = img[:,:,0]
G = img[:,:,1]
B = img[:,:,2]
```
```python
figure(num=None, figsize=(9, 7), dpi=80, facecolor='w', edgecolor='k')
plt.imshow(R)
plt.title("Canal Rojo")
plt.colorbar()
##plt.figure()
```
<matplotlib.colorbar.Colorbar at 0x7feaf4497ac8>
![png](output_4_1.png)
```python
figure(num=None, figsize=(9, 7), dpi=80, facecolor='w', edgecolor='k')
plt.imshow(G)
plt.title("Canal verde")
plt.colorbar()
##plt.figure()
```
<matplotlib.colorbar.Colorbar at 0x7feaf9473fd0>
![png](output_5_1.png)
```python
figure(num=None, figsize=(9, 7), dpi=80, facecolor='w', edgecolor='k')
plt.imshow(B)
##plt.imshow(B,cmap = 'gray')
plt.title("Canal azul")
plt.colorbar()
##plt.figure()
```
<matplotlib.colorbar.Colorbar at 0x7feaf93b3470>
![png](output_6_1.png)
```python
T = 0.299*R+0.587*G+0.114*B
notT = R+G+B
```
```python
figure(num=None, figsize=(9, 7), dpi=80, facecolor='w', edgecolor='k')
plt.imshow(T, cmap = 'gray')
plt.title("total blanco y negro")
plt.colorbar()
```
<matplotlib.colorbar.Colorbar at 0x7feaf92e49b0>
![png](output_8_1.png)
### En lo que vamos a partir la imagen
```python
particion = 10
part_elevation = size[0]/particion
part_wide = size[1]/particion
```
## Funciones a definir,
### importante, he puesto siempre T, debo cam,biar eso y poner como entrada B de alguna forma (CREO)
```python
CRITT = 8
##imgtt_copy = T.copy()
imgtt_copy = np.zeros([size[0],size[1]])
def minn(a):
b= int(round(a))
if a < b:
return int(b-1)
else:
return int(b)
def maxx(a):
b= int(round(a))
if a > b:
return int(b+1)
else:
return int(b)
def img_part(a,b,Y): ## a #de matriz en altura, b lo mismo pero con ancho ; 0<a<20
X = Y[minn(a*part_elevation):minn((a+1)*part_elevation) , minn(b*part_wide):minn((b+1)*part_wide) ]
return X
def histpart_init(img_partt): # creo el histograma y lo inicio en cero
hist_range = maxx(np.max(img_partt)) - minn(np.min(img_partt))
hist_arrayy = np.zeros( hist_range +1 )
return hist_arrayy
def histpart_full(histt,imgtt):
sizezz = imgtt.shape
for i in range (0,sizezz[0],1):
for j in range (0,sizezz[1],1):
##a = imgtt[i,j]
v = minn(imgtt[i,j] - np.min( imgtt ) ) ## revizr si poner maximo o minimo, detalles!!
histt[ int(v) ] += 1
return histt
##sum(hist_full)=minn(part_elevation)*minn(part_wide) ## deberia cumplirse esto
def criteri_histograma(histt): ## criterio: si estamos mas alla de np.max(hist_full)/10 es decir un decimo de la mediana
##CRITT =5
maxx = np.max(histt)
for i in range (0,histt.size,1):
if histt[i] > maxx-1:
aa = i
for j in range (aa+2,histt.size,1):
if histt[j] < maxx/CRITT:
ccc = j
break
return ccc
def clean_part(crit_hist,imgtt):
sizezz = imgtt.shape
imgttTT = imgtt.copy()
for i in range (0,sizezz[0],1):
for j in range (0,sizezz[1],1):
if imgtt[i,j] < (np.min(imgtt) + crit_hist):
imgttTT[i,j] = np.min(imgtt)+crit_hist
if imgtt[i,j] < 55: ##solo por jugar
imgttTT[i,j] = 55
return imgttTT
def New_image(a,b,X,Y): ## parte filtrada, copia de la imagen toral que modificare
ii = 0
for i in range (minn(x*part_elevation), minn((x+1)*part_elevation) ,1 ):
jj=0
for j in range (minn(y*part_wide), minn((y+1)*part_wide) , 1 ):
X[i,j] = Y[ii,jj]
jj += 1
ii += 1
```
```python
T_PART= img_part(6,5,T)
hist = histpart_init(T_PART)
hist_full = histpart_full(hist,T_PART)
plt.title("histograma, minimo es : "+str(np.min(T_PART)) )
plt.plot(hist_full)
```
[<matplotlib.lines.Line2D at 0x7feaf597ee10>]
![png](output_13_1.png)
```python
criterio_hist = criteri_histograma(hist_full)
criterio_hist
```
68
```python
criterio_hist = criteri_histograma(hist_full)
clean_image = clean_part(criterio_hist,T_PART)
plt.imshow(clean_image, cmap = 'gray')
plt.title("parte blanco y negro")
plt.colorbar()
```
<matplotlib.colorbar.Colorbar at 0x7feaf5837d68>
![png](output_15_1.png)
```python
plt.imshow(T_PART, cmap = 'gray')
plt.title("original blanco y negro")
plt.colorbar()
```
<matplotlib.colorbar.Colorbar at 0x7feaee6479b0>
![png](output_16_1.png)
```python
for x in range (0,particion,1):
for y in range (0,particion,1):
T_PART= img_part(x,y,T)
hist = histpart_init(T_PART)
hist_full = histpart_full(hist,T_PART)
criterio_hist = criteri_histograma(hist_full)
criterio_hist = criteri_histograma(hist_full)
clean_image = clean_part(criterio_hist,T_PART)
New_image(x,y,imgtt_copy,clean_image)
figure(num=None, figsize=(9, 7), dpi=80, facecolor='w', edgecolor='k')
plt.imshow(imgtt_copy, cmap = 'gray')
plt.title("original blanco y negro")
plt.colorbar()
```
<matplotlib.colorbar.Colorbar at 0x7feabb6cceb8>
![png](output_17_1.png)
```python
figure(num=None, figsize=(9, 7), dpi=80, facecolor='w', edgecolor='k')
plt.imshow(imgtt_copy, cmap = 'gray',vmin=65,vmax=260)
plt.title("original blanco y negro")
plt.colorbar()
```
<matplotlib.colorbar.Colorbar at 0x7feabe9b0ef0>
![png](output_18_1.png)
```python
figure(num=None, figsize=(9, 7), dpi=80, facecolor='w', edgecolor='k')
plt.imshow(imgtt_copy[300:500,200:400], cmap = 'gray')
plt.title("blanco y negro")
plt.colorbar()
```
<matplotlib.colorbar.Colorbar at 0x7feabb940cf8>
![png](output_19_1.png)
```python
imgttt_copy= imgtt_copy.copy()
x=4
y=5
AA_PART= img_part(x,y,imgttt_copy)
plt.imshow(AA_PART, cmap = 'gray')
plt.title("parte blanco y negro")
plt.colorbar()
```
<matplotlib.colorbar.Colorbar at 0x7feadba63ba8>
![png](output_20_1.png)
```python
figure(num=None, figsize=(9, 7), dpi=80, facecolor='w', edgecolor='k')
plt.imshow(imgttt_copy, cmap = 'gray')
plt.title("parte blanco y negro")
plt.colorbar()
```
<matplotlib.colorbar.Colorbar at 0x7feadb360da0>
![png](output_21_1.png)
## nuevo particion para culsterizar cada estrella
si tomo particion 1, tomo toda la imagen!
```python
particion = 5
part_elevation = size[0]/particion
part_wide = size[1]/particion
```
```python
lum=125 ## tope de luz
imgttt_copy= imgtt_copy.copy()
def tanteo(x,y,iii,jjj): ## iii y jjj desde donde sigue
brek=True
ii = iii
jj=jjj
##voy a terminar la linea
for j in range (minn(y*part_wide)+jjj, minn((y+1)*part_wide),1):
if imgttt_copy[ii,j] > lum:
u=[ii,jj]
brek=False
break
return u
##ii+=1
for i in range (minn(x*part_elevation)+ii, minn((x+1)*part_elevation),1):
jj=0
for j in range (minn(y*part_wide), minn((y+1)*part_wide),1):
if imgttt_copy[i,j] > lum:
u=[ii,jj]
brek=False
break
jj+=1
if brek==False:
break
ii+=1
if brek==True:
u=[-1,-1]
return u
def ubicar_estrella(x,y,iii,jjj,COPY):
contador_puntos=0
ii=iii
jj=jjj
imin=iii-1
imax=0
jmin=10000
jmax=0
line_number=0
rig = True
lef = True
dow = True
while dow==True:
if ii>=maxx(part_elevation):##revizar ese 1
break
line_number=0
rig = True
lef = True
jj=jjj
if COPY[ii,jj] > lum:
COPY[ii,jj]=2
imgttt_copy[minn(x*part_elevation)+ii,minn(y*part_wide)+jj]=2
contador_puntos+=1
line_number+=1
while rig==True:
if jj+2>=maxx(part_wide):
break
jj +=1
if COPY[ii,jj]>lum:
COPY[ii,jj]=2
imgttt_copy[minn(x*part_elevation)+ii,minn(y*part_wide)+jj]=2
contador_puntos +=1
line_number +=1
else: ##debo corregir para terminos frontera
rig = False
if jj>jmax:
jmax=jj+2 ##lo realmente aca tiene 1 sumado
jj=jjj
while lef==True:
jj -=1
if jj<jmin:
jmin=jj-1 ##lo realmente aca tiene 1 restado
if COPY[ii,jj]>lum:
COPY[ii,jj]=2
imgttt_copy[minn(x*part_elevation)+ii,minn(y*part_wide)+jj]=2
contador_puntos +=1
line_number +=1
else: ##debo corregir para terminos frontera
lef = False
if jj==0:
lef = False
ii+=1
if line_number==0: ##podria dejar puntoas por fuera pero pos nahh
dow = False
imax=ii
p=[contador_puntos , imin , imax, jmin , jmax]
return p
```
```python
imgttt_copy= imgtt_copy.copy()
x=2
y=2
AA_PART= img_part(x,y,imgttt_copy)
plt.imshow(AA_PART, cmap = 'gray')
plt.title("parte blanco y negro")
plt.colorbar()
```
<matplotlib.colorbar.Colorbar at 0x7feab77ccac8>
![png](output_25_1.png)
### Ejemplo seleccion estrella
```python
a=tanteo(x,y,34,40)
bb=ubicar_estrella(x,y,a[0],a[1],AA_PART)
data_array = np.full([bb[2]- bb[1], bb[4]- bb[3] ], None)
ui=[]
uj=[]
ulum=[]
for i in range (bb[1],bb[2],1):
for j in range (bb[3],bb[4],1):
if AA_PART[i,j]==2:
ui.append(i)
uj.append(j)
ulum.append( imgtt_copy[minn(x*part_elevation)+i,minn(y*part_wide)+j] )
data_array[i-bb[1],j-bb[3]] = imgtt_copy[minn(x*part_elevation)+i,minn(y*part_wide)+j]
plt.imshow(AA_PART[bb[1]:bb[2],bb[3]:bb[4]], cmap = 'gray')
plt.title("parte blanco y negro")
plt.colorbar()
```
<matplotlib.colorbar.Colorbar at 0x7feab7504b00>
![png](output_27_1.png)
```python