Image inversion: Gray image range is [0,l-1] image inversion, expression s=l-1-r; reverse the intensity of the image in this way, it can produce the image inversion of the equivalent image.
# include <stdlib.h> #include <stdio.h> #include <math.h> #include "cv.h" #include "highgui.h" #pragma Comment (lib, "Cv.lib") #pragma comment (lib, "Cxcore.lib") #pragma comment (lib, "Highgui.lib") int main () { int length,width,step,channel; UCHAR * data; int i,j,k; iplimage* img; Img=cvloadimage ("1.jpg", 0); Cvnamedwindow ("source", 0); Cvshowimage ("Source", IMG); if (!img) printf ("Could not find the image\n"); length=img->height; width=img->width; step=img->widthstep; channel=img->nchannels; Data= (uchar*) img->imagedata; for (i=0;i<=length-1;i++) {for (j=0;j<=width-1;j++) {for (k=0;k<=channel-1;k++) { data[i* STEP+J*CHANNEL+K]=255-DATA[I*STEP+J*CHANNEL+K]; } }} Cvnamedwindow ("Convert", 0); Cvshowimage ("Convert", IMG); Cvwaitkey (0); Cvreleaseimage (&img); return 0;}
Inversion of image pixel values