Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use opencv FT saliency detection algorithm

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to use the opencv FT saliency detection algorithm". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use the opencv FT saliency detection algorithm.

Principle of FT algorithm

The FT algorithm comes from the paper:

Frequency-tuned salient region detection

The implementation of the FT algorithm is also very simple, which analyzes the image from the point of view of frequency.

The image can be divided into low frequency part and high frequency part in frequency domain. The low frequency part reflects the overall information of the image, such as the outline of the object, the basic composition of the region. The high frequency part reflects the details of the image, such as the texture of the object. The significant region detection uses more information of the low frequency part.

In the actual calculation, the FT method uses the Gaussian smoothing of window 5 to 5 to realize the rounding of the highest frequency. The significance of pixels can be calculated by the following formula:

Among them, Iu is the average feature of the image, using Lab color feature, and the latter is the Lab color feature of pixel p after Gaussian smoothing, |. | | L2 normal form, that is, the Euclidean distance between the former term and the latter term in the Lab color space is calculated.

Algorithm realization

The FT method is easy to implement and only needs Gaussian smoothing and average calculation.

The image is smoothed by 5-5 Gaussian smoothing.

Convert the color space. Convert RGB color space to CIELAB color space

Calculate the average of l, a, b of the whole picture

According to the formula in the algorithm, the Euclidean distance between the l, a, b values of each pixel and the three l, a, b means of the image is calculated, and a significant graph is obtained.

Normalization. The salient value of each pixel in the image divided by the largest salient value. Get the final salient map.

Programming:

Void FT::calculateSaliencyMap (Mat * src, Mat * dst, bool corlor,int ksize) {if (corlor & & (* src). Channels () = 3) / / deal with color fields {Mat img3f = (* src); img3f.convertTo (img3f, CV_32FC3, 1.0255); Mat sal (img3f.size (), CV_32F), tImg; GaussianBlur (img3f, tImg, Size (ksize, ksize), 0) / / Gaussian smooth removal of high frequency information cvtColor (tImg, tImg, COLOR_BGR2Lab); / / conversion to LAB color space Scalar colorM = mean (tImg); / / calculation of the LAB color mean of the whole image / / ergodic image for (int r = 0; r)

< tImg.rows; r++) { float *s = sal.ptr(r); float *lab = tImg.ptr(r); for (int c = 0; c < tImg.cols; c++, lab += 3) //计算每个像素LAB值与LAB均值的差,即为显著性 s[c] = (float)(sqr(colorM[0] - lab[0]) + sqr(colorM[1] - lab[1]) + sqr(colorM[2] - lab[2])); } normalize(sal, *dst, 0, 1, NORM_MINMAX); } else //灰度域 { Mat imgf, tImg; imgf = *src; if (imgf.channels() == 3) { cvtColor(imgf, imgf, COLOR_RGB2GRAY); } imgf.convertTo(imgf, CV_32FC1, 1.0 / 255); Scalar colorM = mean(imgf); GaussianBlur(imgf, tImg, Size(ksize, ksize), 0); Mat sal(imgf.size(), CV_32F); for (int r = 0; r < tImg.rows; r++) { float *s = sal.ptr(r); float *gray = tImg.ptr(r); for (int c = 0; c < tImg.cols; c++) s[c] = (colorM[0] - gray[c])*(colorM[0] - gray[c]); } normalize(sal, *dst, 0, 1, NORM_MINMAX); }}算法效果

At this point, I believe you have a deeper understanding of "how to use the opencv FT significance detection algorithm". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report