我學習下面的代碼與3個通道,但是當我嘗試將其轉換爲4個通道拿給我襯上的圖像,下面的代碼工作的3通道圖像如何使用圖像4個通道
void Vignette(Mat&img, Mat &out) {
Mat a, b, c, d, f;
double sigma = 280; // vignette 'aperture', the param to play with
a = getGaussianKernel(img.cols, sigma, CV_32F);
b = getGaussianKernel(img.rows, sigma, CV_32F);
c = b * a.t();
double minVal;
double maxVal;
cv::minMaxLoc(c, &minVal, &maxVal);
d = c/maxVal;
d.convertTo(d, CV_8U, 255);
cvtColor(d, d, COLOR_GRAY2RGB);
d.convertTo(d, CV_32F, 1.0/255);
multiply(img, d, out, 1, CV_8U);
}
但我嘗試了4通道拿給我襯,4通道代碼如下
void Vignette(Mat&img, Mat &out) {
Mat a, b, c, d, f;
double sigma = 280; // vignette 'aperture', the param to play with
a = getGaussianKernel(img.cols, sigma, CV_32F);
b = getGaussianKernel(img.rows, sigma, CV_32F);
c = b * a.t();
double minVal;
double maxVal;
cv::minMaxLoc(c, &minVal, &maxVal);
d = c/maxVal;
d.convertTo(d, CV_8UC4, 255);
cvtColor(d, d, COLOR_GRAY2RGBA);
d.convertTo(d, CV_32F, 1.0/255);
multiply(img, d, out, 1, CV_8UC4);
}
你能顯示輸入和輸出圖像嗎? – AldurDisciple 2014-10-05 10:28:01