Skip to content

Color

Classes for point colors

NormalizeColor

Normalize point-wise color features into a target value range [low, high].

This transform expects a dictionary containing:

  • "color": NumPy array of shape (N, 3) with point color values.

If range255 is True, input colors are assumed to be in [0, 255] and are first scaled to [0, 1] by dividing by 255. Otherwise, they are assumed to already be in [0, 1].

The normalized [0, 1] values are then mapped linearly to [low, high] such that:

  • 0 → low
  • 1 → high

Parameters:

Name Type Description Default
low float

Lower bound of the target color range. Defaults to -1.0.

-1.0
high float

Upper bound of the target color range. Must be greater than low. Defaults to 1.0.

1.0
range255 bool

Whether the input color values are in [0, 255]. If True, values are divided by 255.0 before mapping. If False, values are used as-is (assumed to be in [0, 1]). Defaults to False.

False
Source code in src\augmentation_class.py
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
@TRANSFORMS.register()
class NormalizeColor:
    """Normalize point-wise color features into a target value range ``[low, high]``.

    This transform expects a dictionary containing:

    * `"color"`: NumPy array of shape (N, 3) with point color values.

    If `range255` is True, input colors are assumed to be in `[0, 255]` and are
    first scaled to `[0, 1]` by dividing by 255. Otherwise, they are assumed
    to already be in `[0, 1]`.

    The normalized `[0, 1]` values are then mapped linearly to `[low, high]`
    such that:

    * 0 → low
    * 1 → high

    Args:
        low (float, optional):
            Lower bound of the target color range.
            Defaults to -1.0.
        high (float, optional):
            Upper bound of the target color range. Must be greater than `low`.
            Defaults to 1.0.
        range255 (bool, optional):
            Whether the input color values are in `[0, 255]`. If True, values are divided by 255.0 before mapping.
            If False, values are used as-is (assumed to be in `[0, 1]`).
            Defaults to False.
    """
    def __init__(self, low: float = -1., high: float = 1., range255=False):
        assert high > low
        self.low = low
        self.high = high
        self.range255 = range255

    def __call__(self, data_dict: dict) -> dict:
        """Normalize the `"color"` entry in `data_dict` into `[low, high]`.

        Args:
            data_dict (dict): Input dictionary that must contain a `"color"` key with a NumPy array of shape (N, 3)
                representing point color values.

        Returns:
            dict: The same dictionary with `"color"` normalized into `[low, high]`, if present.
        """
        if "color" in data_dict.keys():
            # data_dict["color"] = data_dict["color"] / 127.5 - 1
            normalized_color = data_dict["color"] / 255. if self.range255 else data_dict["color"]  # [0, 1]
            tmp = (self.high - self.low)
            data_dict["color"] = (normalized_color - 1.0) * tmp + self.high
        return data_dict

__call__(data_dict)

Normalize the "color" entry in data_dict into [low, high].

Parameters:

Name Type Description Default
data_dict dict

Input dictionary that must contain a "color" key with a NumPy array of shape (N, 3) representing point color values.

required

Returns:

Name Type Description
dict dict

The same dictionary with "color" normalized into [low, high], if present.

Source code in src\augmentation_class.py
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
def __call__(self, data_dict: dict) -> dict:
    """Normalize the `"color"` entry in `data_dict` into `[low, high]`.

    Args:
        data_dict (dict): Input dictionary that must contain a `"color"` key with a NumPy array of shape (N, 3)
            representing point color values.

    Returns:
        dict: The same dictionary with `"color"` normalized into `[low, high]`, if present.
    """
    if "color" in data_dict.keys():
        # data_dict["color"] = data_dict["color"] / 127.5 - 1
        normalized_color = data_dict["color"] / 255. if self.range255 else data_dict["color"]  # [0, 1]
        tmp = (self.high - self.low)
        data_dict["color"] = (normalized_color - 1.0) * tmp + self.high
    return data_dict

ChromaticAutoContrast

Apply chromatic auto-contrast to point colors with optional blending.

This transform expects a dictionary containing:

  • "color": NumPy array of shape (N, 3) with point color values.

The transform computes per-channel minimum and maximum over the whole point set, linearly stretches each channel to the target range, and then blends this auto-contrasted result with the original colors using a blend_factor.

Parameters:

Name Type Description Default
blend_factor float | None

Weight used to blend the original colors with the auto-contrasted colors:

out = (1 - blend_factor) * original + blend_factor * contrasted

If a float in [0, 1], the same value is used for every call. If None, a new random value in [0, 1] is sampled on each call. Defaults to None.

None
range255 bool

Whether the input color values are in [0, 255]. If True, the auto-contrast maps into [0, 255]. If False, it maps into [0, 1]. Defaults to False.

False
apply_p float

Probability of applying the auto-contrast. Defaults to 1.0.

1.0
Source code in src\augmentation_class.py
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
@TRANSFORMS.register()
class ChromaticAutoContrast:
    """Apply chromatic auto-contrast to point colors with optional blending.

    This transform expects a dictionary containing:

    * `"color"`: NumPy array of shape (N, 3) with point color values.

    The transform computes per-channel minimum and maximum over the whole point set,
    linearly stretches each channel to the target range, and then blends this auto-contrasted
    result with the original colors using a `blend_factor`.

    Args:
        blend_factor (float | None, optional):
            Weight used to blend the original colors with the auto-contrasted colors:

                out = (1 - blend_factor) * original + blend_factor * contrasted

            If a float in [0, 1], the same value is used for every call. If ``None``, a new random
            value in [0, 1] is sampled on each call.
            Defaults to ``None``.
        range255 (bool, optional):
            Whether the input color values are in `[0, 255]`. If True, the auto-contrast maps into `[0, 255]`. If
            False, it maps into `[0, 1]`.
            Defaults to False.
        apply_p (float, optional):
            Probability of applying the auto-contrast.
            Defaults to 1.0.
    """
    def __init__(self, blend_factor: float = None, range255=False, apply_p: float = 1.0):
        self.blend_factor = blend_factor
        self.range255 = range255
        self.apply_p = apply_p


    def __call__(self, data_dict: dict) -> dict:
        """Apply chromatic auto-contrast to the first 3 color channels.

        Args:
            data_dict (dict): Input dictionary that must contain a `"color"` key with a NumPy array of shape (N, 3)
                representing point color values.

        Returns:
            dict: The same dictionary with `"color"` updated in-place, if applied.
        """

        if random.random() > self.apply_p:
            return data_dict

        if "color" in data_dict.keys():
            dtype = data_dict["color"].dtype
            if self.range255:
                target_range = 255.0
            else:
                target_range = 1.0

            # choose blend for this call
            blend_factor = np.random.rand() if self.blend_factor is None else self.blend_factor

            # Apply autocontrast calculation
            lo = np.min(data_dict["color"], axis=0, keepdims=True)
            hi = np.max(data_dict["color"], axis=0, keepdims=True)

            # Prevent division by zero if hi == lo
            scale = target_range / (hi - lo + 1e-6)  # Add small epsilon for stability

            # Apply contrast adjustment to the first 3 color channels
            contrast_feat = (data_dict["color"][:, :3] - lo[:, :3]) * scale[:, :3]

            # Blend the original with the contrasted feature
            # Ensure the blending maintains the data type
            blended_color = (1 - blend_factor) * data_dict["color"][:, :3] + blend_factor * contrast_feat

            # Clip values to ensure they stay within the target range [0, target_range]
            # and convert to the appropriate data type
            data_dict["color"][:, :3] = np.clip(blended_color, 0, target_range).astype(dtype)

        return data_dict

__call__(data_dict)

Apply chromatic auto-contrast to the first 3 color channels.

Parameters:

Name Type Description Default
data_dict dict

Input dictionary that must contain a "color" key with a NumPy array of shape (N, 3) representing point color values.

required

Returns:

Name Type Description
dict dict

The same dictionary with "color" updated in-place, if applied.

Source code in src\augmentation_class.py
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
def __call__(self, data_dict: dict) -> dict:
    """Apply chromatic auto-contrast to the first 3 color channels.

    Args:
        data_dict (dict): Input dictionary that must contain a `"color"` key with a NumPy array of shape (N, 3)
            representing point color values.

    Returns:
        dict: The same dictionary with `"color"` updated in-place, if applied.
    """

    if random.random() > self.apply_p:
        return data_dict

    if "color" in data_dict.keys():
        dtype = data_dict["color"].dtype
        if self.range255:
            target_range = 255.0
        else:
            target_range = 1.0

        # choose blend for this call
        blend_factor = np.random.rand() if self.blend_factor is None else self.blend_factor

        # Apply autocontrast calculation
        lo = np.min(data_dict["color"], axis=0, keepdims=True)
        hi = np.max(data_dict["color"], axis=0, keepdims=True)

        # Prevent division by zero if hi == lo
        scale = target_range / (hi - lo + 1e-6)  # Add small epsilon for stability

        # Apply contrast adjustment to the first 3 color channels
        contrast_feat = (data_dict["color"][:, :3] - lo[:, :3]) * scale[:, :3]

        # Blend the original with the contrasted feature
        # Ensure the blending maintains the data type
        blended_color = (1 - blend_factor) * data_dict["color"][:, :3] + blend_factor * contrast_feat

        # Clip values to ensure they stay within the target range [0, target_range]
        # and convert to the appropriate data type
        data_dict["color"][:, :3] = np.clip(blended_color, 0, target_range).astype(dtype)

    return data_dict

Chromatic AutoContrast PC Colors

Before After

ChromaticAutoContrastPercent

Apply percentile-based chromatic auto-contrast with optional blending.

This transform expects a dictionary containing:

  • "color": NumPy array of shape (N, 3) with point color values.

This is similar to ChromaticAutoContrast, but instead of using the absolute min/max per channel, it uses the 1st and 99th percentiles as low/high boundaries. This makes the transform effective even when:

  • The input already spans the full range (e.g., lo=0.0, hi=1.0), or
  • There are outliers that would otherwise dominate the min/max.

Parameters:

Name Type Description Default
blend_factor float | None

Blending weight between the original and auto-contrasted colors. If a float in [0, 1], the same value is used for every call. If None, a new random value in [0, 1) is sampled on each call. Defaults to None.

None
range255 bool

Whether the input color values are in [0, 255]. If True, the auto-contrast maps into [0, 255]. If False, it maps into [0, 1]. Defaults to False.

False
apply_p float

Probability of applying the auto-contrast. Defaults to 1.0.

1.0
Source code in src\augmentation_class.py
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
@TRANSFORMS.register()
class ChromaticAutoContrastPercent:
    """Apply percentile-based chromatic auto-contrast with optional blending.

    This transform expects a dictionary containing:

    * `"color"`: NumPy array of shape (N, 3) with point color values.

    This is similar to ``ChromaticAutoContrast``, but instead of using the absolute min/max per channel,
    it uses the 1st and 99th percentiles as low/high boundaries. This makes the transform effective even when:

    * The input already spans the full range (e.g., `lo=0.0`, `hi=1.0`), or
    * There are outliers that would otherwise dominate the min/max.


    Args:
        blend_factor (float | None, optional):
            Blending weight between the original and auto-contrasted colors. If a float in [0, 1], the
            same value is used for every call. If ``None``, a new random value in [0, 1) is sampled on each call.
            Defaults to ``None``.
        range255 (bool, optional):
            Whether the input color values are in `[0, 255]`. If True, the auto-contrast maps into `[0, 255]`.
            If False, it maps into `[0, 1]`.
            Defaults to False.
        apply_p (float, optional):
            Probability of applying the auto-contrast.
            Defaults to 1.0.
    """
    def __init__(self, blend_factor: float = None, range255=False, apply_p: float = 1.0):
        self.blend_factor = blend_factor
        self.range255 = range255
        self.apply_p = apply_p


    def __call__(self, data_dict: dict) -> dict:
        """Apply percentile-based chromatic auto-contrast to the point color.
        Args:
            data_dict (dict): Input dictionary that must contain a `"color"` key with a NumPy array of shape (N, 3)
                representing point color values.

        Returns:
            dict: The same dictionary with `"color"` updated in-place, if applied.
        """
        if random.random() > self.apply_p:
            return data_dict

        if "color" in data_dict.keys():
            dtype = data_dict["color"].dtype
            if self.range255:
                target_range = 255.0
            else:
                target_range = 1.0
            blend_factor = np.random.rand() if self.blend_factor is None else self.blend_factor

            # Apply autocontrast calculation, calculate 1% and 99% of the value among each channels
            low_p, high_p = 1, 99
            lo = np.percentile(data_dict["color"][:, :3], low_p, axis=0, keepdims=True)
            hi = np.percentile(data_dict["color"][:, :3], high_p, axis=0, keepdims=True)

            # Prevent division by zero if hi == lo
            scale = target_range / (hi - lo + 1e-6)  # Add small epsilon for stability

            # Apply contrast adjustment to the first 3 color channels
            contrast_feat = (data_dict["color"][:, :3] - lo[:, :3]) * scale[:, :3]

            # Blend the original with the contrasted feature
            # Ensure the blending maintains the data type
            blended_color = (1 - blend_factor) * data_dict["color"][:, :3] + blend_factor * contrast_feat

            # Clip values to ensure they stay within the target range [0, target_range]
            # and convert to the appropriate data type
            data_dict["color"][:, :3] = np.clip(blended_color, 0, target_range).astype(dtype)

        return data_dict

__call__(data_dict)

Apply percentile-based chromatic auto-contrast to the point color. Args: data_dict (dict): Input dictionary that must contain a "color" key with a NumPy array of shape (N, 3) representing point color values.

Returns:

Name Type Description
dict dict

The same dictionary with "color" updated in-place, if applied.

Source code in src\augmentation_class.py
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
def __call__(self, data_dict: dict) -> dict:
    """Apply percentile-based chromatic auto-contrast to the point color.
    Args:
        data_dict (dict): Input dictionary that must contain a `"color"` key with a NumPy array of shape (N, 3)
            representing point color values.

    Returns:
        dict: The same dictionary with `"color"` updated in-place, if applied.
    """
    if random.random() > self.apply_p:
        return data_dict

    if "color" in data_dict.keys():
        dtype = data_dict["color"].dtype
        if self.range255:
            target_range = 255.0
        else:
            target_range = 1.0
        blend_factor = np.random.rand() if self.blend_factor is None else self.blend_factor

        # Apply autocontrast calculation, calculate 1% and 99% of the value among each channels
        low_p, high_p = 1, 99
        lo = np.percentile(data_dict["color"][:, :3], low_p, axis=0, keepdims=True)
        hi = np.percentile(data_dict["color"][:, :3], high_p, axis=0, keepdims=True)

        # Prevent division by zero if hi == lo
        scale = target_range / (hi - lo + 1e-6)  # Add small epsilon for stability

        # Apply contrast adjustment to the first 3 color channels
        contrast_feat = (data_dict["color"][:, :3] - lo[:, :3]) * scale[:, :3]

        # Blend the original with the contrasted feature
        # Ensure the blending maintains the data type
        blended_color = (1 - blend_factor) * data_dict["color"][:, :3] + blend_factor * contrast_feat

        # Clip values to ensure they stay within the target range [0, target_range]
        # and convert to the appropriate data type
        data_dict["color"][:, :3] = np.clip(blended_color, 0, target_range).astype(dtype)

    return data_dict

Chromatic AutoContrast Percentage PC Colors

Before After

ChromaticTranslation

Apply random global color translation to the point color.

This transform expects a dictionary containing:

  • "color": NumPy array of shape (N, 3) with point color values.

For each call (with some probability), it samples a random translation vector tr in a bounded range and adds it to all color values:

tr ∈ [-target_range * ratio, target_range * ratio]^3

where target_range is 255.0 if range255=True, else 1.0. The result is then clipped back to [0, target_range] and cast to the original dtype.

Parameters:

Name Type Description Default
ratio float

Maximum relative translation magnitude as a fraction of the full range. For range255=True, each channel offset lies in:

[-255 * ratio, 255 * ratio]

For range255=False, each channel offset lies in:

[-1.0 * ratio, 1.0 * ratio]

Defaults to 0.05.

0.05
range255 bool

Whether the input color values are in [0, 255]. If True, translations and clipping are done in that range. If False, they are done in [0, 1]. Defaults to False.

False
apply_p float

Probability of applying the chromatic translation. Defaults to 1.0.

1.0
Source code in src\augmentation_class.py
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
@TRANSFORMS.register()
class ChromaticTranslation:
    """Apply random global color translation to the point color.

    This transform expects a dictionary containing:

    * `"color"`: NumPy array of shape (N, 3) with point color values.

    For each call (with some probability), it samples a random translation
    vector `tr` in a bounded range and adds it to all color values:

        tr ∈ [-target_range * ratio, target_range * ratio]^3

    where `target_range` is 255.0 if `range255=True`, else 1.0. The result is
    then clipped back to `[0, target_range]` and cast to the original dtype.

    Args:
        ratio (float, optional):
            Maximum relative translation magnitude as a fraction of the full range. For `range255=True`, each channel
            offset lies in:

                [-255 * ratio, 255 * ratio]

            For `range255=False`, each channel offset lies in:

                [-1.0 * ratio, 1.0 * ratio]

            Defaults to 0.05.
        range255 (bool, optional):
            Whether the input color values are in `[0, 255]`. If True, translations and clipping are done in that
            range. If False, they are done in `[0, 1]`.
            Defaults to False.
        apply_p (float, optional):
            Probability of applying the chromatic translation.
            Defaults to 1.0.
    """
    def __init__(self, ratio: float = 0.05, range255=False, apply_p: float = 1.0):
        self.ratio = ratio
        self.range255 = range255
        self.apply_p = apply_p

    def __call__(self, data_dict: dict) -> dict:
        """Apply a random color translation to the first 3 channels.

        Args:
            data_dict (dict): Input dictionary that must contain a `"color"` key with a NumPy array of shape (N, 3)
                representing point color values.

        Returns:
            dict: The same dictionary with `"color"` updated in-place, if applied.
        """
        if random.random() > self.apply_p:
            return data_dict

        if "color" in data_dict.keys():
            dtype = data_dict["color"].dtype
            if self.range255:
                target_range = 255.0
            else:
                target_range = 1.0

            tr = (np.random.rand(1, 3) - 0.5) * target_range * 2 * self.ratio  # [-255 * ratio, 255 * ratio]
            data_dict["color"][:, :3] = np.clip(tr + data_dict["color"][:, :3], 0, target_range).astype(dtype)

        return data_dict

__call__(data_dict)

Apply a random color translation to the first 3 channels.

Parameters:

Name Type Description Default
data_dict dict

Input dictionary that must contain a "color" key with a NumPy array of shape (N, 3) representing point color values.

required

Returns:

Name Type Description
dict dict

The same dictionary with "color" updated in-place, if applied.

Source code in src\augmentation_class.py
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
def __call__(self, data_dict: dict) -> dict:
    """Apply a random color translation to the first 3 channels.

    Args:
        data_dict (dict): Input dictionary that must contain a `"color"` key with a NumPy array of shape (N, 3)
            representing point color values.

    Returns:
        dict: The same dictionary with `"color"` updated in-place, if applied.
    """
    if random.random() > self.apply_p:
        return data_dict

    if "color" in data_dict.keys():
        dtype = data_dict["color"].dtype
        if self.range255:
            target_range = 255.0
        else:
            target_range = 1.0

        tr = (np.random.rand(1, 3) - 0.5) * target_range * 2 * self.ratio  # [-255 * ratio, 255 * ratio]
        data_dict["color"][:, :3] = np.clip(tr + data_dict["color"][:, :3], 0, target_range).astype(dtype)

    return data_dict

Chromatic Translate PC Colors

Before After

ChromaticJitter

Add Gaussian noise (jitter) to point colors.

This transform expects a dictionary containing:

  • "color": NumPy array of shape (N, 3) with point color values.

It samples per-point, per-channel Gaussian noise and adds it to the channels:

noise ~ N(0, (std * target_range)^2)

where target_range is 255.0 if range255=True, else 1.0. The result is then clipped back to [0, target_range] and cast to the original dtype.

Parameters:

Name Type Description Default
std float

Standard deviation of the jitter, expressed as a fraction of the target range. The actual noise standard deviation per channel is:

sigma_noise = std * target_range

For example, with std=0.005 and range255=True, the noise standard deviation is 0.005 * 255 ≈ 1.275. Defaults to 0.005.

0.005
range255 bool

Whether the input color values are in [0, 255]. If True, noise and clipping are done in that range. If False, they are done in [0, 1]. Defaults to False.

False
apply_p float

Probability of applying the chromatic jitter. Defaults to 1.0.

1.0
Source code in src\augmentation_class.py
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
@TRANSFORMS.register()
class ChromaticJitter:
    """Add Gaussian noise (jitter) to point colors.

    This transform expects a dictionary containing:

    * `"color"`: NumPy array of shape (N, 3) with point color values.

    It samples per-point, per-channel Gaussian noise and adds it to the channels:

        noise ~ N(0, (std * target_range)^2)

    where `target_range` is 255.0 if `range255=True`, else 1.0. The result is then clipped back to `[0, target_range]`
    and cast to the original dtype.

    Args:
        std (float, optional):
            Standard deviation of the jitter, expressed as a fraction of the target range. The actual noise standard
            deviation per channel is:

                sigma_noise = std * target_range

            For example, with `std=0.005` and `range255=True`, the noise standard deviation is `0.005 * 255 ≈ 1.275`.
            Defaults to 0.005.
        range255 (bool, optional):
            Whether the input color values are in `[0, 255]`. If True, noise and clipping are done in that range.
            If False, they are done in `[0, 1]`.
            Defaults to False.
        apply_p (float, optional):
            Probability of applying the chromatic jitter.
            Defaults to 1.0.
    """
    def __init__(self, std: float = 0.005, range255=False, apply_p: float = 1.0):
        self.std = std
        self.range255 = range255
        self.apply_p = apply_p

    def __call__(self, data_dict: dict) -> dict:
        """Apply Gaussian color jitter to the first 3 channels.

        Args:
            data_dict (dict): Input dictionary that must contain a `"color"` key with a NumPy array of shape (N, 3)
                representing point color values.

        Returns:
            dict: The same dictionary with `"color"` jittered in-place, if applied.
        """
        if random.random() > self.apply_p:
            return data_dict

        if "color" in data_dict.keys():
            dtype = data_dict["color"].dtype
            if self.range255:
                target_range = 255.0
            else:
                target_range = 1.0

            noise = np.random.randn(data_dict["color"].shape[0], 3)
            noise = noise * self.std * target_range
            data_dict["color"][:, :3] = np.clip(noise + data_dict["color"][:, :3], 0, target_range).astype(dtype)

        return data_dict

__call__(data_dict)

Apply Gaussian color jitter to the first 3 channels.

Parameters:

Name Type Description Default
data_dict dict

Input dictionary that must contain a "color" key with a NumPy array of shape (N, 3) representing point color values.

required

Returns:

Name Type Description
dict dict

The same dictionary with "color" jittered in-place, if applied.

Source code in src\augmentation_class.py
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
def __call__(self, data_dict: dict) -> dict:
    """Apply Gaussian color jitter to the first 3 channels.

    Args:
        data_dict (dict): Input dictionary that must contain a `"color"` key with a NumPy array of shape (N, 3)
            representing point color values.

    Returns:
        dict: The same dictionary with `"color"` jittered in-place, if applied.
    """
    if random.random() > self.apply_p:
        return data_dict

    if "color" in data_dict.keys():
        dtype = data_dict["color"].dtype
        if self.range255:
            target_range = 255.0
        else:
            target_range = 1.0

        noise = np.random.randn(data_dict["color"].shape[0], 3)
        noise = noise * self.std * target_range
        data_dict["color"][:, :3] = np.clip(noise + data_dict["color"][:, :3], 0, target_range).astype(dtype)

    return data_dict

Chromatic Jitter PC Colors

Before After

RandomColorGrayScale

Randomly convert point colors to grayscale.

This transform expects a dictionary containing:

  • "color": NumPy array of shape (N, 3) with point color values.

It converts the "color" from RGB to grayscale using an NTSC-style luminance formula, and returns a 3-channel grayscale image (gray copied into R, G, B).

Parameters:

Name Type Description Default
apply_p float

Probability of converting colors to grayscale. Defaults to 1.0.

1.0
Source code in src\augmentation_class.py
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
@TRANSFORMS.register()
class RandomColorGrayScale:
    """Randomly convert point colors to grayscale.

    This transform expects a dictionary containing:

    * `"color"`: NumPy array of shape (N, 3) with point color values.

    It converts the `"color"` from RGB to grayscale using an NTSC-style luminance formula, and returns
    a 3-channel grayscale image (gray copied into R, G, B).

    Args:
        apply_p (float, optional):
            Probability of converting colors to grayscale.
            Defaults to 1.0.
    """
    def __init__(self, apply_p: float = 1.0):
        self.apply_p = apply_p

    @staticmethod
    def rgb_to_grayscale(color: np.ndarray, num_output_channels=1) -> np.ndarray:
        """Convert RGB colors to grayscale using an NTSC-style formula.

        Uses the luminance computation:

            gray = 0.2999 * R + 0.587 * G + 0.114 * B

        Args:
            color (np.ndarray):
                Input color array with shape (..., C), where C ≥ 3 and the last dimension contains RGB channels
                in positions 0, 1, 2.
            num_output_channels (int, optional):
                Number of channels in the output. Must be 1 or 3.

                * 1 → returns a single-channel grayscale array.
                * 3 → returns a 3-channel array with the grayscale value broadcast to R, G, B.

                Defaults to 1.

        Returns:
            gray (np.ndarray):
                Grayscale array with the same dtype as `color` and either 1 or 3 channels in the last dimension.
        """
        assert color.shape[-1] >= 3
        assert num_output_channels in (1, 3)
        r, g, b = color[..., 0], color[..., 1], color[..., 2]
        # NTSC formula
        gray = (0.2999 * r + 0.587 * g + 0.114 * b).astype(color.dtype)
        gray = np.expand_dims(gray, axis=-1)
        if num_output_channels == 3:
            gray = np.broadcast_to(gray, color.shape)

        return gray

    def __call__(self, data_dict: dict) -> dict:
        """Randomly convert `"color"` to grayscale in-place.

        Args:
            data_dict (dict): Input dictionary that must contain a `"color"` key with a NumPy array of shape (N, 3)
                representing point color values.

        Returns:
            dict: The same dictionary with `"color"` converted to 3-channel grayscale, if applied.
        """
        if random.random() > self.apply_p:
            return data_dict

        if "color" in data_dict.keys():
            data_dict["color"] = self.rgb_to_grayscale(data_dict["color"], 3)
        return data_dict

__call__(data_dict)

Randomly convert "color" to grayscale in-place.

Parameters:

Name Type Description Default
data_dict dict

Input dictionary that must contain a "color" key with a NumPy array of shape (N, 3) representing point color values.

required

Returns:

Name Type Description
dict dict

The same dictionary with "color" converted to 3-channel grayscale, if applied.

Source code in src\augmentation_class.py
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
def __call__(self, data_dict: dict) -> dict:
    """Randomly convert `"color"` to grayscale in-place.

    Args:
        data_dict (dict): Input dictionary that must contain a `"color"` key with a NumPy array of shape (N, 3)
            representing point color values.

    Returns:
        dict: The same dictionary with `"color"` converted to 3-channel grayscale, if applied.
    """
    if random.random() > self.apply_p:
        return data_dict

    if "color" in data_dict.keys():
        data_dict["color"] = self.rgb_to_grayscale(data_dict["color"], 3)
    return data_dict

Transfer PC Colors into GrayScale

Before After

RandomColorJitter

Random color jitter for 3D point cloud colors (similar to torchvision).

This transform expects a dictionary containing:

  • "color": NumPy array of shape (N, 3) with point color values.

At each call (with probability apply_p), it:

  1. Converts "color" to float in the range [0, 1].
  2. If range255=True, it divides by 255.
  3. Otherwise it assumes values are already in [0, 1] (or compatible).
  4. Randomly samples brightness, contrast, saturation, and hue factors within the ranges specified at initialization.
  5. Applies a random ordering of these adjustments (brightness, contrast, saturation, hue) to the colors.
  6. Clips the result to [0, 1].
  7. Converts back to the original dtype (and multiplies by 255 if range255=True).

The argument conventions follow torchvision's ColorJitter:

Parameters:

Name Type Description Default
brightness float | tuple[float, float]

How much to jitter brightness.

* If a single non-negative float ``b`` is given, the brightness
  factor is chosen uniformly from ``[max(0, 1 - b), 1 + b]``.
* If a tuple ``(b_min, b_max)`` is given, the brightness factor is
  chosen uniformly from ``[b_min, b_max]``.
* If set to 0 or (1.0, 1.0), no brightness change is applied.

Defaults to 0.

0
contrast float | tuple[float, float]

How much to jitter contrast. Same semantics as brightness (centered at 1.0). If set to 0 or (1.0, 1.0), no contrast change is applied. Defaults to 0.

0
saturation float | tuple[float, float]

How much to jitter saturation. Same semantics as brightness (centered at 1.0). If set to 0 or (1.0, 1.0), no saturation change is applied. Defaults to 0.

0
hue float | tuple[float, float]

How much to jitter hue.

  • If a single float h is given, the hue factor is chosen uniformly from [-h, h].
  • If a tuple (h_min, h_max) is given, it is chosen uniformly from [h_min, h_max].

Values must be in [-0.5, 0.5]. If set to 0 or (0.0, 0.0), no hue change is applied. Defaults to 0.

0
range255 bool

Whether the input color values are in [0, 255]. If True, values are converted to float in [0, 1] before jittering and converted back to [0, 255] afterwards. If False, values are treated as floats in [0, 1]. Defaults to False.

False
apply_p float

Probability of applying the color jitter. Defaults to 1.0.

1.0
Source code in src\augmentation_class.py
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
@TRANSFORMS.register()
class RandomColorJitter:
    """Random color jitter for 3D point cloud colors (similar to torchvision).

    This transform expects a dictionary containing:

    * `"color"`: NumPy array of shape (N, 3) with point color values.

    At each call (with probability ``apply_p``), it:

    1. Converts `"color"` to float in the range [0, 1].
       - If ``range255=True``, it divides by 255.
       - Otherwise it assumes values are already in [0, 1] (or compatible).
    2. Randomly samples brightness, contrast, saturation, and hue factors within the ranges specified at initialization.
    3. Applies a random ordering of these adjustments (brightness, contrast, saturation, hue) to the colors.
    4. Clips the result to [0, 1].
    5. Converts back to the original dtype (and multiplies by 255 if ``range255=True``).

    The argument conventions follow torchvision's ``ColorJitter``:

    Args:
        brightness (float | tuple[float, float], optional):
            How much to jitter brightness.

                * If a single non-negative float ``b`` is given, the brightness
                  factor is chosen uniformly from ``[max(0, 1 - b), 1 + b]``.
                * If a tuple ``(b_min, b_max)`` is given, the brightness factor is
                  chosen uniformly from ``[b_min, b_max]``.
                * If set to 0 or (1.0, 1.0), no brightness change is applied.

            Defaults to 0.
        contrast (float | tuple[float, float], optional):
            How much to jitter contrast. Same semantics as ``brightness`` (centered at 1.0).
            If set to 0 or (1.0, 1.0), no contrast change is applied.
            Defaults to 0.
        saturation (float | tuple[float, float], optional):
            How much to jitter saturation. Same semantics as ``brightness`` (centered at 1.0).
            If set to 0 or (1.0, 1.0), no saturation change is applied.
            Defaults to 0.
        hue (float | tuple[float, float], optional):
            How much to jitter hue.

            * If a single float ``h`` is given, the hue factor is chosen
              uniformly from ``[-h, h]``.
            * If a tuple ``(h_min, h_max)`` is given, it is chosen uniformly
              from ``[h_min, h_max]``.

            Values must be in ``[-0.5, 0.5]``. If set to 0 or (0.0, 0.0), no hue change is applied.
            Defaults to 0.
        range255 (bool, optional):
            Whether the input color values are in ``[0, 255]``. If True, values are converted to float in [0, 1]
            before jittering and converted back to [0, 255] afterwards. If False, values are treated as floats in [0, 1].
            Defaults to False.
        apply_p (float, optional):
            Probability of applying the color jitter.
            Defaults to 1.0.
    """
    def __init__(self, brightness=0, contrast=0, saturation=0, hue=0, range255=False, apply_p=1.0):
        self.brightness = self._check_input(brightness, "brightness")
        self.contrast = self._check_input(contrast, "contrast")
        self.saturation = self._check_input(saturation, "saturation")
        self.hue = self._check_input(hue, "hue", center=0, bound=(-0.5, 0.5), clip_first_on_zero=False)
        self.range255 = range255
        self.apply_p = apply_p

    @staticmethod
    def _check_input(value: int | float | tuple | list, name: str, center: float = 1, bound: tuple = (0, float("inf")),
                     clip_first_on_zero: bool = True):
        """Normalize jitter argument into a (min, max) interval or None.

        This helper follows torchvision's ``ColorJitter._check_input`` logic.

        Args:
            value (int | float | tuple | list):
                Jitter specification.
                    * Single number: interpreted as symmetric range around ``center``, i.e.
                    ``[center - value, center + value]``.
                    * Tuple/list of length 2: interpreted as explicit ``(min, max)``.
            name (str):
                Name of the parameter (for error messages).
            center (float, optional):
                Center value. Usually 1 for brightness/contrast/saturation, 0 for hue.
                Defaults to 1.
            bound (tuple[float, float], optional):
                Allowed bounds for the resulting interval.
                Defaults to ``(0, inf)``.
            clip_first_on_zero (bool, optional):
                If True and value is scalar, the lower bound is clipped at 0.0 (for cases like brightness or contrast).
                For hue, this is False.
                Defaults to True.

        Returns:
            value (list[float] | None):
                A 2-element list ``[min, max]`` if the range is non-trivial, or ``None`` if no change should be applied
                for this parameter.
        """
        if isinstance(value, (int, float)):
            if value < 0:
                raise ValueError(f"If {name} is a single number, it must be non negative.")
            value = [center - float(value), center + float(value)]
            if clip_first_on_zero:
                value[0] = max(value[0], 0.0)
        elif isinstance(value, (tuple, list)) and len(value) == 2:
            if not bound[0] <= value[0] <= value[1] <= bound[1]:
                raise ValueError(f"{name} values should be between {bound}")
        else:
            raise TypeError(f"{name} should be a single number or a list/tuple with length 2.")

        # if value is 0 or (1., 1.) for brightness/contrast/saturation
        # or (0., 0.) for hue, do nothing
        if value[0] == value[1] == center:
            value = None
        return value

    @staticmethod
    def blend(color1, color2, ratio):
        """Blend two color tensors with a given ratio.

        Computes:

            out = ratio * color1 + (1 - ratio) * color2

        and clips the result to [0, 1].

        Args:
            color1 (np.ndarray):
                First color array in [0, 1].
            color2 (np.ndarray):
                Second color array, broadcastable to color1.
            ratio (float):
                Blend ratio. 1.0 means all ``color1``, 0.0 means all ``color2``.

        Returns:
            np.ndarray:
                Blended color array with same dtype as ``color1``.
        """
        ratio = float(ratio)
        return (ratio * color1 + (1.0 - ratio) * color2).clip(0, 1.0).astype(color1.dtype)

    @staticmethod
    def rgb2hsv(rgb):
        """Convert RGB colors in [0, 1] to HSV.

        Args:
            rgb (np.ndarray):
            Array of shape (..., 3) with RGB channels in the last dimension.

        Returns:
            np.ndarray:
            Array of shape (..., 3) with HSV channels in the last dimension.
        """
        r, g, b = rgb[..., 0], rgb[..., 1], rgb[..., 2]
        maxc = np.max(rgb, axis=-1)
        minc = np.min(rgb, axis=-1)
        eqc = maxc == minc
        cr = maxc - minc
        s = cr / (np.ones_like(maxc) * eqc + maxc * (1 - eqc))
        cr_divisor = np.ones_like(maxc) * eqc + cr * (1 - eqc)
        rc = (maxc - r) / cr_divisor
        gc = (maxc - g) / cr_divisor
        bc = (maxc - b) / cr_divisor

        hr = (maxc == r) * (bc - gc)
        hg = ((maxc == g) & (maxc != r)) * (2.0 + rc - bc)
        hb = ((maxc != g) & (maxc != r)) * (4.0 + gc - rc)
        h = hr + hg + hb
        h = (h / 6.0 + 1.0) % 1.0
        return np.stack((h, s, maxc), axis=-1)

    @staticmethod
    def hsv2rgb(hsv):
        """Convert HSV colors in [0, 1] to RGB.

        Args:
            hsv (np.ndarray):
                Array of shape (..., 3) with HSV channels in the last dimension.

        Returns:
            np.ndarray:
                Array of shape (..., 3) with RGB channels in the last dimension.
        """
        h, s, v = hsv[..., 0], hsv[..., 1], hsv[..., 2]
        i = np.floor(h * 6.0)
        f = (h * 6.0) - i
        i = i.astype(np.int32)

        p = np.clip((v * (1.0 - s)), 0.0, 1.0)
        q = np.clip((v * (1.0 - s * f)), 0.0, 1.0)
        t = np.clip((v * (1.0 - s * (1.0 - f))), 0.0, 1.0)
        i = i % 6
        mask = np.expand_dims(i, axis=-1) == np.arange(6)

        a1 = np.stack((v, q, p, p, t, v), axis=-1)
        a2 = np.stack((t, v, v, q, p, p), axis=-1)
        a3 = np.stack((p, p, t, v, v, q), axis=-1)
        a4 = np.stack((a1, a2, a3), axis=-1)

        return np.einsum("...na, ...nab -> ...nb", mask.astype(hsv.dtype), a4)

    def adjust_brightness(self, color, brightness_factor):
        """Adjust brightness of a color tensor.

        Args:
            color (np.ndarray):
                Color array in [0, 1].
            brightness_factor (float):
                Non-negative brightness scaling factor. 0 means all black, 1 means no change, >1 makes it brighter.

        Returns:
            np.ndarray:
                Brightness-adjusted color array in [0, 1].
        """
        if brightness_factor < 0:
            raise ValueError(f"brightness_factor ({brightness_factor}) is not non-negative.")
        # color and zeros are in [0,1] float
        return self.blend(color, np.zeros_like(color), brightness_factor)

    def adjust_contrast(self, color, contrast_factor):
        """Adjust contrast of a color tensor.

        Args:
            color (np.ndarray):
                Color array in [0, 1].
            contrast_factor (float):
                Non-negative contrast scaling factor. 0 means the colors at mean intensity (from grayscale value),
                1 means no change, >1 increases contrast.

        Returns:
            np.ndarray:
                Contrast-adjusted color array in [0, 1].
        """
        if contrast_factor < 0:
            raise ValueError(f"contrast_factor ({contrast_factor}) is not non-negative.")
        mean = np.mean(RandomColorGrayScale.rgb_to_grayscale(color))
        return self.blend(color, mean, contrast_factor)

    def adjust_saturation(self, color, saturation_factor):
        """Adjust saturation of a color tensor.

        Args:
            color (np.ndarray):
                Color array in [0, 1].
            saturation_factor (float):
                Non-negative saturation scaling factor. 0 means grayscale, 1 means no change, >1 increases saturation.

        Returns:
            np.ndarray:
                Saturation-adjusted color array in [0, 1].
        """
        if saturation_factor < 0:
            raise ValueError(f"saturation_factor ({saturation_factor}) is not non-negative.")
        gray = RandomColorGrayScale.rgb_to_grayscale(color)
        return self.blend(color, gray, saturation_factor)

    def adjust_hue(self, color, hue_factor):
        """Adjust hue of a color tensor.

        Args:
            color (np.ndarray):
                Color array in [0, 1].
            hue_factor (float):
                Hue shift factor in [-0.5, 0.5]. The hue channel (in HSV) is shifted by this amount modulo 1.

        Returns:
            np.ndarray:
                Hue-adjusted color array in [0, 1].
        """
        # color in (0, 1.0) range
        if not (-0.5 <= hue_factor <= 0.5):
            raise ValueError(f"hue_factor ({hue_factor}) is not in [-0.5, 0.5].")
        hsv = self.rgb2hsv(color)
        h, s, v = hsv[..., 0], hsv[..., 1], hsv[..., 2]
        h = (h + hue_factor) % 1.0
        hsv = np.stack((h, s, v), axis=-1)
        return self.hsv2rgb(hsv)

    @staticmethod
    def get_params(brightness, contrast, saturation, hue):
        """Sample random jitter parameters and a random order of operations.

        Args:
            brightness: Parsed brightness range from ``_check_input`` or ``None``.
            contrast: Parsed contrast range from ``_check_input`` or ``None``.
            saturation: Parsed saturation range from ``_check_input`` or ``None``.
            hue: Parsed hue range from ``_check_input`` or ``None``.

        Returns:
            tuple:
                ``(fn_idx, b, c, s, h)`` where:

                * ``fn_idx`` is a permutation of [0, 1, 2, 3] indicating the
                  order in which brightness/contrast/saturation/hue will be
                  applied.
                * ``b, c, s, h`` are the sampled scalar factors (or ``None`` if
                  the corresponding transform is disabled).
        """
        fn_idx = np.arange(4)
        np.random.shuffle(fn_idx)
        b = (None if brightness is None else np.random.uniform(brightness[0], brightness[1]))
        c = None if contrast is None else np.random.uniform(contrast[0], contrast[1])
        s = (None if saturation is None else np.random.uniform(saturation[0], saturation[1]))
        h = None if hue is None else np.random.uniform(hue[0], hue[1])
        return fn_idx, b, c, s, h

    def __call__(self, data_dict: dict) -> dict:
        """Apply random color jitter to the `"color"` entry in `data_dict`.

        Args:
            data_dict (dict): Input dictionary that must contain a `"color"` key with a NumPy array of shape (N, 3)
                representing point color values.

        Returns:
            dict: The same dictionary with `"color"` updated in-place, if applied.
        """
        if random.random() > self.apply_p:
            return data_dict

        if "color" in data_dict.keys():
            # make sure color range is [0, 1.0]
            dtype = data_dict["color"].dtype
            if self.range255:
                data_dict["color"] = data_dict["color"].astype(np.float32) / 255.
            else:
                data_dict["color"] = data_dict["color"].astype(np.float32)


            fn_idx, brightness_factor, contrast_factor, saturation_factor, hue_factor = self.get_params(self.brightness,
                                                                                                        self.contrast,
                                                                                                        self.saturation,
                                                                                                        self.hue)
            for fn_id in fn_idx:
                if fn_id == 0 and brightness_factor is not None:
                    data_dict["color"] = self.adjust_brightness(data_dict["color"], brightness_factor)
                elif fn_id == 1 and contrast_factor is not None:
                    data_dict["color"] = self.adjust_contrast(data_dict["color"], contrast_factor)
                elif fn_id == 2 and saturation_factor is not None:
                    data_dict["color"] = self.adjust_saturation(data_dict["color"], saturation_factor)
                elif fn_id == 3 and hue_factor is not None:
                    data_dict["color"] = self.adjust_hue(data_dict["color"], hue_factor)


            data_dict["color"] = np.clip(data_dict["color"], 0.0, 1.0)
            # convert back to original dtype / range
            if self.range255:
                data_dict["color"] = (data_dict["color"] * 255.).round().astype(dtype)
            else:
                data_dict["color"] = data_dict["color"].astype(dtype)

        return data_dict

__call__(data_dict)

Apply random color jitter to the "color" entry in data_dict.

Parameters:

Name Type Description Default
data_dict dict

Input dictionary that must contain a "color" key with a NumPy array of shape (N, 3) representing point color values.

required

Returns:

Name Type Description
dict dict

The same dictionary with "color" updated in-place, if applied.

Source code in src\augmentation_class.py
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
def __call__(self, data_dict: dict) -> dict:
    """Apply random color jitter to the `"color"` entry in `data_dict`.

    Args:
        data_dict (dict): Input dictionary that must contain a `"color"` key with a NumPy array of shape (N, 3)
            representing point color values.

    Returns:
        dict: The same dictionary with `"color"` updated in-place, if applied.
    """
    if random.random() > self.apply_p:
        return data_dict

    if "color" in data_dict.keys():
        # make sure color range is [0, 1.0]
        dtype = data_dict["color"].dtype
        if self.range255:
            data_dict["color"] = data_dict["color"].astype(np.float32) / 255.
        else:
            data_dict["color"] = data_dict["color"].astype(np.float32)


        fn_idx, brightness_factor, contrast_factor, saturation_factor, hue_factor = self.get_params(self.brightness,
                                                                                                    self.contrast,
                                                                                                    self.saturation,
                                                                                                    self.hue)
        for fn_id in fn_idx:
            if fn_id == 0 and brightness_factor is not None:
                data_dict["color"] = self.adjust_brightness(data_dict["color"], brightness_factor)
            elif fn_id == 1 and contrast_factor is not None:
                data_dict["color"] = self.adjust_contrast(data_dict["color"], contrast_factor)
            elif fn_id == 2 and saturation_factor is not None:
                data_dict["color"] = self.adjust_saturation(data_dict["color"], saturation_factor)
            elif fn_id == 3 and hue_factor is not None:
                data_dict["color"] = self.adjust_hue(data_dict["color"], hue_factor)


        data_dict["color"] = np.clip(data_dict["color"], 0.0, 1.0)
        # convert back to original dtype / range
        if self.range255:
            data_dict["color"] = (data_dict["color"] * 255.).round().astype(dtype)
        else:
            data_dict["color"] = data_dict["color"].astype(dtype)

    return data_dict

Random Jitter PC Colors

Before After

HueSaturationTranslation

Randomly shift hue and scale saturation of point colors.

This transform expects a dictionary containing:

  • "color": NumPy array of shape (N, 3) with point color values.

For each call (with probability apply_p), it:

  1. Converts "color" to float in the range [0, 1].
  2. If range255=True, it divides by 255.
  3. Otherwise it assumes values are already in [0, 1] (or compatible).
  4. Converts the color from RGB to HSV.
  5. Samples:
  6. a hue shift h ~ U(-hue_max, hue_max) and applies it modulo 1.0,
  7. a saturation scale s = 1 + U(-saturation_max, saturation_max) and multiplies the saturation channel by s (clipped to [0, 1]).
  8. Converts HSV back to RGB, clips to [0, 1], and restores the original dtype (multiplying by 255 if needed).

Parameters:

Name Type Description Default
hue_max float

Maximum absolute hue shift. The actual hue offset is sampled uniformly from [-hue_max, hue_max] and added to the hue channel modulo 1.0. Defaults to 0.5.

0.5
saturation_max float

Maximum relative change in saturation. The saturation scale factor is sampled as:

s = 1 + U(-saturation_max, saturation_max)

so saturation can be slightly decreased or increased. Defaults to 0.2.

0.2
range255 bool

Whether the input color values are in [0, 255]. If True, values are converted to float in [0, 1] before modification and converted back to [0, 255] afterwards. If False, values are treated as floats in [0, 1]. Defaults to False.

False
apply_p float

Probability of applying the hue/saturation translation. Defaults to 1.0.

1.0
Source code in src\augmentation_class.py
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
@TRANSFORMS.register()
class HueSaturationTranslation:
    """Randomly shift hue and scale saturation of point colors.

    This transform expects a dictionary containing:

    * `"color"`: NumPy array of shape (N, 3) with point color values.

    For each call (with probability ``apply_p``), it:

    1. Converts `"color"` to float in the range [0, 1].
       - If ``range255=True``, it divides by 255.
       - Otherwise it assumes values are already in [0, 1] (or compatible).
    2. Converts the color from RGB to HSV.
    3. Samples:
       - a hue shift ``h ~ U(-hue_max, hue_max)`` and applies it modulo 1.0,
       - a saturation scale ``s = 1 + U(-saturation_max, saturation_max)`` and
         multiplies the saturation channel by ``s`` (clipped to [0, 1]).
    4. Converts HSV back to RGB, clips to [0, 1], and restores the original dtype (multiplying by 255 if needed).

    Args:
        hue_max (float, optional):
            Maximum absolute hue shift. The actual hue offset is sampled uniformly from ``[-hue_max, hue_max]`` and added
            to the hue channel modulo 1.0.
            Defaults to 0.5.
        saturation_max (float, optional):
            Maximum relative change in saturation. The saturation scale factor is sampled as:

                s = 1 + U(-saturation_max, saturation_max)

            so saturation can be slightly decreased or increased.
            Defaults to 0.2.
        range255 (bool, optional):
            Whether the input color values are in ``[0, 255]``. If True, values are converted to float in [0, 1]
            before modification and converted back to [0, 255] afterwards. If False, values are treated as floats in [0, 1].
            Defaults to False.
        apply_p (float, optional):
            Probability of applying the hue/saturation translation.
            Defaults to 1.0.
    """
    def __init__(self, hue_max=0.5, saturation_max=0.2, range255=False, apply_p=1.0):
        self.hue_max = hue_max
        self.saturation_max = saturation_max
        self.range255 = range255
        self.apply_p = apply_p

    def __call__(self, data_dict: dict) -> dict:
        """Apply random hue and saturation translation to `"color"`.
        Args:
            data_dict (dict): Input dictionary that must contain a `"color"` key with a NumPy array of shape (N, 3)
                representing point color values.

        Returns:
            dict: The same dictionary with `"color"` updated in-place, if applied.
        """
        if random.random() > self.apply_p:
            return data_dict

        if "color" in data_dict.keys():

            # make sure color range is [0, 1.0]
            dtype = data_dict["color"].dtype
            if self.range255:
                data_dict["color"] = data_dict["color"].astype(np.float32) / 255.
            else:
                data_dict["color"] = data_dict["color"].astype(np.float32)

            hsv = RandomColorJitter.rgb2hsv(data_dict["color"][:, :3])
            hue_val = np.random.uniform(-self.hue_max, self.hue_max)
            sat_ratio = 1 + np.random.uniform(-self.saturation_max, self.saturation_max)
            hsv[..., 0] = np.remainder(hue_val + hsv[..., 0] + 1, 1)
            hsv[..., 1] = np.clip(sat_ratio * hsv[..., 1], 0, 1)

            data_dict["color"][:, :3] = np.clip(RandomColorJitter.hsv2rgb(hsv), 0, 1.0)
            if self.range255:
                data_dict["color"] = (data_dict["color"] * 255.).round().astype(dtype)
            else:
                data_dict["color"] = data_dict["color"].astype(dtype)

        return data_dict

__call__(data_dict)

Apply random hue and saturation translation to "color". Args: data_dict (dict): Input dictionary that must contain a "color" key with a NumPy array of shape (N, 3) representing point color values.

Returns:

Name Type Description
dict dict

The same dictionary with "color" updated in-place, if applied.

Source code in src\augmentation_class.py
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
def __call__(self, data_dict: dict) -> dict:
    """Apply random hue and saturation translation to `"color"`.
    Args:
        data_dict (dict): Input dictionary that must contain a `"color"` key with a NumPy array of shape (N, 3)
            representing point color values.

    Returns:
        dict: The same dictionary with `"color"` updated in-place, if applied.
    """
    if random.random() > self.apply_p:
        return data_dict

    if "color" in data_dict.keys():

        # make sure color range is [0, 1.0]
        dtype = data_dict["color"].dtype
        if self.range255:
            data_dict["color"] = data_dict["color"].astype(np.float32) / 255.
        else:
            data_dict["color"] = data_dict["color"].astype(np.float32)

        hsv = RandomColorJitter.rgb2hsv(data_dict["color"][:, :3])
        hue_val = np.random.uniform(-self.hue_max, self.hue_max)
        sat_ratio = 1 + np.random.uniform(-self.saturation_max, self.saturation_max)
        hsv[..., 0] = np.remainder(hue_val + hsv[..., 0] + 1, 1)
        hsv[..., 1] = np.clip(sat_ratio * hsv[..., 1], 0, 1)

        data_dict["color"][:, :3] = np.clip(RandomColorJitter.hsv2rgb(hsv), 0, 1.0)
        if self.range255:
            data_dict["color"] = (data_dict["color"] * 255.).round().astype(dtype)
        else:
            data_dict["color"] = data_dict["color"].astype(dtype)

    return data_dict

Hue Saturation Translation PC Colors

Before After

RandomColorAugment

Apply a simple global color scaling to point colors.

This transform expects a dictionary containing:

  • "color": NumPy array of shape (N, 3) with point color values.

It multiplies the color values by color_augment and clips them to a valid range:

  • If range255=True → values are clipped to [0, 255].
  • If range255=False → values are clipped to [0, 1].

Parameters:

Name Type Description Default
color_augment float

Multiplicative scaling factor applied to all color channels (e.g., 1.1 to slightly brighten, 0.9 to slightly darken). Defaults to 1.1.

1.1
range255 bool

Whether the input color values are in [0, 255]. If True, clipping is done in that range. If False, clipping is done in [0, 1]. Defaults to False.

False
apply_p float

Probability of applying the color scaling. Defaults to 1.0.

1.0
Source code in src\augmentation_class.py
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
@TRANSFORMS.register()
class RandomColorAugment:
    """Apply a simple global color scaling to point colors.

    This transform expects a dictionary containing:

    * `"color"`: NumPy array of shape (N, 3) with point color values.

    It multiplies the color values by ``color_augment`` and clips them to a valid range:

    * If ``range255=True`` → values are clipped to ``[0, 255]``.
    * If ``range255=False`` → values are clipped to ``[0, 1]``.

    Args:
        color_augment (float, optional):
            Multiplicative scaling factor applied to all color channels (e.g., 1.1 to slightly brighten, 0.9 to slightly darken).
            Defaults to 1.1.
        range255 (bool, optional):
            Whether the input color values are in ``[0, 255]``. If True, clipping is done in that range. If False,
            clipping is done in ``[0, 1]``.
            Defaults to False.
        apply_p (float, optional):
            Probability of applying the color scaling.
            Defaults to 1.0.
    """
    def __init__(self, color_augment: float = 1.1, range255=False, apply_p: float = 1.0):
        self.color_augment = color_augment
        self.range255 = range255
        self.apply_p = apply_p

    def __call__(self, data_dict: dict) -> dict:
        """Apply global color scaling to the `"color"` entry in `data_dict`.

        Args:
            data_dict (dict): Input dictionary that must contain a `"color"` key with a NumPy array of shape (N, 3)
                representing point color values.

        Returns:
            dict: The same dictionary with `"color"` updated in-place, if applied.
        """
        if random.random() > self.apply_p:
            return data_dict

        if "color" in data_dict.keys():
            dtype = data_dict["color"].dtype
            if self.range255:
                target_range = 255.0
            else:
                target_range = 1.0

            data_dict["color"] = np.clip(data_dict["color"] * self.color_augment, 0, target_range).astype(dtype)

        return data_dict

__call__(data_dict)

Apply global color scaling to the "color" entry in data_dict.

Parameters:

Name Type Description Default
data_dict dict

Input dictionary that must contain a "color" key with a NumPy array of shape (N, 3) representing point color values.

required

Returns:

Name Type Description
dict dict

The same dictionary with "color" updated in-place, if applied.

Source code in src\augmentation_class.py
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
def __call__(self, data_dict: dict) -> dict:
    """Apply global color scaling to the `"color"` entry in `data_dict`.

    Args:
        data_dict (dict): Input dictionary that must contain a `"color"` key with a NumPy array of shape (N, 3)
            representing point color values.

    Returns:
        dict: The same dictionary with `"color"` updated in-place, if applied.
    """
    if random.random() > self.apply_p:
        return data_dict

    if "color" in data_dict.keys():
        dtype = data_dict["color"].dtype
        if self.range255:
            target_range = 255.0
        else:
            target_range = 1.0

        data_dict["color"] = np.clip(data_dict["color"] * self.color_augment, 0, target_range).astype(dtype)

    return data_dict

Random Augment PC Colors

Before After