IMREAD_COLOR 图像中不使用 OpenCV、DFT 函数
OpenCV, DFT function don't use in the image with IMREAD_COLOR
使用IMREAD_COLOR读取图像时,'dft'函数抛出错误:
DFT 函数在使用 IMREAD_GRAYSCALE 读取图像时工作正常。但我想用 IMREAD_COLOR.
读取图像
主要功能
const char* filename = "face.jpg";
Mat I = imread(filename, IMREAD_COLOR);
if(I.empty()) return 0;
Mat padded;
I.convertTo(padded, CV_32F);
Mat fft;
Mat planes[2];
dft(padded, fft, DFT_SCALE|DFT_COMPLEX_OUTPUT);
Mat fftBlur = fft.clone();
fftBlur *= 0.5;
split(fftBlur, planes);
Mat ph, mag;
mag.zeros(planes[0].rows, planes[0].cols, CV_32F);
ph.zeros(planes[0].rows, planes[0].cols, CV_32F);
cartToPolar(planes[0], planes[1], mag, ph);
merge(planes, 2, fftBlur);
//inverse
Mat invfft;
dft(fftBlur, invfft, DFT_INVERSE|DFT_REAL_OUTPUT);
Mat result;
invfft.convertTo(result, CV_8U);
Mat image;
cvtColor(result, image, COLOR_GRAY2RGB);
imshow("Output", result);
imshow("Image", image);
waitKey();
来自Learning OpenCV(关于dft函数):
The input array must be of floating-point type and may be single- or double-channel. In the single-channel case, the entries are assumed to be real numbers, and the output will be packed in a special space-saving format called complex conjugate symmetrical.
同样的问题在matlab图像处理方面提到here。
如果您想分离初始图像的通道,您可以查看 cv::split 函数。
您收到的消息是一个断言,它告诉您 DFT 函数只采用一个或两个通道的单精度浮点图像(CV_32FC1、CV_32FC2,最后的字母 C标记平均通道)或具有一个或两个通道的双精度浮点图像(CV_64FC1、CV_64FC2)。
双通道情况实际上是复杂图像在 OpenCV 数据存储中的表示。
如果你愿意,你可以将图像拆分为 std::vector<cv::Mat>
,其中每个元素代表一个通道,使用 cv::split
在每个通道上应用 DFT 进行你想要的处理并重新创建多通道图像,这要归功于 cv::merge
.
使用IMREAD_COLOR读取图像时,'dft'函数抛出错误:
DFT 函数在使用 IMREAD_GRAYSCALE 读取图像时工作正常。但我想用 IMREAD_COLOR.
读取图像主要功能
const char* filename = "face.jpg";
Mat I = imread(filename, IMREAD_COLOR);
if(I.empty()) return 0;
Mat padded;
I.convertTo(padded, CV_32F);
Mat fft;
Mat planes[2];
dft(padded, fft, DFT_SCALE|DFT_COMPLEX_OUTPUT);
Mat fftBlur = fft.clone();
fftBlur *= 0.5;
split(fftBlur, planes);
Mat ph, mag;
mag.zeros(planes[0].rows, planes[0].cols, CV_32F);
ph.zeros(planes[0].rows, planes[0].cols, CV_32F);
cartToPolar(planes[0], planes[1], mag, ph);
merge(planes, 2, fftBlur);
//inverse
Mat invfft;
dft(fftBlur, invfft, DFT_INVERSE|DFT_REAL_OUTPUT);
Mat result;
invfft.convertTo(result, CV_8U);
Mat image;
cvtColor(result, image, COLOR_GRAY2RGB);
imshow("Output", result);
imshow("Image", image);
waitKey();
来自Learning OpenCV(关于dft函数):
The input array must be of floating-point type and may be single- or double-channel. In the single-channel case, the entries are assumed to be real numbers, and the output will be packed in a special space-saving format called complex conjugate symmetrical.
同样的问题在matlab图像处理方面提到here。 如果您想分离初始图像的通道,您可以查看 cv::split 函数。
您收到的消息是一个断言,它告诉您 DFT 函数只采用一个或两个通道的单精度浮点图像(CV_32FC1、CV_32FC2,最后的字母 C标记平均通道)或具有一个或两个通道的双精度浮点图像(CV_64FC1、CV_64FC2)。
双通道情况实际上是复杂图像在 OpenCV 数据存储中的表示。
如果你愿意,你可以将图像拆分为 std::vector<cv::Mat>
,其中每个元素代表一个通道,使用 cv::split
在每个通道上应用 DFT 进行你想要的处理并重新创建多通道图像,这要归功于 cv::merge
.