In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how OpenCV achieves the ground glass effect of PS diffusion. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Realization principle
The diffusion effect of PS can produce a texture similar to ground glass, making the picture feel hairy. It can be realized by manipulating the three-channel values of pixels, defining a random numerator, assigning the value of any point in the image to the value of a random point in a window of a certain size (such as 3-3-5-5).
Function code
/ / Diffusion effect cv::Mat Diffusion (cv::Mat src,int size) {int row = src.rows; int col = src.cols; RNG rng; cv::Mat result = src.clone (); for (int I = size; I < row- size; + + I) {uchar* t = result.ptr (I); for (int j = size; j < col- size) + + j) {int tmp = rng.uniform (0, 2*size+1); t [3 * j] = src.at (I-size+ tmp / (2*size+1), 3 * (j-size+ tmp% (2*size+1) T [3 * j + 1] = src.at (I-size + tmp / (2 * size + 1), 3 * (j-size + tmp% (2 * size + 1) + 1); t [3 * j + 2] = src.at (I-size + tmp / (2 * size + 1), 3 * (j-size + tmp% (2 * size + 1)) + 2) }} return result;}
C++ test code
# include # include # include using namespace std;using namespace cv; cv::Mat Diffusion (cv::Mat src, int size); int main () {cv::Mat src = imread ("test.jpg"); int size = 5; cv::Mat result = Diffusion (src,size); cv::imshow ("original", src); cv::imshow ("result", result); waitKey (0); return 0 } / / Diffusion effect cv::Mat Diffusion (cv::Mat src,int size) {int row = src.rows; int col = src.cols; RNG rng; cv::Mat result = src.clone (); for (int I = size; I < row- size; + + I) {uchar* t = result.ptr (I); for (int j = size J < col- size; + + j) {int tmp = rng.uniform (0, 2*size+1); t [3 * j] = src.at (I-size+ tmp / (2*size+1), 3 * (j-size+ tmp% (2*size+1) T [3 * j + 1] = src.at (I-size + tmp / (2 * size + 1), 3 * (j-size + tmp% (2 * size + 1) + 1); t [3 * j + 2] = src.at (I-size + tmp / (2 * size + 1), 3 * (j-size + tmp% (2 * size + 1)) + 2) }} return result;}
Test effect
Fig. 1 original picture
Fig. 2 5 Diffusion
Fig. 3 11-11 diffusion
Proper adjustment of size can change the intensity of diffusion and bring different texture.
Thank you for reading! This is the end of this article on "how to achieve PS diffusion ground glass effect in OpenCV". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
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.