Spaces:
Sleeping
Sleeping
use local cos2mat function
Browse files
app.py
CHANGED
|
@@ -5,8 +5,6 @@ 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 |
-
from deepdespeckling.utils.load_cosar import cos2mat
|
| 9 |
-
from deepdespeckling.utils.utils import load_sar_image
|
| 10 |
|
| 11 |
st.set_page_config(layout="wide", page_title="Deepdespeckling")
|
| 12 |
|
|
@@ -16,7 +14,61 @@ st.write(
|
|
| 16 |
)
|
| 17 |
st.sidebar.write("## Upload and download :gear:")
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
|
| 22 |
def convert_image(img):
|
|
|
|
| 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")
|
| 10 |
|
|
|
|
| 14 |
)
|
| 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):
|
requirements.txt
CHANGED
|
@@ -1,7 +1,3 @@
|
|
| 1 |
deepdespeckling
|
| 2 |
pillow
|
| 3 |
numpy
|
| 4 |
-
geopandas
|
| 5 |
-
osgeo
|
| 6 |
-
./wheelhouse/GDAL-3.4.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl
|
| 7 |
-
|
|
|
|
| 1 |
deepdespeckling
|
| 2 |
pillow
|
| 3 |
numpy
|
|
|
|
|
|
|
|
|
|
|
|
wheelhouse/GDAL-3.4.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:2da982c14b04a6a5181f8ea423cff3081f7447cccb861e27b02dbdc59e1d3ee4
|
| 3 |
-
size 76026316
|
|
|
|
|
|
|
|
|
|
|
|