Skip to content

Add crs and transform for array input #400

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

Merged
merged 2 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions samgeo/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1458,12 +1458,16 @@ def array_to_image(
array = cv2.imread(array)
array = cv2.cvtColor(array, cv2.COLOR_BGR2RGB)

if output.endswith(".tif") and source is not None:
with rasterio.open(source) as src:
crs = src.crs
transform = src.transform
if compress is None:
compress = src.compression
if output.endswith(".tif"):
if source is not None:
with rasterio.open(source) as src:
crs = src.crs
transform = src.transform
if compress is None:
compress = src.compression
else:
crs = kwargs.get("crs", None)
transform = kwargs.get("transform", None)

# Determine the minimum and maximum values in the array

Expand Down
10 changes: 5 additions & 5 deletions samgeo/samgeo.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,11 @@ def show_anns(
img[m] = color_mask
ax.imshow(img)

if "dpi" not in kwargs:
kwargs["dpi"] = 100
# if "dpi" not in kwargs:
# kwargs["dpi"] = 100

if "bbox_inches" not in kwargs:
kwargs["bbox_inches"] = "tight"
# if "bbox_inches" not in kwargs:
# kwargs["bbox_inches"] = "tight"

plt.axis(axis)

Expand All @@ -442,7 +442,7 @@ def show_anns(
)
else:
array = self.annotations
array_to_image(array, output, self.source)
array_to_image(array, output, self.source, **kwargs)

def set_image(self, image, image_format="RGB"):
"""Set the input image as a numpy array.
Expand Down
10 changes: 5 additions & 5 deletions samgeo/samgeo2.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,11 @@ def show_anns(
img[m] = color_mask
ax.imshow(img)

if "dpi" not in kwargs:
kwargs["dpi"] = 100
# if "dpi" not in kwargs:
# kwargs["dpi"] = 100

if "bbox_inches" not in kwargs:
kwargs["bbox_inches"] = "tight"
# if "bbox_inches" not in kwargs:
# kwargs["bbox_inches"] = "tight"

plt.axis(axis)

Expand All @@ -473,7 +473,7 @@ def show_anns(
)
else:
array = self.annotations
common.array_to_image(array, output, self.source)
common.array_to_image(array, output, self.source, **kwargs)

@torch.no_grad()
def set_image(
Expand Down
Loading