1
I = imread('C:\\Users\\20055316\\Desktop\\blurMetric\\Illumination_Changes\\z_0001.bmp');
I = double(I);
[y, x] = size(I);
Hv = [1 1 1 1 1 1 1 1 1]/9;
Hh = Hv';
B_Ver = imfilter(I,Hv);%blur the input image in vertical direction
B_Hor = imfilter(I,Hh);%blur the input image in horizontal direction
我需要轉換上面的Matlab代碼到OpenCV的, 我嘗試使用Filter2D但沒有得到期望的結果。 OpenCV的代碼如下所示Matlab來opencv的代碼
Mat oMatTempImage = imread("C:\\Users\\20055316\\Desktop\\blurMetric\\Illumination_Changes\\z_0001.bmp");
cvtColor(oMatTempImage, oMatTempImage, CV_BGR2RGB);
oMatTempImage.convertTo(oMatTempImage, CV_32FC3);
Mat oMatVerticalKernel = Mat(1, 9, CV_32FC1);
for (int nColItr = 0; nColItr < 9; nColItr++)
{
oMatVerticalKernel.at<float>(0, nColItr) = 1.0f/9.0f;
}
Mat oMatHorizontalKernel;
transpose(oMatVerticalKernel, oMatHorizontalKernel);
Mat oMatVeriticalBlurr;
filter2D(oMatTempImage, oMatVeriticalBlurr, -1, oMatVerticalKernel);
Mat oMatHorizontalBlurr;
filter2D(oMatTempImage, oMatHorizontalBlurr, -1, oMatHorizontalKernel);
我沒有得到類似的結果,請幫我請。
編輯: 謝謝你們的回覆, 我已經知道是什麼問題了。 當imfilter()函數被調用時,Matlab在內部進行零填充,而opencv不會這樣做。在應用過濾器之前,我必須先將零點填充並在稍後移除零填充像素。這解決了這個問題。
結果是什麼?我假設你知道你在做什麼轉換開始 – 2014-09-29 09:05:08
@ MarcoA.yes即時嘗試將圖像從uchar轉換爲浮點類型,我想知道的是,filter2D正確的方法來轉換Matlab imfilter opencv,如果不是,我該如何繼續? – Barry 2014-09-29 09:09:16
@Barry是的,這些是等價的(雖然有更簡單的方法來編寫您的OpenCV代碼)。請張貼顯示不同結果的圖像。 – 2014-09-29 11:46:03