-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDSHG_solex_util.py
76 lines (70 loc) · 1.86 KB
/
DSHG_solex_util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""
@author: Valerie Desnoux
with improvements by Andrew Smith
Version 1 August 2021
"""
import numpy as np
import matplotlib.pyplot as plt
from astropy.io import fits
from scipy.interpolate import interp1d
import os
#import time
from scipy.signal import savgol_filter
import cv2
import sys
import math
from scipy.ndimage import gaussian_filter1d
mylog=[]
def clearlog():
mylog.clear()
def logme(s):
print(s)
mylog.append(s+'\n')
def detect_bord (img, axis, offset):
#axis donne la direction de detection des bords si 1 vertical, ou 0 horiz
#offset decalage la coordonnée pour prendre en compte le lissage gaussien
ih=img.shape[0]
iw=img.shape[1]
if axis==1:
# Determination des limites de la projection du soleil sur l'axe Y
ymean=np.mean(img,1)
#plt.plot(ymean)
#plt.title('Profil Y')
#plt.show()
ymean=gaussian_filter1d(ymean, 11)
yth=np.gradient(ymean)
y1=yth.argmax()-offset
y2=yth.argmin()+offset
if y1<=11:
y1=0
if y2>ih-11:
y2=ih
a1=y1
a2=y2
#plt.plot(yth)
#plt.title('Gradient Profil Y - filtre gaussien')
#plt.show()
else:
# Determination des limites de la projection du soleil sur l'axe X
# Elimine artefact de bords
xmean=np.mean(img[10:,:-10],0)
#plt.title('Profil X ')
#plt.plot(xmean)
#plt.show()
b=np.max(xmean)
bb=b*0.5
xmean[xmean>bb]=bb
xmean=gaussian_filter1d(xmean, 11)
xth=np.gradient(xmean)
#plt.plot(xth)
#plt.title('Gradient Profil X - filtre gaussien ')
#plt.show()
x1=xth.argmax()-offset
x2=xth.argmin()+offset
#test si pas de bord en x
if x1<=11 or x2>iw:
x1=0
x2=iw
a1=x1
a2=x2
return (a1,a2)