Making transparent in Custom Algorithms #757
Answered
by
vincentsarago
sairahul1526
asked this question in
Q&A
Replies: 1 comment 3 replies
-
@sairahul1526 are you using the latest version of titiler? if yes, the class Mask(BaseAlgorithm):
min: int
max: int
def __call__(self, img: ImageData) -> ImageData:
# Create a mask where values are within the specified range
valid_mask = (img.data[0] >= self.min) & (img.data[0] <= self.max)
# Apply the mask: keep data as is where valid, else set to 0
data = numpy.where(valid_mask, img.data, 0)
# # Update the transparency mask: 255 (opaque) for valid data, 0 (transparent) otherwise
modified_mask = numpy.where(valid_mask, 255, 0)
arr = numpy.ma.MaskedArray(data, mask=modified_mask)
# Create a new ImageData instance with the modified data and transparency mask
return ImageData(arr, assets=img.assets, crs=img.crs, bounds=img.bounds) |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I wanted to make some values in a band transparent using Custom Algos
Read it here: #745
Below is the code
I was able to make the values as 0 but not able to make them transparent in output.
Any help on this? How to show pixel values transparent?
Beta Was this translation helpful? Give feedback.
All reactions