In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
How to use multi-scale fusion to improve image details in OpenCV image processing, in order to solve this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
Preface
Today, I will introduce an algorithm that uses multi-scale to improve the details of the image. You can try this algorithm if you want your picture to look richer in details.
Algorithm principle
The core of the paper is that the paper uses the similar idea of Retinex method, uses multi-scale Gaussian kernel to filter the original image, and then subtracts with the original image to obtain different degrees of detail information, and then fuses these detail information into the original image through a certain combination way, so as to enhance the ability of the original image information. The formula is very simple. Note that the first coefficient is a little special. If you realize it, just look at several formulas in the figure below.
"from the idea of the feature pyramid network in deep learning, this algorithm is actually a fusion of feature maps on different scales, but this way is directly aimed at the original image, which is relatively rough, but there is an advantage that this algorithm is easy to optimize when used in the preprocessing stage. We will discuss how to optimize the SSE instruction set later when we talk about optimization. Today we will first provide the original implementation. "
Insert the picture description code here to implement void separateGaussianFilter (const Mat & src, Mat & dst, int ksize, double sigma) {
CV_Assert (src.channels () = = 1 | | src.channels () = = 3); / / only single-channel or three-channel images are processed
/ / generate one-dimensional
Double * matrix = new double [ksize]
Double sum = 0
Int origin = ksize / 2
For (int I = 0; I
< ksize; i++){ double g = exp(-(i-origin) * (i-origin) / (2 * sigma * sigma)); sum += g; matrix[i] = g; } for(int i = 0; i < ksize; i++) matrix[i] /= sum; int border = ksize / 2; copyMakeBorder(src, dst, border, border, border, border, BORDER_CONSTANT); int channels = dst.channels(); int rows = dst.rows - border; int cols = dst.cols - border; //水平方向 for(int i = border; i < rows; i++){ for(int j = border; j < cols; j++){ double sum[3] = {0}; for(int k = -border; k 255) sum[k] = 255; } if(channels == 1) dst.at(i, j) = static_cast(sum[0]); else if(channels == 3){ Vec3b rgb = {static_cast(sum[0]), static_cast(sum[1]), static_cast(sum[2])}; dst.at(i, j) = rgb; } } } //竖直方向 for(int i = border; i < rows; i++){ for(int j = border; j < cols; j++){ double sum[3] = {0}; for(int k = -border; k 255) sum[k] = 255; } if(channels == 1) dst.at(i, j) = static_cast(sum[0]); else if(channels == 3){ Vec3b rgb = {static_cast(sum[0]), static_cast(sum[1]), static_cast(sum[2])}; dst.at(i, j) = rgb; } } } delete [] matrix; } Mat MultiScaleDetailBoosting(Mat src, int Radius){ int rows = src.rows; int cols = src.cols; Mat B1, B2, B3; separateGaussianFilter(src, B1, Radius, 1.0); separateGaussianFilter(src, B2, Radius*2-1, 2.0); separateGaussianFilter(src, B3, Radius*4-1, 4.0); float w1 = 0.5, w2 = 0.5, w3 = 0.25; Mat dst(rows, cols, CV_8UC3); for(int i = 0; i < rows; i++){ for(int j = 0; j < cols; j++){ for(int k = 0; k < 3; k++){ int D1 = src.at(i, j)[k] - B1.at(i, j)[k]; int D2 = B1.at(i, j)[k] - B2.at(i, j)[k]; int D3 = B2.at(i, j)[k] - B3.at(i, j)[k]; int sign = D1 >0? 1:-1
Dst.at (I, j) [k] = saturate_cast ((1-w1*sign) * D1-w2 * D2 + w3 * D3 + src.at (I, j) [k])
}
}
}
Return dst
}
This is the answer to the question about how to use multi-scale fusion to improve image details in OpenCV image processing. I hope the above content can be of some help to everyone. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.