FILTERING IMAGE

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;
}
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;
}
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;
}
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; }
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;
}
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; }
Okay these are just some of the existing filtering process in OpenCV. I will continue it at any time.
2 comments:
You know how they can do this example in a "Windows Form" I try, and image in "gray scale" appears 3 times! : S
Try changing the PixelFormat but did not work.
Know how to do it?
Tomás
Sory I don't have a solution for your problem.
Cause grayscale image in 8 bit color image, but picturebox must be in 24 bit color(RGB 3-channel) Pixelformat, so we must convert it before.
frame= cvQueryFrame(capture); cvCvtColor(frame,img,CV_BGR2GRAY);
cvSaveImage("tes.jpg",img);
img2 = cvLoadImage("tes.jpg",1);
pictureBox1->Image = gcnew //replacement of cvShowImage
System::Drawing::Bitmap(img2->width,img2->height,img2->widthStep,
System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr) img2->imageData);
pictureBox1->Refresh();
maybe you can use this to convert it, but I think it's not good idea for continuously. cause it will make an unhandled exception(over memory)
Post a Comment