Replies: 2 comments
|
yes. it should be. |
|
Yes. The current With the current release: python -m pip install -U segment-geospatialfrom samgeo import SamGeo
sam = SamGeo(model_type="vit_h", automatic=True)
sam.generate(
"dem.tif",
output="dem_segments.tif",
unique=True,
foreground=True,
)
sam.tiff_to_vector("dem_segments.tif", "dem_segments.gpkg")Relevant source: However, simply copying elevation into R/G/B does not add information—the three channels remain identical. It only makes the tensor shape compatible with a model trained mainly on natural RGB imagery. Whether the masks are useful depends on whether boundaries are visually expressed in the DEM values. For terrain features, a more informative three-channel visualization is often:
For example: import numpy as np
import rasterio
from matplotlib.colors import LightSource
def stretch(a, valid):
lo, hi = np.percentile(a[valid], (2, 98))
out = np.clip((a - lo) / max(hi - lo, 1e-6), 0, 1)
return (out * 255).astype("uint8")
with rasterio.open("dem.tif") as src:
dem = src.read(1, masked=True).astype("float32")
profile = src.profile.copy()
valid = ~np.ma.getmaskarray(dem)
filled = dem.filled(np.nanmedian(dem[valid]))
# Account for pixel spacing when calculating the gradient.
dy, dx = np.gradient(filled, abs(src.transform.e), abs(src.transform.a))
slope = np.hypot(dx, dy)
hillshade = LightSource(azdeg=315, altdeg=45).hillshade(filled)
rgb = np.stack([
stretch(filled, valid),
(hillshade * 255).astype("uint8"),
stretch(slope, valid),
])
rgb[:, ~valid] = 0
profile.update(count=3, dtype="uint8", nodata=0)
with rasterio.open("dem_terrain_rgb.tif", "w", **profile) as dst:
dst.write(rgb)Then run SAM on Two important limitations:
So: a single-band DEM is supported directly, but a terrain-derivative composite is usually the better experiment when the target boundaries depend on landform rather than absolute elevation. |
Uh oh!
There was an error while loading. Please reload this page.
Would it be possible to use SAM with single-band rasters such as DEMs?
My understanding that SAM is intended to work with 3-bands such as RGB. However, could a DEM be converted to a 3-band raster to take advantage of SAM?
All reactions