Spaces:
Sleeping
Sleeping
gdal new test
Browse files- app.py +1 -56
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -4,6 +4,7 @@ from io import BytesIO, TextIOWrapper
|
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
from deepdespeckling.despeckling import get_denoiser, get_model_weights_path
|
|
|
|
| 7 |
from deepdespeckling.utils.constants import PATCH_SIZE, STRIDE_SIZE
|
| 8 |
|
| 9 |
st.set_page_config(layout="wide", page_title="Deepdespeckling")
|
|
@@ -15,62 +16,6 @@ st.write(
|
|
| 15 |
st.sidebar.write("## Upload and download :gear:")
|
| 16 |
|
| 17 |
|
| 18 |
-
def cos2mat(path_to_cosar_image: str) -> np.array:
|
| 19 |
-
"""Convert a CoSAR imge to a numpy array of size [ncolumns,nlines,2]
|
| 20 |
-
|
| 21 |
-
Args:
|
| 22 |
-
path_to_cosar_image (str): path to the image which is a cos file
|
| 23 |
-
|
| 24 |
-
Returns:
|
| 25 |
-
numpy array : the image in a numpy array
|
| 26 |
-
"""
|
| 27 |
-
|
| 28 |
-
print('Converting CoSAR to numpy array of size [ncolumns,nlines,2]')
|
| 29 |
-
|
| 30 |
-
try:
|
| 31 |
-
fin = open(path_to_cosar_image, 'rb')
|
| 32 |
-
except IOError:
|
| 33 |
-
legx = path_to_cosar_image + ': it is a not openable file'
|
| 34 |
-
print(legx)
|
| 35 |
-
print(u'failed to call cos2mat')
|
| 36 |
-
return 0, 0, 0, 0
|
| 37 |
-
|
| 38 |
-
ibib = struct.unpack(">i", fin.read(4))[0]
|
| 39 |
-
irsri = struct.unpack(">i", fin.read(4))[0]
|
| 40 |
-
irs = struct.unpack(">i", fin.read(4))[0]
|
| 41 |
-
ias = struct.unpack(">i", fin.read(4))[0]
|
| 42 |
-
ibi = struct.unpack(">i", fin.read(4))[0]
|
| 43 |
-
irtnb = struct.unpack(">i", fin.read(4))[0]
|
| 44 |
-
itnl = struct.unpack(">i", fin.read(4))[0]
|
| 45 |
-
|
| 46 |
-
nlig = struct.unpack(">i", fin.read(4))[0]
|
| 47 |
-
ncoltot = int(irtnb / 4)
|
| 48 |
-
ncol = ncoltot - 2
|
| 49 |
-
nlig = ias
|
| 50 |
-
|
| 51 |
-
print(u'Reading image in CoSAR format. ncolumns=%d nlines=%d' % (ncol, nlig))
|
| 52 |
-
|
| 53 |
-
firm = np.zeros(4 * ncoltot, dtype=np.byte())
|
| 54 |
-
imgcxs = np.empty([nlig, ncol], dtype=np.complex64())
|
| 55 |
-
|
| 56 |
-
fin.seek(0)
|
| 57 |
-
firm = fin.read(4 * ncoltot)
|
| 58 |
-
firm = fin.read(4 * ncoltot)
|
| 59 |
-
firm = fin.read(4 * ncoltot)
|
| 60 |
-
firm = fin.read(4 * ncoltot)
|
| 61 |
-
|
| 62 |
-
for iut in range(nlig):
|
| 63 |
-
firm = fin.read(4 * ncoltot)
|
| 64 |
-
imgligne = np.ndarray(2 * ncoltot, '>h', firm)
|
| 65 |
-
imgcxs[iut, :] = imgligne[4:2 * ncoltot:2] + \
|
| 66 |
-
1j * imgligne[5:2 * ncoltot:2]
|
| 67 |
-
|
| 68 |
-
print('[:,:,0] contains the real part of the SLC image data')
|
| 69 |
-
print('[:,:,1] contains the imaginary part of the SLC image data')
|
| 70 |
-
|
| 71 |
-
return np.stack((np.real(imgcxs), np.imag(imgcxs)), axis=2)
|
| 72 |
-
|
| 73 |
-
|
| 74 |
def convert_image(img):
|
| 75 |
buf = BytesIO()
|
| 76 |
img.save(buf, format="PNG")
|
|
|
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
from deepdespeckling.despeckling import get_denoiser, get_model_weights_path
|
| 7 |
+
from deepdespeckling.utils.load_cosar import cos2mat
|
| 8 |
from deepdespeckling.utils.constants import PATCH_SIZE, STRIDE_SIZE
|
| 9 |
|
| 10 |
st.set_page_config(layout="wide", page_title="Deepdespeckling")
|
|
|
|
| 16 |
st.sidebar.write("## Upload and download :gear:")
|
| 17 |
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
def convert_image(img):
|
| 20 |
buf = BytesIO()
|
| 21 |
img.save(buf, format="PNG")
|
requirements.txt
CHANGED
|
@@ -1,3 +1,4 @@
|
|
| 1 |
deepdespeckling
|
| 2 |
pillow
|
| 3 |
numpy
|
|
|
|
|
|
| 1 |
deepdespeckling
|
| 2 |
pillow
|
| 3 |
numpy
|
| 4 |
+
GDAL
|