Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
GeoSentinel
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mario Chirinos Colunga
GeoSentinel
Commits
b92b4013
Commit
b92b4013
authored
May 14, 2018
by
Alfonso Ramire Pedraza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update
parent
2dcff62f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
113 deletions
+35
-113
Index.py
geosentinel/Index.py
+1
-0
Merge.py
geosentinel/Merge.py
+34
-113
No files found.
geosentinel/Index.py
View file @
b92b4013
...
@@ -37,6 +37,7 @@ class Index(object):
...
@@ -37,6 +37,7 @@ class Index(object):
Args:
Args:
self: The object pointer.
self: The object pointer.
ResolSize (str): destination directory.
IndexType (str): # NDVI - Normalized Difference Vegetation Index, NDWI - Normalized Difference Water Index, NBAI - Normalized Built-up Area Index
IndexType (str): # NDVI - Normalized Difference Vegetation Index, NDWI - Normalized Difference Water Index, NBAI - Normalized Built-up Area Index
Returns:
Returns:
...
...
geosentinel/Merge.py
View file @
b92b4013
...
@@ -6,40 +6,41 @@ Example:
...
@@ -6,40 +6,41 @@ Example:
$ python -m doctest -v Merge.py
$ python -m doctest -v Merge.py
"""
"""
""" Class for Sentinel satellites configuration
Test Case
"""
import
os
,
sys
import
os
,
sys
from
os.path
import
expanduser
from
os.path
import
expanduser
home
=
expanduser
(
"~"
)
home
=
expanduser
(
"~"
)
a
=
os
.
path
.
join
(
os
.
path
.
expandvars
(
home
),
".snap/snap-python/"
)
a
=
os
.
path
.
join
(
os
.
path
.
expandvars
(
home
),
".snap/snap-python/"
)
sys
.
path
.
append
(
a
)
sys
.
path
.
append
(
a
)
import
cv2
import
snappy
,
numpy
import
snappy
,
numpy
from
snappy
import
jpy
,
ProductData
,
ProgressMonitor
,
ProductUtils
from
snappy
import
jpy
,
ProductData
,
ProgressMonitor
,
ProductUtils
from
tools
import
(
tools
)
from
tools
import
(
tools
)
from
readProduct
import
(
readProduct
)
from
readProduct
import
(
readProduct
)
jpy
=
snappy
.
jpy
Color
=
jpy
.
get_type
(
'java.awt.Color'
)
ColorPoint
=
jpy
.
get_type
(
'org.esa.snap.core.datamodel.ColorPaletteDef$Point'
)
ColorPaletteDef
=
jpy
.
get_type
(
'org.esa.snap.core.datamodel.ColorPaletteDef'
)
ImageInfo
=
jpy
.
get_type
(
'org.esa.snap.core.datamodel.ImageInfo'
)
ImageLegend
=
jpy
.
get_type
(
'org.esa.snap.core.datamodel.ImageLegend'
)
JAI
=
jpy
.
get_type
(
'javax.media.jai.JAI'
)
System
=
jpy
.
get_type
(
'java.lang.System'
)
System
.
setProperty
(
'com.sun.media.jai.disableMediaLib'
,
'true'
)
class
Merge
(
object
):
class
Merge
(
object
):
""" Class for Sentinel satellites configuration
Test Case
>>> Files = tools("all") #IW_SLC,IW_GRDH,MSIL1C
>>> dir="make/"
>>> platform='Sentinel-2'
>>> list_files=Files.findFilesSentinel(dir,platform,4)#4 for resample_subset.dim
>>> print 'There is/are
%
d '
%
len(list_files) + platform + ' file(s)'
>>> Read=readProduct(dir,platform)
>>> TypeMerge="RGB"
>>> Mergee=Merge("60",TypeMerge)
>>> for image in list_files:
... file = dir + image
... print"Applying SubSet... ", image
... product=Read.ReadFilesSentinel(file,2)#The flag 2 ReadFiles .dim
... Mergee.merges(product, file)
"""
def
__init__
(
self
,
ResolSize
,
TypeMerge
):
def
__init__
(
self
,
ResolSize
,
TypeMerge
):
"""The constructor Initialize Sentinel Data.
"""The constructor Initialize Sentinel Data.
Args:
Args:
self: The object pointer.
self: The object pointer.
folder (str): destination directory.
ResolSize (str): destination directory.
TypeMerge (str): RGB
Returns:
Returns:
pointer: The object pointer.
pointer: The object pointer.
...
@@ -53,104 +54,24 @@ class Merge(object):
...
@@ -53,104 +54,24 @@ class Merge(object):
self
.
ImageManager
=
jpy
.
get_type
(
'org.esa.snap.core.image.ImageManager'
)
self
.
ImageManager
=
jpy
.
get_type
(
'org.esa.snap.core.image.ImageManager'
)
(
self
.
h
,
self
.
w
)
=
(
None
,
None
)
(
self
.
h
,
self
.
w
)
=
(
None
,
None
)
def
merges
(
self
,
product
,
products
,
file
):
def
merges
(
self
,
product
,
file
):
##blue = product.getBand('B2')
"""Index Files Sentinel
##green = product.getBand('B3')
##red = product.getBand('B4')
##width = product.getSceneRasterWidth()
##height = product.getSceneRasterHeight()
##RGB = [green,red, blue]#Bueno
#################################################################################
#RES = []
#for i in range(len(RGB)):
# Band = ProductData.createInstance(numpy.zeros((width, height), numpy.uint16))
# RGB[i].readRasterData(0, 0, width, height, Band)
# RES.append(Band)
# Image without georreference
##info = ProductUtils.createImageInfo(RGB, True, ProgressMonitor.NULL)
##image = ProductUtils.createRgbImage(RGB, info, ProgressMonitor.NULL)
# print"Wrinting PNG..."
Args:
##salida = file[:-4] + self.Type_Merge + self.ext
self (pointer): The object pointer.
##savefile = self.File(salida)
product (bin): Metadata Sentinel.
##self.looks.writeImage(image, savefile)
file (str): local path to image.
######################################################################################
#salida = file[:-5] + self.Type_Merge+ self.ext
#image_info = ProductUtils.createImageInfo(RGB, True, ProgressMonitor.NULL)
#im = self.ImageManager.getInstance().createColoredBandImage(RGB, image_info, 0)
#JAI.create("filestore", im, salida, "JPEG-LS")
##TotImage = len(products)
##print"IMAGES...",products
#sys.exit()
# Get Raster
#dataset1 = gdal.Open(products[2], GA_ReadOnly)
#dataset2 = gdal.Open(products[1], GA_ReadOnly)
#dataset3 = gdal.Open(products[0], GA_ReadOnly)
##dataset1=cv2.imread(products[2], cv2.IMREAD_UNCHANGED)#B4 R
##dataset2=cv2.imread(products[1], cv2.IMREAD_UNCHANGED)#B3 G
##dataset3=cv2.imread(products[0], cv2.IMREAD_UNCHANGED)#B2 B
##salida = file[:-5] + self.Type_Merge
##image = cv2.merge((dataset3, dataset2, dataset1))
##cv2.imwrite(salida + '.jpg', image)
########################################################################
red
=
Image
.
open
(
products
[
2
])
.
convert
(
'L'
)
"""
blue
=
Image
.
open
(
products
[
0
])
blue
=
product
.
getBand
(
'B2'
)
green
=
Image
.
open
(
products
[
1
])
green
=
product
.
getBand
(
'B3'
)
red
=
product
.
getBand
(
'B4'
)
out
=
Image
.
merge
(
"RGB"
,
(
red
,
green
,
blue
))
RGB
=
[
red
,
green
,
blue
]
out
.
save
(
"img-out.TIF"
)
#https://gis.stackexchange.com/questions/180534/merge-rgb-band-using-python
#https://stackoverflow.com/questions/30227466/combine-several-images-horizontally-with-python
#https://gist.github.com/glombard/7cd166e311992a828675
#https://pillow.readthedocs.io/en/3.1.x/reference/Image.html
#https://stackoverflow.com/questions/32812547/working-with-jp2-image-on-python-pillow
def
search_band_combination
(
self
,
sentinel_image
,
Type_Merge
):
info
=
ProductUtils
.
createImageInfo
(
RGB
,
True
,
ProgressMonitor
.
NULL
)
Granule
=
"/GRANULE"
image
=
ProductUtils
.
createRgbImage
(
RGB
,
info
,
ProgressMonitor
.
NULL
)
path
=
sentinel_image
+
Granule
file
=
os
.
listdir
(
path
)
path
=
path
+
"/"
+
file
[
0
]
Img_Data
=
"/IMG_DATA"
path
=
path
+
Img_Data
file
=
os
.
listdir
(
path
)
products
=
[]
if
Type_Merge
==
"RGB"
:
ext1
=
"B04.jp2"
ext2
=
"B03.jp2"
ext3
=
"B02.jp2"
raster
=
[
f
for
f
in
file
if
f
.
endswith
(
ext1
)
or
f
.
endswith
(
ext2
)
or
f
.
endswith
(
ext3
)]
for
raster
in
raster
:
product
=
path
+
"/"
+
raster
a
=
os
.
path
.
join
(
os
.
path
.
expandvars
(
home
),
product
)
products
.
append
(
a
)
#combinations_bands_sentinel(sentinel_image, Type_Merge, products)
return
products
#Applying Index Flag=3 Search .dim files
salida
=
file
[:
-
4
]
+
self
.
Type_Merge
+
self
.
ext
#Find Sentinel Files
savefile
=
self
.
File
(
salida
)
Files
=
tools
(
"all"
)
#IW_SLC,IW_GRDH,MSIL1C
self
.
looks
.
writeImage
(
image
,
savefile
)
#dir="C:\Users\Garantias723\Documents\Poncho\Image_Sentinel"
\ No newline at end of file
dir
=
"make/"
platform
=
'Sentinel-2'
list_files
=
Files
.
findFilesSentinel
(
dir
,
platform
,
2
)
#4 for resample_subset.dim
print
'There is/are
%
d '
%
len
(
list_files
)
+
platform
+
' file(s)'
#Read Sentinel Files
Read
=
readProduct
(
dir
,
platform
)
#Applying Resampling
TypeMerge
=
"RGB"
Mergee
=
Merge
(
"60"
,
TypeMerge
)
for
image
in
list_files
:
#file = dir + "/" + image
file
=
dir
+
image
products
=
Mergee
.
search_band_combination
(
file
,
TypeMerge
)
print
"Applying SubSet... "
,
image
product
=
Read
.
ReadFilesSentinel
(
file
,
2
)
#The flag 2 ReadFiles .dim
Mergee
.
merges
(
product
,
products
,
file
)
#Mergee.merges(product, file)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment