OpenCV: How to visualize a depth image

前端 未结 4 1391
终归单人心
终归单人心 2020-12-04 10:48

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 greysca

相关标签:
4条回答
  • 2020-12-04 10:59

    Adding to Sammy answer, if the original range color is [-min,max] and you want to perform histogram equalization and display the Depth color, the code should be like below:

    double min;
    double max;
    cv::minMaxIdx(map, &min, &max);
    cv::Mat adjMap;
    // Histogram Equalization
    float scale = 255 / (max-min);
    map.convertTo(adjMap,CV_8UC1, scale, -min*scale); 
    
    // this is great. It converts your grayscale image into a tone-mapped one, 
    // much more pleasing for the eye
    // function is found in contrib module, so include contrib.hpp 
    // and link accordingly
    cv::Mat falseColorsMap;
    applyColorMap(adjMap, falseColorsMap, cv::COLORMAP_AUTUMN);
    
    cv::imshow("Out", falseColorsMap);
    
    0 讨论(0)
  • 2020-12-04 11:08

    Adding to samg' answer, you can expand even more the range of your displayed image.

    double min;
    double max;
    cv::minMaxIdx(map, &min, &max);
    cv::Mat adjMap;
    // expand your range to 0..255. Similar to histEq();
    map.convertTo(adjMap,CV_8UC1, 255 / (max-min), -min); 
    
    // this is great. It converts your grayscale image into a tone-mapped one, 
    // much more pleasing for the eye
    // function is found in contrib module, so include contrib.hpp 
    // and link accordingly
    cv::Mat falseColorsMap;
    applyColorMap(adjMap, falseColorsMap, cv::COLORMAP_AUTUMN);
    
    cv::imshow("Out", falseColorsMap);
    

    The result should be something like the one below

    enter image description here

    0 讨论(0)
  • 2020-12-04 11:11

    According to the documentation, the function imshow can be used with a variety of image types. It support 16-bit unsigned images, so you can display your image using

    cv::Mat map = cv::imread("image", CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH);
    cv::imshow("window", map);
    

    In this case, the image value range is mapped from the range [0, 255*256] to the range [0, 255].

    If your image only contains values on the low part of this range, you will observe an obscure image. If you want to use the full display range (from black to white), you should adjust the image to cover the expected dynamic range, one way to do it is

    double min;
    double max;
    cv::minMaxIdx(map, &min, &max);
    cv::Mat adjMap;
    cv::convertScaleAbs(map, adjMap, 255 / max);
    cv::imshow("Out", adjMap);
    
    0 讨论(0)
  • 2020-12-04 11:14

    Ifimshow input has floating point data type then the function assumes that pixel values are in [0; 1] range. As result all values higher than 1 are displayed white.

    So you need not divide your divisor by 255.

    0 讨论(0)
提交回复
热议问题