Guest User

Untitled

a guest
Jan 24th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. void invert_image( IplImage* source, IplImage* result )
  2. {
  3.     //+ TO DO:  Write code to invert all points in the source image (i.e. for each channel for each pixel in the result
  4.     //        image the value should be 255 less the corresponding value in the source image).
  5.     int width_step=source->widthStep;
  6.     int pixel_step=source->widthStep/source->width;
  7.     int number_channels=source->nChannels;
  8.     cvZero( result );
  9.     unsigned char white_pixel[4] = {255,255,255,0};
  10.     int row=0,col=0;
  11.  
  12.     for (row=0; row < result->height; row++)
  13.         for (col=0; col < result->width; col++)
  14.         {
  15.             unsigned char* curr_point = GETPIXELPTRMACRO( source, col, row, width_step, pixel_step );
  16.             char pixel[4]={curr_point[RED_CH]-255,curr_point[GREEN_CH]-255,curr_point[BLUE_CH]-255};
  17.             PUTPIXELMACRO( result, col, row, white_pixel, width_step, pixel_step, number_channels );
  18.            
  19.         }
  20. }
Add Comment
Please, Sign In to add comment