Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PySegCNN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
earth_observation_public
PySegCNN
Commits
a199b0a2
Commit
a199b0a2
authored
4 years ago
by
Frisinghelli Daniel
Browse files
Options
Downloads
Patches
Plain Diff
Added a function to calculate the extent of a low-resolution pixel in a high resolution image.
parent
b8ae911e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pysegcnn/core/utils.py
+65
-0
65 additions, 0 deletions
pysegcnn/core/utils.py
with
65 additions
and
0 deletions
pysegcnn/core/utils.py
+
65
−
0
View file @
a199b0a2
...
...
@@ -2271,3 +2271,68 @@ def extract_by_mask(src_ds, mask_ds, trg_ds, overwrite=False):
# clear source and mask dataset
del
src_ds
,
mask_ds
def
pixels_within_lowres
(
top_left
,
res_prop
):
"""
Calculate the position of high-res pixels within a low-res pixel.
.. important:
This function assumes that the low-resolution and high-resolution image
have the same georeferenced origin, i.e. the same top left corner in
physical coordinates.
Parameters
----------
top_left : `tuple`
The top left corner indices of the low-resolution pixel in the
low-resolution image.
res_prop : `int` or `float`
The proportion of the low-resolution to the high-resolution.
Returns
-------
indices : `tuple` [:py:class:`numpy.ndarray`]
The indices of the high-resolution pixels within the high-resolution
image, which are fully-covered by the extent of the low-resolution
pixel ``top_left``.
Example
-------
The resolution of the low-resolution image is 250m, the one of the
high-resolution image is 30m, thus ``res_prop=250/30``. Assume that the
top left corner of the pixel of interest in the low-resolution image is
given by the position ``top_left=(0, 1)``. In the high-resolution
image, the top left corner of the pixel of interest is hence located
at ``top_left * res_prop``. This function returns the indices of all
the pixels in the high-resolution image, which are fully-covered by
the low-resolution pixel with position ``top-left``.
"""
# the top left corner of a pixel in the low resolution image
xtl_lres
,
ytl_lres
=
top_left
# Note: only high-resolution pixel which are fully-covered by the
# low-resolution pixel are considered.
# the top left corner of the first pixel in the high resolution image,
# which lies within the extent of the low-resolution pixel
xtl_hres
,
ytl_hres
=
(
np
.
ceil
(
xtl_lres
*
res_prop
).
astype
(
np
.
int
),
np
.
ceil
(
ytl_lres
*
res_prop
).
astype
(
np
.
int
))
# the bottom right corner of last pixel in the high resolution image,
# which lies within the extent of the low-resolution pixel
xbl_hres
,
ybl_hres
=
(
np
.
floor
((
xtl_lres
+
1
)
*
res_prop
).
astype
(
np
.
int
),
np
.
floor
((
ytl_lres
+
1
)
*
res_prop
).
astype
(
np
.
int
))
# the range of the indices in the high-resolution image
xhres
=
np
.
arange
(
xtl_hres
,
xbl_hres
,
1
)
yhres
=
np
.
arange
(
ytl_hres
,
ybl_hres
,
1
)
# the indices of all the high-resolution pixels, which fully lie within
# the extent of the low-resolution pixel
indices
=
(
np
.
repeat
(
xhres
,
repeats
=
len
(
yhres
)),
np
.
tile
(
yhres
,
reps
=
len
(
xhres
)))
return
indices
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment