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.
![]() |
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");
cvNamedWindow("MyWindow");
cvShowImage("MyWindow", img);
//invert and display the inverted image
cvNot(img, img);
cvNamedWindow("Inverted");
cvShowImage("Inverted", img);
cvWaitKey(0);
//cleaning up
cvDestroyWindow("MyWindow");
cvDestroyWindow("Inverted");
cvReleaseImage(&img);
return 0;
}
#include <cv.h>
#include <highgui.h>
int main()
{
//display the original image
IplImage* img = cvLoadImage("C:/MyPic.jpg");
cvNamedWindow("MyWindow");
cvShowImage("MyWindow", img);
//invert and display the inverted image
cvNot(img, img);
cvNamedWindow("Inverted");
cvShowImage("Inverted", img);
cvWaitKey(0);
//cleaning up
cvDestroyWindow("MyWindow");
cvDestroyWindow("Inverted");
cvReleaseImage(&img);
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 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
bitwise_not(src,dest);
ReplyDeleteThank you!
DeleteThank you so much for this greate tutorial.
DeleteI'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++.