FILTERING IMAGE

In the previous episode, you have learned how to load an image with OpenCV (Episode 2). For this episode, we will try how to editing of the image in the real time such as
brightness, negatve, bluring, removing noise, etc. We will now move on to higher-level methods that treat the images as images, and not just as arrays of colored (or grayscale) values. When we say “image processing”, we mean just that: using higher-level operators that are defined on image structures in order to accomplish tasks whose meaning is naturally defi ned in the context of graphical, visual images.
Part A. Eroding the ImageI won't explain in detail what is erode?
because you can learn it yourself. Here I will Erode the image 2 times;
#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
int main(int argc, char* argv[])
{
IplImage *img = cvLoadImage("Step_forward.jpg");
IplImage *img2= cvCreateImage( cvGetSize(img), 8,1 );
img2 = cvCloneImage(img);
cvErode(img2, img2, 0, 2);
cvShowImage("Image:",img);
cvShowImage("Eroded", img2);
cvWaitKey();
cvReleaseImage(&img);
cvReleaseImage(&img2);
return 0;
}
picture 0_eroding_images
Part B. Dilating the Image
Dilating the image is the opposite of Erode image.
#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
int main(int argc, char* argv[])
{
IplImage *img = cvLoadImage("Step_forward.jpg");
IplImage *img2= cvCreateImage( cvGetSize(img), 8,1 );
img2 = cvCloneImage(img);
cvDilate(img2, img2, 0, 2);
cvShowImage("Image:",img);
cvShowImage("Dilate", img2);
cvWaitKey();
cvReleaseImage(&img);
cvReleaseImage(&img2);
return 0;
}
picture 1_dilating_images
Part C. BrightnessFor brightness, we use the cvAddS function. This function adds a scalar to each element of the matrix. There also exists a cvAdd function, but that function adds two matrices (not a matrix and a value).
#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
int main(int argc, char* argv[])
{
IplImage *img = cvLoadImage("Step_forward.jpg");
IplImage *img2= cvCreateImage( cvGetSize(img), 8,1 );
img2 = cvCloneImage(img);
cvAddS(img2, cvScalar(50,50,50), img2);
cvShowImage("Image:",img);
cvShowImage("Brigth", img2);
cvWaitKey();
cvReleaseImage(&img);
cvReleaseImage(&img2);
return 0;
}
picture 2_brightness_image
Part D. Contrast
For brightness, you added values. For contrast, you multiply.
For adding scalars (values), you use cvAddS. For multiplying, you use cvScale
#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
int main(int argc, char* argv[])
{
IplImage *img = cvLoadImage("Step_forward.jpg");
IplImage *img2= cvCreateImage( cvGetSize(img), 8,1 );
img2 = cvCloneImage(img);
cvScale(img2, img2, 2);
cvShowImage("Image:",img);
cvShowImage("Contrast", img2);
cvWaitKey();
cvReleaseImage(&img);
cvReleaseImage(&img2);
return 0;
}
picture 3_contrast_image
Part E. NegativeInverting the image such as giving a NOT logic operation on each element matrix.
#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
int main(int argc, char* argv[])
{
IplImage *img = cvLoadImage("Step_forward.jpg");
IplImage *img2= cvCreateImage( cvGetSize(img), 8,1 );
img2 = cvCloneImage(img);
cvNot(img2, img2);
cvShowImage("Image:",img);
cvShowImage("Negative", img2);
cvWaitKey();
cvReleaseImage(&img);
cvReleaseImage(&img2);
return 0;
}
picture 4_negative_images
Part F. GrayColorFor further image processing, is generally used to change the image in the form of a binary image so its can facilitate the morpological operation such as threshold, laplace, Canny, and others.
#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
int main(int argc, char* argv[])
{
IplImage *img = cvLoadImage("Step_forward.jpg");
IplImage *img2= cvCreateImage( cvGetSize(img), 8,1 );
cvCvtColor(img,img2,CV_BGR2GRAY);
cvShowImage("Image:",img);
cvShowImage("Gray", img2);
cvWaitKey();
cvReleaseImage(&img);
cvReleaseImage(&img2);
return 0;
}
picture 5_graycolor
Okay these are just some of the existing filtering process in OpenCV. I will continue it at any time.