cv2.applyColorMap got different result shape between 4.x and 5.x · Issue #1263 · opencv/opencv-python · GitHub
Skip to content

cv2.applyColorMap got different result shape between 4.x and 5.x #1263

Open

Description

@ganlvtech
import numpy as np
import cv2

colors = cv2.applyColorMap(np.array([0, 63, 127, 191, 255], dtype=np.uint8), cv2.COLORMAP_PARULA)
print('shape', colors.shape)

opencv-python 4.x got shape (5, 1, 3)

# pip list | grep -e cv -e numpy
numpy                                  2.4.6
opencv-python                          4.13.0.92

Python version 3.11.9

opencv-python 5.x got shape (1, 5, 3)

# pip list | grep -e cv -e numpy
numpy                                  2.4.6
opencv-python                          5.0.0.93


Python version 3.11.9

Activity

  1. Hemanath400 commented on Aug 30, 2026

    @Hemanath400

    I can reproduce this issue on Windows with Python 3.10.

    • OpenCV 4.13.0.92 → output shape (5, 1, 3)
    • OpenCV 5.0.0.93 → output shape (1, 5, 3)

    Using:

    import numpy as np
    import cv2
    
    x = np.array([0, 63, 127, 191, 255], dtype=np.uint8)
    colors = cv2.applyColorMap(x, cv2.COLORMAP_PARULA)
    print(colors.shape)

    The behavior change appears reproducible across versions.

  2. ganlvtech commented on Sep 1, 2026

    @ganlvtech
    Author

    Affected code: detectron2/DensePose

    https://github.com/facebookresearch/detectron2/blob/a2f4a8771ab77e8411c26b27f24f9489a28a2453/projects/DensePose/densepose/vis/densepose_results.py#L158

    class DensePoseResultsCustomContourVisualizer(DensePoseResultsVisualizer):
        """
        Contour visualization using marching squares
        """
    
        def __init__(self, levels=10, **kwargs):
            # TODO: colormap is hardcoded
            cmap = cv2.COLORMAP_PARULA
            if isinstance(levels, int):
                self.levels = np.linspace(0, 1, levels)
            else:
                self.levels = levels
            if "linewidths" in kwargs:
                self.linewidths = kwargs["linewidths"]
            else:
                self.linewidths = [1] * len(self.levels)
            self.plot_args = kwargs
            img_colors_bgr = cv2.applyColorMap((self.levels * 255).astype(np.uint8), cmap)
            self.level_colors_bgr = [
                [int(v) for v in img_color_bgr.ravel()] for img_color_bgr in img_colors_bgr
            ]
  3. MDSALMANSHAMS commented on Sep 15, 2026

    @MDSALMANSHAMS
    Contributor

    Reproduced the shape difference too. Before this gets triaged as a bug — is the (1, N, 3) shape on 5.x an intentional layout change (e.g. matching a broader row/column-major convention update for 5.x) or a genuine regression? It's already breaking downstream consumers that assume the 4.x (N, 1, 3) shape (detectron2/DensePose per the comment above). If unintentional, could this get an actionable label? The fix would live in opencv/opencv core (imgproc), not this packaging repo, so happy to help there once it's confirmed which side of that line it's on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions