影象A,B,為同一場景在不一樣的光照拍攝圖片,那麼: 光照分佈 L = A / B 如果已知 A, L ,則 B = A / L (B 為A去光照的結果) 這裡L約等於 gaussFilter(A, 大核)
Mat src = imread("t1.jpeg"); src.convertTo(src,CV_32FC3,1.0/255); Mat gauss; Mat dst = src.clone(); cv::GaussianBlur(src,gauss,Size(101,101),0); //劃分 //如果混合色與基色相同則結果色為白色 //如混合色為白色則結果色為基色不變 //如混合色為黑色則結果色為白色 dst = src/gauss; waitKey();
//USM影象增 void ImageSharp(Mat &src,Mat &dst,int nAmount = 1000) { double sigma = 3; int threshold = 1; float amount = nAmount/100.0f; Mat imgBlurred; GaussianBlur(src, imgBlurred, Size(), sigma, sigma); Mat lowContrastMask = abs(src-imgBlurred)<threshold; dst = src*(1+amount)+imgBlurred*(-amount); src.copyTo(dst, lowContrastMask); } int main() { Mat src = imread("E:\\未來專案\\白板增強\\images\\t1.jpeg"); src.convertTo(src,CV_32FC3,1.0/255); Mat gauss; Mat dst1 = src.clone(); Mat dst2 = src.clone(); cv::GaussianBlur(src,gauss,Size(101,101),0); dst1 = src/gauss; blur(src,gauss,Size(101,101)); dst2 = src/gauss; //劃分 ImageSharp(dst2,dst2,101); waitKey(); return 0; }
「這個演演算法在此類影象中能夠成功的核心是:在原圖中比較黑的文字部分,佔用的整體是比較少的,當大半徑模糊時,模糊的值是接近紙張之類的顏色的,也就是比較靠近白色,所以結果基本上沒什麼變化,而紙張那些地方的顏色,因為模糊的值和他們的原始值基本差不多,所以Src/Blur基本接近1,在乘以255,所以結果就變為白色了。」
divide Performs per-element division of two arrays or a scalar by an array. C++: void divide(InputArray src1, InputArray src2, OutputArray dst, double scale=1, int dtype=-1) C++: void divide(double scale, InputArray src2, OutputArray dst, int dtype=-1) Python: cv2.divide(src1, src2[, dst[, scale[, dtype]]]) → dst Python: cv2.divide(scale, src2[, dst[, dtype]]) → dst C: void cvDiv(const CvArr* src1, const CvArr* src2, CvArr* dst, double scale=1) Python: cv.Div(src1, src2, dst, scale=1) → None Parameters: src1 – first input array. src2 – second input array of the same size and type as src1. scale – scalar factor. dst – output array of the same size and type as src2. dtype – optional depth of the output array; if -1, dst will have depth src2.depth(), but in case of an array-by-array division, you can only pass -1 when src1.depth()==src2.depth(). The functions divide divide one array by another: or a scalar by an array when there is no src1 : When src2(I) is zero, dst(I) will also be zero. Different channels of multi-channel arrays are processed independently.