Skip to content
Snippets Groups Projects
Commit 85063239 authored by Miguel Angel Bulla Rivas's avatar Miguel Angel Bulla Rivas
Browse files

Primer desarrollo de la tarea. Se logra crear la imagen combinando RGB-planes...

Primer desarrollo de la tarea. Se logra crear la imagen combinando RGB-planes con una combinación de pesos específico. También se logra hacer el primer ajuste, particularmente a la estrella más brillante.
parent 076ba35b
Branches master
No related tags found
No related merge requests found
Showing
with 5309 additions and 0 deletions
source diff could not be displayed: it is too large. Options to address this: view the blob.
source diff could not be displayed: it is too large. Options to address this: view the blob.
source diff could not be displayed: it is too large. Options to address this: view the blob.
source diff could not be displayed: it is too large. Options to address this: view the blob.
```python
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
zapatocaImage = plt.imread('zapatocaImage.jpeg')
plt.imshow(zapatocaImage[:,:,0], cmap='gray')
```
<matplotlib.image.AxesImage at 0x7f9cc66ceac8>
![png](Image_Analysing-Star1_files/Image_Analysing-Star1_0_1.png)
```python
zapatocaImage.shape
```
(789, 1184, 3)
```python
bs1 = 0.2989 * zapatocaImage[:,:,0]
bs1 = bs1.astype(int)
bs2 = 0.5870 * zapatocaImage[:,:,1]
bs2 = bs2.astype(int)
bs3 = 0.1140 * zapatocaImage[:,:,2]
bs3 = bs3.astype(int)
blckndwht_star1 = bs1 +bs2 + bs3
#plt.imshow(bs3, cmap='gray', vmin=0, vmax=255)
#plt.imshow(bs1 +bs2 + bs3)
```
```python
plt.imshow(blckndwht_star1)
#plt.imshow(blckndwht_star1, cmap='gray')
#plt.imshow(blckndwht_star1, cmap='gray', vmin=0, vmax=255)
plt.colorbar()
```
<matplotlib.colorbar.Colorbar at 0x7f9c653d83c8>
![png](Image_Analysing-Star1_files/Image_Analysing-Star1_3_1.png)
```python
#plt.imshow(blckndwht_star1[543:564,648:677])
plt.imshow(blckndwht_star1[543:564,652:673])
#plt.imshow(blckndwht_star1[543:564,648:677], vmin=0, vmax=255)
plt.colorbar()
```
<matplotlib.colorbar.Colorbar at 0x7f9c65328940>
![png](Image_Analysing-Star1_files/Image_Analysing-Star1_4_1.png)
```python
#x_axis = np.linspace(-14,14,29)
x_axis = np.linspace(-10,10,21)
y_axis = np.linspace(-10,10,21)
xx_axis, yy_axis = np.meshgrid(x_axis, y_axis)
xx_axis.shape
```
(21, 21)
```python
#star1 = blckndwht_star1[543:564,648:677].copy()
star1 = blckndwht_star1[543:564,652:673].copy()
star1_nrmlzd = star1/255
#star1_nrmlzd_int = star1_nrmlzd.astype(int)
```
```python
from scipy.optimize import leastsq
from scipy.optimize import curve_fit
```
```python
def gauss2D_str1(X, a=255, b=0, c=1, x0=0, y0=0):
x,y = X
exponente = -((x-x0)**2 + (y-y0)**2) / (2*c**2)
z = a * np.exp(exponente) + b
#print(z)
return z
```
```python
#x_axis = np.linspace(-14,14,29)
#y_axis = np.linspace(-10,10,21)
#p0_star1 = 0., 5.
#print(curve_fit(gauss2D_str1, (x_axis,y_axis), z_exp_star1, p0_star1))
```
```python
#gauss2D_str1((x_axis,y_axis),a,b,c).shape
#gauss2D_str1((x_axis,y_axis),255., 0., 5., 0.0, 0.0).shape
#gauss2D_str1((x_axis,y_axis), a=1, b=0, c=3, x0=0, y0=0)
gauss2D_str1((x_axis,y_axis), 1, 0, 3, 0, 0).shape
```
(21,)
```python
gauss2D_str1((x_axis,y_axis), 1, 0, 3, 0, 0)[0]
```
1.4945338524781451e-05
```python
gauss2D_str1((x_axis,y_axis), 1, 0, 3, 0, 0)[10]
```
1.0
```python
gauss2D_str1((x_axis,y_axis), 1, 0, 3, 0, 0)[20]
```
1.4945338524781451e-05
```python
yprueba = gauss2D_str1((x_axis,y_axis), 1, 0, 3, 0, 0)
plt.plot(x_axis,yprueba,"r-")
```
[<matplotlib.lines.Line2D at 0x7f9c3c016dd8>]
![png](Image_Analysing-Star1_files/Image_Analysing-Star1_14_1.png)
```python
plt.plot(y_axis,yprueba,"r-")
```
[<matplotlib.lines.Line2D at 0x7f9c3bf846a0>]
![png](Image_Analysing-Star1_files/Image_Analysing-Star1_15_1.png)
```python
x_exp = np.arange(0,21,1)
y_exp = np.arange(0,21,1)
x_exp
```
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20])
```python
temppx_xpp ,temppy_ypp = (x_exp,y_exp)
```
```python
star1_nrmlzd[temppx_xpp,temppy_ypp] == star1_nrmlzd[temppy_ypp,temppx_xpp]
```
array([ True, True, True, True, True, True, True, True, True,
True, True, True, True, True, True, True, True, True,
True, True, True])
```python
```
```python
def star1_exp_func(X_exp, x_whch):
tempx_exp ,tempy_exp = X_exp
#star1_nrmlzd
tempz_exp = np.array([])
if x_whch == 'Through_x-axis':
tempz_exp = np.append(tempz_exp, star1_nrmlzd[tempx_exp ,tempy_exp] )
#star1_nrmlzd[,]
#z_exp
return tempz_exp
elif x_whch == 'Through_y-axis':
tempz_exp = np.append(tempz_exp, star1_nrmlzd[tempy_exp ,tempx_exp] )
return tempz_exp
```
```python
z_expstar1_thrghx = star1_exp_func((x_exp ,y_exp), 'Through_x-axis') #.shape
```
```python
z_expstar1_thrghy = star1_exp_func((x_exp,y_exp), 'Through_y-axis') #.shape
```
```python
plt.plot(x_axis,z_expstar1_thrghx,"r-")
```
[<matplotlib.lines.Line2D at 0x7f9c3bf560f0>]
![png](Image_Analysing-Star1_files/Image_Analysing-Star1_23_1.png)
```python
plt.plot(x_axis,z_expstar1_thrghy,"r-")
```
[<matplotlib.lines.Line2D at 0x7f9c3bedf080>]
![png](Image_Analysing-Star1_files/Image_Analysing-Star1_24_1.png)
```python
#p0_star1= np.array([255, 0, 5, 0, 0])
# [a=255, b=0, c=5, x0=0, y0=0]
# exponente = -((x-x0)**2 + (y-y0)**2) / (2*c**2)
# z = a * np.exp(exponente) + b
#
p0_star1= np.array([1, 0, 3.5, 0, 0])
print(curve_fit(gauss2D_str1, (x_axis,y_axis),
z_expstar1_thrghx,p0_star1)[0][2])
#z_expstar1_thrghY
print(curve_fit(gauss2D_str1, (x_axis,y_axis),
z_expstar1_thrghy,p0_star1)[0][2])
```
4.126063711744642
4.126063711744642
/home/bullam/.local/lib/python3.7/site-packages/scipy/optimize/minpack.py:829: OptimizeWarning: Covariance of the parameters could not be estimated
category=OptimizeWarning)
```python
p0_star1= np.array([1, 0, 5, 0, 0])
print(curve_fit(gauss2D_str1, (x_axis,y_axis),
z_expstar1_thrghx,p0_star1)[0][2])
print(curve_fit(gauss2D_str1, (x_axis,y_axis),
z_expstar1_thrghy,p0_star1)[0][2])
```
4.928611745994732
4.928611745994732
```python
#z_expstar1_thrghX
p0_star1= np.array([1, 0, 7, 0, 0])
print(curve_fit(gauss2D_str1, (x_axis,y_axis),
z_expstar1_thrghx,p0_star1)[0][2])
#p0_star1= np.array([1, 0, 7, 0, 0])
print(curve_fit(gauss2D_str1, (x_axis,y_axis),
z_expstar1_thrghy,p0_star1)[0][2])
```
4.874353706666568
4.874353706666568
```python
p0_star1= np.array([1, 0, curve_fit(gauss2D_str1, (x_axis,y_axis),
z_expstar1_thrghy,p0_star1)[0][2], 0, 0])
print(curve_fit(gauss2D_str1, (x_axis,y_axis),
z_expstar1_thrghx,p0_star1)[0][2])
print(curve_fit(gauss2D_str1, (x_axis,y_axis),
z_expstar1_thrghy,p0_star1)[0][2])
```
4.875021346933124
4.875021346933124
```python
p0_star1= np.array([1, 0, 17, 0, 0])
print(curve_fit(gauss2D_str1, (x_axis,y_axis),
z_expstar1_thrghx,p0_star1)[0][2])
print(curve_fit(gauss2D_str1, (x_axis,y_axis),
z_expstar1_thrghy,p0_star1)[0][2])
```
4.87435369702605
4.87435369702605
## c es aproximadamente igual a 4.8743
```python
p0_star1= np.array([1, 0, 6, 0, 0])
print(curve_fit(gauss2D_str1, (x_axis,y_axis),
z_expstar1_thrghx,p0_star1)[0][0])
print(curve_fit(gauss2D_str1, (x_axis,y_axis),
z_expstar1_thrghx,p0_star1)[0][1])
print(curve_fit(gauss2D_str1, (x_axis,y_axis),
z_expstar1_thrghx,p0_star1)[0][2])
print(curve_fit(gauss2D_str1, (x_axis,y_axis),
z_expstar1_thrghx,p0_star1)[0][3])
print(curve_fit(gauss2D_str1, (x_axis,y_axis),
z_expstar1_thrghx,p0_star1)[0][4])
#p0_star1= np.array([1, 0, 7, 0, 0])
#print(curve_fit(gauss2D_str1, (x_axis,y_axis),
# z_expstar1_thrghy,p0_star1)[0][1])
```
0.5729727621590178
0.46791300710503303
4.874353709858581
0.9316969381425967
-0.7084043204480968
```python
yprueba1 = gauss2D_str1((x_axis,y_axis), 0.5729727621590178, 0.46791300710503303, 4.874353709858581, 0.9316969381425967, -0.7084043204480968)
plt.plot(x_axis,yprueba,"r-")
```
[<matplotlib.lines.Line2D at 0x7f9c39e692b0>]
![png](Image_Analysing-Star1_files/Image_Analysing-Star1_32_1.png)
```python
```
```python
```
```python
import matplotlib.cm as cm
from mpl_toolkits.mplot3d import Axes3D
z_model_star1 = gauss2D_str1((xx_axis,yy_axis), a=1, b=0, c=3, x0=0, y0=0)
#z_model_star1 = gauss2D_str1((x_axis,y_axis), a=1, b=0, c=3, x0=0, y0=0)
ax_star1 = Axes3D(plt.figure())
ax_star1.plot_surface(xx_axis,yy_axis,z_model_star1,vmax=abs(z_model_star1).max(), vmin=-abs(z_model_star1).max(), cmap=cm.RdYlGn, rstride=1,cstride=1)
plt.show()
#x = y = np.arange(-3.0, 3.0, 0.25)
#X, Y = np.meshgrid(x, y)
#def f(x,y):
# return (1-x/2+x**5+y**3)*np.exp(-x**2-y**2)
#Z1 = f(X,Y)
#ax = Axes3D(plt.figure()) # creando el cubo
#ax.plot_surface(X,Y,Z1,vmax=abs(Z1).max(), vmin=-abs(Z1).max(), cmap=cm.RdYlGn, rstride=1,cstride=1)
#plt.show()
```
![png](Image_Analysing-Star1_files/Image_Analysing-Star1_35_0.png)
```python
z_model_star1.shape
```
(21, 21)
```python
#z_model_star2 = gauss2D_str1((xx_axis,yy_axis), a=1, b=0, c=3, x0=0, y0=0)
z_model_star2 = gauss2D_str1((xx_axis,yy_axis),
0.5729727621590178, 0.46791300710503303, 4.874353709858581, 0.9316969381425967, -0.7084043204480968)
#plt.plot(x_axis,yprueba,"r-")
#z_model_star1 = gauss2D_str1((x_axis,y_axis), a=1, b=0, c=3, x0=0, y0=0)
ax_star1_patentado = Axes3D(plt.figure())
ax_star1_patentado.plot_surface(xx_axis,yy_axis,z_model_star2,vmax=abs(z_model_star2).max(), vmin=-abs(z_model_star2).max(), cmap=cm.RdYlGn, rstride=1,cstride=1)
plt.show()
```
![png](Image_Analysing-Star1_files/Image_Analysing-Star1_37_0.png)
```python
xx_exp, yy_exp = np.meshgrid(x_exp, y_exp)
#z_model_star2 = gauss2D_str1((xx_axis,yy_axis), a=1, b=0, c=3, x0=0, y0=0)
#star1_exp_func((x_exp ,y_exp), 'Through_x-axis')
#z_model_star1 = gauss2D_str1((x_axis,y_axis), a=1, b=0, c=3, x0=0, y0=0)
ax_star1_patentado = Axes3D(plt.figure())
ax_star1_patentado.plot_surface(xx_exp,yy_exp,star1_nrmlzd ,vmax=abs(z_model_star2).max(), vmin=-abs(z_model_star2).max(), cmap=cm.RdYlGn, rstride=1,cstride=1)
#ax_star1_patentado.plot_surface(xx_axis,yy_axis,z_exp_star3,vmax=abs(z_model_star2).max(), vmin=-abs(z_model_star2).max(), cmap=cm.RdYlGn, rstride=1,cstride=1)
plt.show()
```
![png](Image_Analysing-Star1_files/Image_Analysing-Star1_38_0.png)
```python
```
data/Image_Analysing-Star1_files/Image_Analysing-Star1_0_1.png

69.6 KiB

data/Image_Analysing-Star1_files/Image_Analysing-Star1_14_1.png

8.99 KiB

data/Image_Analysing-Star1_files/Image_Analysing-Star1_15_1.png

8.99 KiB

data/Image_Analysing-Star1_files/Image_Analysing-Star1_23_1.png

9.47 KiB

data/Image_Analysing-Star1_files/Image_Analysing-Star1_24_1.png

9.47 KiB

data/Image_Analysing-Star1_files/Image_Analysing-Star1_32_1.png

8.99 KiB

data/Image_Analysing-Star1_files/Image_Analysing-Star1_35_0.png

48.6 KiB

data/Image_Analysing-Star1_files/Image_Analysing-Star1_37_0.png

53.1 KiB

data/Image_Analysing-Star1_files/Image_Analysing-Star1_38_0.png

52.1 KiB

data/Image_Analysing-Star1_files/Image_Analysing-Star1_3_1.png

64.7 KiB

data/Image_Analysing-Star1_files/Image_Analysing-Star1_4_1.png

8.32 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment