Invert Images and Videos

Here is the original image which I am going to filter using above methods.

Inverting an image is like taking the negative of an image.


#include "stdafx.h"
#include <cv.h>
#include <highgui.h>

int main()
        //display the original image
        IplImage* img = cvLoadImage("C:/MyPic.jpg");
        cvShowImage("MyWindow", img);

        //invert and display the inverted image
        cvNot(img, img);
        cvShowImage("Inverted", img);

        //cleaning up
        return 0;


You can download this OpenCV visual c++ project from here

Inverted Image

 New OpenCV functions which are not found earlier are explained here
  • cvNot(img, img)
This function inverts every bit in every element of the image in the 1st parameter and places the result in the image in the 2nd parameter.
This function can process images in place. That means same variable can be used for the 1st and 2nd parameters.

e.g - For a 8 bit image, the value 0 will be mapped to (255-0)=255
                                        the value 46 will be mapped to (255-46)=209

        For a 16 bit image, the value 0 will be mapped to (65535-0)=65535
                                   the value 46 will be mapped to (65535-46)=65489


  1. bitwise_not(src,dest);

    1. Thank you so much for this greate tutorial.
      I'am new to opencv and I found your explanation very well.
      but there is an improvement:

      since your tutorial is with c++ it would be better to use every header and every function that is related to c++.
      for instance in the invert image section you used cv.h or IplImage* cvLoadImage() and ... which are for c and not c++.

  2. Comprar carnet de conducir en nuestra web inscrito en el Dgt en un plazo de 5 a 7 días hábiles sin exámenes y podrá conducir libremente en España y otros países sin ningún problema señor

    Comprar Licencia de Conducir

    Comprar Carnet de Conducir

    Comprar Licencia Conducir Legal

    Comprar carnet de conducir

    comprar licencias de conducir

    comprar carnet conducir dgt

    comprar licencia de conducir

  3. koop rijbewijs online geregistreerd in de gemeente binnen 5 tot 7 werkdagen tegen een goedkope prijs zonder examens
    Rijbewijs Kopen België

    Rijbewijs Kopen

    Rijbewijs b Kopen

    Rijbewijs Online Kopen