Ask Your Question

Revision history [back]

cv::edgePreservingFilter() not working on grayscale images

Pretty much what the title says. It does however work on BGR images. I'm using a self-compiled build of OpenCV 3.1.0, if it matters.

If you run the MWE, the second call to cv::edgePreservingFilter() (on the grayscale image) appears to do nothing. Any ideas?

MWE:

#include <iostream>

#include <opencv2/core.hpp>
#include <opencv2/photo.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgcodecs.hpp>

int main(int argc, char** argv)
{
    if (argc < 2) {
        std::cout << "Requires path to image" << std::endl;
        return 1;
    }

    cv::Mat image = cv::imread(argv[1]);

    cv::Mat filtered;
    cv::edgePreservingFilter(image, filtered);
    cv::imshow("RGB", filtered);
    cv::waitKey();

    cv::cvtColor(image, image, CV_BGR2GRAY);
    cv::edgePreservingFilter(image, filtered);
    cv::imshow("Grayscale", filtered);
    cv::waitKey();

    return 0;
}

cv::edgePreservingFilter() not working on grayscale images

Pretty much what the title says. It does however work on BGR images. I'm using a self-compiled build of OpenCV 3.1.0, if it matters.

If you run the MWE, the second call to cv::edgePreservingFilter() (on the grayscale image) appears to do nothing. Any ideas?

MWE:

#include <iostream>

#include <opencv2/core.hpp>
#include <opencv2/photo.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgcodecs.hpp>

int main(int argc, char** argv)
{
    if (argc < 2) {
        std::cout << "Requires path to image" << std::endl;
        return 1;
    }

    cv::Mat image = cv::imread(argv[1]);

    cv::Mat filtered;
    cv::edgePreservingFilter(image, filtered);
    cv::imshow("RGB", filtered);
    cv::waitKey();

    cv::cvtColor(image, image, CV_BGR2GRAY);
    cv::edgePreservingFilter(image, filtered);
    cv::imshow("Grayscale", filtered);
    cv::waitKey();

    return 0;
}