OpenCV Learning Record: filter: comic picture

Source: Internet
Author: User

OpenCV Learning Record: filter: comic picture

When I was in elementary school, I read the small comic book of the Dragon Ball many times, and I borrowed the book from the bookstore next to the school. At that time, I thought I was a Chinese author. I was wondering why some people were named such strange names. My tears have fallen :(.

The main algorithm idea of the loop painting filter:

1. Use the following formula to calculate the new RGB value:
R = (| 2 * g-B + r | * r)> 8;
G = (| 2 * B-g + r | * r)> 8;
B = (| 2 * B-g + r | * r)> 8;
The 8-digit shift to the right is equivalent to dividing by 256.

2. Calculate the gray value using the average value method:
Gray = (R + G + B)/3

3. Set the new RGB value:
R = Gray + 10;
G = Gray + 10;
B = Gray;
The RGB value must be between 0 and 255.

The complete code is as follows:

# Include
  
   
# Include
   
    
Using namespace cv; using namespace std; void lihuan1_filter (Mat & srcImage); int main () {Mat srcImage = imread ("longzhu.jpg"); if (! SrcImage. data) {cout <"An error occurred while reading the image! "<
    
     
(J); for (int I = 0; I
     
      
> 8; int G = (abs (2 * B-g + r) * r)> 8; int B = (abs (2 * B-g + r) * r)> 8; R = max (0, min (R, 255); G = max (0, min (G, 255 )); B = max (0, min (B, 255); int gray = (R + G + B)/3; R = min (255, gray + 10 ); data [I * 3 + 2] = R; data [I * 3 + 1] = R; data [I * 3] = gray ;}} imshow ("loop filter ", srcImage );}
     
    
   
  

Laizhang longzhu's:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.