Regarding Issue in undistorting RGB Image

RGB image undistortion was performed using BORDER_CONSTANT and interpolation (INTER_LINEAR). We utilized the initUndistortRectifyMap and remap functions in OpenCV version 4.2.0 and 4.10.0. The undistorted image is expected to have 0 values for out-of-bounds pixels, but the image does not display 0s. Why is this?

show us the input image, the result image, and the relevant code, including any third party library calls for “displaying” your result image.

Thanks crackwitz for early reply.

We have attached images below.
rgb_image


#include <opencv2/opencv.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>

using namespace cv;

int main()
{
    // Load the image
    cv::Mat rgb_image = cv::imread("rgb_image.png", cv::IMREAD_UNCHANGED); 

    // Get the number of channels in the image
    int channels = rgb_image.channels(); 
   // Print the number of channels
    std::cout << "Number of channels: " << channels << std::endl;

    // RGB Camera intrinsic parameters (you need to replace these with your actual parameters)
    Mat camera_Matrix_rgb = (Mat_<double>(3, 3) << 704.642972, 0, 318.955605,
                             0, 704.345741, 241.220241,
                             0, 0, 1);                                                                // Intrinsic parameters: fx, fy, cx, cy
    Mat distCoeffs_rgb = (Mat_<double>(1, 5) << 0.007755, -0.060623, -0.000348, -0.000087, 0.000000); // Distortion coefficients: k1, k2, p1, p2, k3

    // Define width and height of the rgb  and depth image
    int width_rgb = 640;  // example width
    int height_rgb = 480; // example height

    // Undistort the rgb image / Generate the rectification map

    cv::Mat map_x_rgb, map_y_rgb;
    initUndistortRectifyMap(camera_Matrix_rgb, distCoeffs_rgb, Mat(), camera_Matrix_rgb, Size(width_rgb, height_rgb), CV_32FC1, map_x_rgb, map_y_rgb);

    // Remap the rgb image to rectify it
    cv::Mat rectified_rgb_image;
    remap(rgb_image, rectified_rgb_image, map_x_rgb, map_y_rgb, INTER_LINEAR, cv::BORDER_CONSTANT, Scalar(0, 0, 0));

    // Save the cropped image
    cv::imshow("rectified_rgb_image", rectified_rgb_image);
    cv::imwrite("rectified_rgb_image.png", rectified_rgb_image);

    cv::waitKey(0);
    cv::destroyAllWindows();

    return 0;
}

We are not able to attach the rectified_rgb_image (result image).
You will get the same from the mentioned code.