diff --git a/entrega/output_13_1.png b/entrega/output_13_1.png new file mode 100644 index 0000000000000000000000000000000000000000..b84594134c8a89c22928f42c7c94a4dc02018c18 Binary files /dev/null and b/entrega/output_13_1.png differ diff --git a/entrega/output_15_1.png b/entrega/output_15_1.png new file mode 100644 index 0000000000000000000000000000000000000000..5354e5cafe0480c9f7f77da1d05635b6fc9c8dc6 Binary files /dev/null and b/entrega/output_15_1.png differ diff --git a/entrega/output_16_1.png b/entrega/output_16_1.png new file mode 100644 index 0000000000000000000000000000000000000000..9466846b798c46a6dc6da54deb0c2e6d726f1356 Binary files /dev/null and b/entrega/output_16_1.png differ diff --git a/entrega/output_17_1.png b/entrega/output_17_1.png new file mode 100644 index 0000000000000000000000000000000000000000..e3224de734a12f5aabc2c1a7abc50bd405f2ad45 Binary files /dev/null and b/entrega/output_17_1.png differ diff --git a/entrega/output_18_1.png b/entrega/output_18_1.png new file mode 100644 index 0000000000000000000000000000000000000000..c1266b9772a5e4e1b217dc2ceaf48833ee333f22 Binary files /dev/null and b/entrega/output_18_1.png differ diff --git a/entrega/output_19_1.png b/entrega/output_19_1.png new file mode 100644 index 0000000000000000000000000000000000000000..3a36c6c35f14930a086578cc4c8684c7203c9b49 Binary files /dev/null and b/entrega/output_19_1.png differ diff --git a/entrega/output_1_0.png b/entrega/output_1_0.png new file mode 100644 index 0000000000000000000000000000000000000000..98910edfbb336dad701736791f2ea152c75d6069 Binary files /dev/null and b/entrega/output_1_0.png differ diff --git a/entrega/output_20_1.png b/entrega/output_20_1.png new file mode 100644 index 0000000000000000000000000000000000000000..14f7994c9cce0f75d139cb378591a4d46028a655 Binary files /dev/null and b/entrega/output_20_1.png differ diff --git a/entrega/output_21_1.png b/entrega/output_21_1.png new file mode 100644 index 0000000000000000000000000000000000000000..7ba4d44e3b03198b9fc8c5acaae394f0e026d67e Binary files /dev/null and b/entrega/output_21_1.png differ diff --git a/entrega/output_25_1.png b/entrega/output_25_1.png new file mode 100644 index 0000000000000000000000000000000000000000..45776d703d422c118792f058c414d28bf23bd2a5 Binary files /dev/null and b/entrega/output_25_1.png differ diff --git a/entrega/output_27_1.png b/entrega/output_27_1.png new file mode 100644 index 0000000000000000000000000000000000000000..394baea0ef23521c8c49d32924b643310bc9ffa5 Binary files /dev/null and b/entrega/output_27_1.png differ diff --git a/entrega/output_28_0.png b/entrega/output_28_0.png new file mode 100644 index 0000000000000000000000000000000000000000..76f0b4bab2518e7e42bbf575f06dcc19debb9531 Binary files /dev/null and b/entrega/output_28_0.png differ diff --git a/entrega/output_30_1.png b/entrega/output_30_1.png new file mode 100644 index 0000000000000000000000000000000000000000..5cb94c69e24b36b27faf20002de00707fd7ff14c Binary files /dev/null and b/entrega/output_30_1.png differ diff --git a/entrega/output_39_0.png b/entrega/output_39_0.png new file mode 100644 index 0000000000000000000000000000000000000000..476d3c84bcdd6953386809dc54e5032939d98a91 Binary files /dev/null and b/entrega/output_39_0.png differ diff --git a/entrega/output_4_1.png b/entrega/output_4_1.png new file mode 100644 index 0000000000000000000000000000000000000000..a92928f61af4c29229c2364ecc5bfe4c05110ea0 Binary files /dev/null and b/entrega/output_4_1.png differ diff --git a/entrega/output_5_1.png b/entrega/output_5_1.png new file mode 100644 index 0000000000000000000000000000000000000000..d87355bd4ca2af7c5b55fadc72f188b8e49d90b3 Binary files /dev/null and b/entrega/output_5_1.png differ diff --git a/entrega/output_6_1.png b/entrega/output_6_1.png new file mode 100644 index 0000000000000000000000000000000000000000..517679897e0244714bd6cd9e0726365c2bd728ce Binary files /dev/null and b/entrega/output_6_1.png differ diff --git a/entrega/output_8_1.png b/entrega/output_8_1.png new file mode 100644 index 0000000000000000000000000000000000000000..410d74b698c5fb7c904701b2000acd7bbc6c075f Binary files /dev/null and b/entrega/output_8_1.png differ diff --git a/entrega/solucion.md b/entrega/solucion.md new file mode 100644 index 0000000000000000000000000000000000000000..9904464f95da9bf68af27d7fcdc0cb2c99b236db --- /dev/null +++ b/entrega/solucion.md @@ -0,0 +1,753 @@ +```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() +``` + + + + + + + + +```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> + + + + + + + + + + +```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> + + + + + + + + + + +```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> + + + + + + + + + + +```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> + + + + + + + + + +### 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>] + + + + + + + + + + +```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> + + + + + + + + + + +```python +plt.imshow(T_PART, cmap = 'gray') +plt.title("original blanco y negro") +plt.colorbar() +``` + + + + + <matplotlib.colorbar.Colorbar at 0x7feaee6479b0> + + + + + + + + + + +```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> + + + + + + + + + + +```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> + + + + + + + + + + +```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> + + + + + + + + + + +```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> + + + + + + + + + + +```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> + + + + + + + + + +## 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> + + + + + + + + + +### 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> + + + + + + + + + + +```python +plt.axes([0.025,0.025,0.95,0.95]) +plt.xlim(bb[1],bb[2]), plt.xticks([]) +plt.ylim(bb[3],bb[4]), plt.yticks([]) +plt.scatter(ui,uj,s=70, c = ulum, alpha=5) +plt.colorbar() +plt.show() + +##NOTA, LA IMAGEN ESTA ROTADA +``` + + + + + + + +## Se haria el ciclo sobre todas las estrellas +### Se haria en este ciclo cada uno de los analisis imponiendo las condiciones que yo quiera + + +```python +for x in range (2,3,1): ## cuando termine funcion de fitear hay si pongo x en el rango que es + for y in range (2,3,1): + AA_PART= img_part(x,y,imgttt_copy) + a=[0,0] + while a[0]>-1: + a=tanteo(x,y,0,0) + ubicar_estrella(x,y,a[0],a[1],AA_PART) + +plt.imshow(AA_PART, cmap = 'gray') +plt.title("parte blanco y negro") +plt.colorbar() +``` + + + + + <matplotlib.colorbar.Colorbar at 0x7feab797a828> + + + + + + + + + +### Funcion para analizar cada estrella + + +```python + +``` + + +```python +ui +uj +ulum +``` + +## :( + + +```python +def gauss2D(xdata_tuple,a, b, c, x0, y0): + (X,Y)=xdata_tuple + X, Y = np.meshgrid(ui, uj) + exponente= -((x-x0)**2 + (y-y0)**2) / (2*c**2) + z= a * np.exp(exponente) + b + return z + +``` + + +```python +p0 = [10., 100., 4. ,2. , 2.] +curve_fit(gauss2D, [X,Y] , ulum ,p0 ) +``` + + +```python + xData = numpy.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]) + yData = numpy.array([11.0, 12.1, 13.0, 14.1, 15.0, 16.1, 17.0, 18.1, 90.0]) + zData = numpy.array([1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.0, 9.9]) + + data = [xData, yData, zData] + + initialParameters = [1.0, 1.0, 1.0] # these are the same as scipy default values in this example + + # here a non-linear surface fit is made with scipy's curve_fit() + fittedParameters, pcov = scipy.optimize.curve_fit(func, [xData, yData], zData, p0 = initialParameters) + + ScatterPlot(data) + SurfacePlot(func, data, fittedParameters) + ContourPlot(func, data, fittedParameters) + + #print('fitted prameters', fittedParameters) + + modelPredictions = func(data, *fittedParameters) + + absError = modelPredictions - zData + + SE = numpy.square(absError) # squared errors + MSE = numpy.mean(SE) # mean squared errors + RMSE = numpy.sqrt(MSE) # Root Mean Squared Error, RMSE + Rsquared = 1.0 - (numpy.var(absError) / numpy.var(zData)) + #print('RMSE:', RMSE) + #print('R-squared:', Rsquared) +``` + + +```python +def gauss2D( X,Y , a, b, c, x0, y0): + exponente= -((X-x0)**2 + (Y-y0)**2) / (2*c**2) + z= a * np.exp(exponente) + b + return z +``` + + +```python +import matplotlib.pyplot as plt + +x = ui +y = uj +X, Y = np.meshgrid(ui, uj) #sparse=True +z = np.sin(xx + yy) +h = plt.contourf(x,y,z) + +plt.show() +``` + + + + + + + + +```python +def SurfacePlot(func, data, fittedParameters): + f = plt.figure(figsize=(graphWidth/100.0, graphHeight/100.0), dpi=100) + + matplotlib.pyplot.grid(True) + axes = Axes3D(f) + + xModel = numpy.linspace(min(ui), max(ui), 20) + yModel = numpy.linspace(min(uj), max(uj), 20) + X, Y = numpy.meshgrid(xModel, yModel) + + Z = func(numpy.array([X, Y]), *fittedParameters) + + axes.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm, linewidth=1, antialiased=True) + + axes.scatter(x_data, y_data, z_data) # show data along with plotted surface + + axes.set_title('Surface Plot (click-drag with mouse)') # add a title for surface plot + axes.set_xlabel('X Data') # X axis data label + axes.set_ylabel('Y Data') # Y axis data label + axes.set_zlabel('Z Data') # Z axis data label + + plt.show() + plt.close('all') # clean up after using pyplot or else there can be memory and process problems + + +``` + + +```python + +```