diff --git a/manim/mobject/types/image_mobject.py b/manim/mobject/types/image_mobject.py index f03541cd1f..6a462d0265 100644 --- a/manim/mobject/types/image_mobject.py +++ b/manim/mobject/types/image_mobject.py @@ -26,8 +26,6 @@ ) from ...utils.images import change_to_rgba_array, get_full_raster_image_path -__all__ = ["ImageMobject", "ImageMobjectFromCamera"] - if TYPE_CHECKING: from typing import Self @@ -35,8 +33,6 @@ from manim.typing import PixelArray, StrPath - from ...camera.moving_camera import MovingCamera - class AbstractImageMobject(Mobject): """ @@ -216,6 +212,10 @@ def get_pixel_array(self) -> PixelArray: """A simple getter method.""" return self.pixel_array + def init_colors(self) -> None: + """Override base init_colors to avoid overwriting image pixels during init.""" + return None + def set_color( # type: ignore[override] self, color: ParsableManimColor = YELLOW_C, diff --git a/tests/module/mobject/test_image.py b/tests/module/mobject/test_image.py index ef00eb75b9..584068bd45 100644 --- a/tests/module/mobject/test_image.py +++ b/tests/module/mobject/test_image.py @@ -7,7 +7,7 @@ @pytest.mark.parametrize("dtype", [np.uint8, np.uint16]) def test_invert_image(dtype): rng = np.random.default_rng() - array = (255 * rng.random((10, 10, 4))).astype(dtype) + array = (np.iinfo(dtype).max * rng.random((10, 10, 4))).astype(dtype) image = ImageMobject(array, pixel_array_dtype=dtype, invert=True) assert image.pixel_array.dtype == dtype