Ask Your Question
0

How to visualize a depth image

asked 2012-12-12 06:27:43 -0600

alykhantejani gravatar image

Hi,

I am using a dataset in which it has images where each pixel is a 16 bit unsigned int storing the depth value of that pixel in mm. I am trying to visualize this as a greyscale depth image by doing the following:

cv::Mat depthImage; 
depthImage = cv::imread("coffee_mug_1_1_1_depthcrop.png", CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR ); // Read the file 
depthImage.convertTo(depthImage, CV_32F); // convert the image data to float type   
namedWindow("window");
float max = 0;
for(int i = 0; i < depthImage.rows; i++){
    for(int j = 0; j < depthImage.cols; j++){
        if(depthImage.at<float>(i,j) > max){
            max = depthImage.at<float>(i,j);
        }
    }   
}
cout << max << endl;


float divisor = max / 255.0;
cout << divisor << endl;
for(int i = 0; i < depthImage.rows; i++){
    for(int j = 0; j < depthImage.cols; j++){
        cout << depthImage.at<float>(i,j) << ", ";
        max = depthImage.at<float>(i,j) /= divisor;
        cout << depthImage.at<float>(i,j) << endl;
    }   
}


imshow("window", depthImage);
waitKey(0);

However, it is only showing two colours this is because all of the values are close together i.e. in the range of 150-175 + the small values which show up black (see below).

RGB image greyscale image

Is there a way to normalize this data such that it will show various grey levels to highlight these small depth differences?

edit retag flag offensive close merge delete

Comments

Try histogram equalization

Haris gravatar imageHaris ( 2012-12-12 06:38:51 -0600 )edit

Can you provide a code sample? Or link to tutorial, I am fairly new to the library

alykhantejani gravatar imagealykhantejani ( 2012-12-12 06:46:34 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2012-12-12 06:51:18 -0600

Haris gravatar image

updated 2012-12-12 06:52:50 -0600

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-12-12 06:27:43 -0600

Seen: 5,004 times

Last updated: Dec 12 '12