π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
Feat/codeflash_grayscale_to_rgb (#3209)
Meggison Oritsemisan662a38bd0b36
diff --git a/kornia/color/gray.py b/kornia/color/gray.pyindex 7974120ff..32ee31c8d 100644--- a/kornia/color/gray.py+++ b/kornia/color/gray.py@@ -23,7 +23,7 @@ import torchfrom kornia.color.rgb import bgr_to_rgbfrom kornia.core import ImageModule as Module-from kornia.core import Tensor, concatenate+from kornia.core import Tensorfrom kornia.core.check import KORNIA_CHECK_IS_TENSOR@@ -50,7 +50,10 @@ def grayscale_to_rgb(image: Tensor) -> Tensor:if len(image.shape) < 3 or image.shape[-3] != 1:raise ValueError(f"Input size must have a shape of (*, 1, H, W). Got {image.shape}.")- return concatenate([image, image, image], -3)+ shape = list(image.shape)+ shape[-3] = 3+ # Use expand to create a view that repeats along channel dimension, no memory overhead.+ return image.expand(*shape)def rgb_to_grayscale(image: Tensor, rgb_weights: Optional[Tensor] = None) -> Tensor: