Skip to content

Making transparent in Custom Algorithms #757

Answered by vincentsarago
sairahul1526 asked this question in Q&A
Discussion options

You must be logged in to vote
"""titiler.core.algorithm Mask."""

import numpy
from rio_tiler.models import ImageData

from titiler.core.algorithm.base import BaseAlgorithm


class Mask(BaseAlgorithm):
    """Mask values between bounds."""
    # parameters
    min: float
    max: float

    def __call__(self, img: ImageData) -> ImageData:
        """Normalized difference."""
        # Create a mask where values in the first band are within the specified range
        valid_mask = (img.array >= self.min) & (img.array <= self.max)

        # Apply the mask to 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 dat…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@sairahul1526
Comment options

@vincentsarago
Comment options

Answer selected by sairahul1526
@sairahul1526
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants