-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Visualization of a SAR image as a ground surface added #24
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e905e6b
ground surface visualization added
MargrietGroenendijk 7aa74a6
Merge branch 'main' into mg/ground_scene
MargrietGroenendijk 0650296
python formatted
MargrietGroenendijk 2b1c261
updated parameter names for style=ground
MargrietGroenendijk b4e89e0
ground_schema check added
MargrietGroenendijk d13dc52
formatting with black
MargrietGroenendijk ff912eb
updated parameter names for the ground visulaization
MargrietGroenendijk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Copyright 2022 TileDB Inc. | ||
# Licensed under the MIT License. | ||
"""Functions to format data from the arrays to be used in the visualization.""" | ||
|
||
# from array import array | ||
import io | ||
import json | ||
from datetime import datetime | ||
import numpy as np | ||
import pandas as pd | ||
import cv2 | ||
import tiledb | ||
|
||
|
||
def create_mbrs(array_uri: str): | ||
"""Create a Dict to be passed on to BabylonMBRS to create MBRS outlines.""" | ||
fragments_info = tiledb.array_fragments(array_uri, include_mbrs=True) | ||
|
||
df = pd.DataFrame() | ||
|
||
f = 0 | ||
for fragment in fragments_info.mbrs: | ||
f += 1 | ||
b = 0 | ||
for box in fragment: | ||
b += 1 | ||
box_dict = { | ||
"fragment": f, | ||
"box": b, | ||
"xmin": box[0][0], | ||
"xmax": box[0][1], | ||
"ymin": box[1][0], | ||
"ymax": box[1][1], | ||
"zmin": box[2][0], | ||
"zmax": box[2][1], | ||
} | ||
box_df = pd.DataFrame([box_dict]) | ||
df = pd.concat([df, box_df], ignore_index=True) | ||
|
||
data = { | ||
"Xmin": df["xmin"], | ||
"Xmax": df["xmax"], | ||
"Ymin": df["ymin"], | ||
"Ymax": df["ymax"], | ||
"Zmin": df["zmin"], | ||
"Zmax": df["zmax"], | ||
} | ||
|
||
extents = [ | ||
min(df["xmin"].tolist()), | ||
max(df["xmax"].tolist()), | ||
min(df["ymin"].tolist()), | ||
max(df["ymax"].tolist()), | ||
min(df["zmin"].tolist()), | ||
max(df["zmax"].tolist()), | ||
] | ||
|
||
return dict(extents=extents, data=data) | ||
|
||
|
||
def create_ground(array_uri: str, **kwargs): | ||
"""Create a Dict to be passed on to BabylonGround containing images as blobs. | ||
|
||
Parameters: | ||
array_uri: uri of the dense array | ||
attribute: the attribute to load from the array | ||
xy_bbox: ranges of x and y to slice data on [x1,x2,y1,y2] | ||
band: band number to slice from the array | ||
scale_factor: factor to scale the values in the image | ||
""" | ||
|
||
def numpy_to_binary(arr): | ||
is_success, buffer = cv2.imencode(".png", arr) | ||
io_buf = io.BytesIO(buffer) | ||
return io_buf.read() | ||
|
||
bbox = kwargs["xy_bbox"] | ||
band = kwargs["band"] | ||
image_type = kwargs["image_type"] | ||
sar_scale_factor = kwargs["sar_scale_factor"] | ||
|
||
with tiledb.open(array_uri, "r") as arr: | ||
img = arr[band, bbox[0] : bbox[1], bbox[2] : bbox[3]][kwargs["attribute"]] | ||
|
||
if image_type == "sar": | ||
img = 20 * np.log10(img * sar_scale_factor) | ||
img = ((img - np.min(img)) / (np.max(img) - np.min(img))) * 255 | ||
binary_image = numpy_to_binary(img) | ||
|
||
[img_height, img_width] = np.shape(img) | ||
|
||
return dict(data=binary_image, img_width=img_width, img_height=img_height) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,8 @@ | |
"dev": [ | ||
"matplotlib", | ||
"python-pdal", | ||
"pandas", | ||
"cv2", | ||
], | ||
}, | ||
url=pkg_json["homepage"], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whitespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed