Thresholding is very very Important aspect in any field and not just in Open Computer Vision..but in Image processing you need to specify some conditions which is very frequently Thresholding and this is what is the main concern of this post.Here you would get to know about what is Thresholding and also how to use the same and when its required.In almost every program you would specify to extract a pixel above a certain value which is nothing but thresholding ….. (more…)
April 9, 2008
Setting an Region of Interest in an image
Friends below is some code which can set the region of interest.Well its really simple.
Have a look at the code below and it will be really simple to understand here you go (more…)
April 8, 2008
Loading an Image, Manipulating it and Saving it.
Here in this post I am speaking about how to load an image and how to play with the Image.Here I have used the same Image called lena.jpg which is a very good image for all of the image processing operations.The image is special because any or most of the image processing operations are easily observable on the image.
In the program below by uncommenting certain lines we can make the data in the certain channels zero and it depends upon which line/lines are you uncommenting.The below program allows you to convert any channel image data to zero.You can make your own changes to the code I have put up and Remember that I have already told you that please do not look at an image as an image but look at it as an array of data channels.Then things will get easier for you. (more…)
Loading and saving an Image.
I’d really suggest that you read another post on this blog which speaks about an IplImage for beginners.Others can look after the code if you already know about the basics of IplImage..
//Program starts
#include "cv.h"
#include "highgui.h"
#include "stdio.h"
//#include "conio.h"
int main() {//Here if you want you can also put arguments to main if you want
int height,width,step,channels;
uchar *data;
int i,j,k;
IplImage* frame=cvLoadImage("lena.jpg",1);/*This is the basic function which can load an image into a frame.
Here name of the image is same as the image which should be present in the the same
folder where you are working, along with the Extension(here .jpg).*/
if(frame==NULL){ /*If unable to find image, exit.This is the function of this loop */
printf("the file doesnot exist");
exit(0);
}
height = frame->height;/*height is a member of IplImage structure
and hence it comes handy like this in such situations, and same goes with below four statements*/
width = frame->width;
step = frame->widthStep;
channels = frame->nChannels;/*Number of channels in the image*/
data = (uchar *)frame->imageData;/*Image is treated as as unsigned char data
hence we use an unsigned char pointer to point to the same*/
for(i=0;i< (height);i++)
for(j=0;j< (width);j++)
for(k=0;k<(channels);k++)
if(data[i*step+j*channels+k]>200)
/*Here if the pixel is above the threshold(200) is moved to highest value
and the pixels below the threshold are left as it is*/
cvNamedWindow( "mywindow", CV_WINDOW_AUTOSIZE );/*this statement
will initiate a window named mywindow in autosize mode*/
cvShowImage("mywindow",frame);/*THis statement will shoe the image in
the window made by the above statement*/
cvSaveImage("Thresholded_image.jpg",frame);/*THis function will save the image */
/*as we can see name of the image is followed by the extension..
and the second argument "frame" is the image which will
be saved .This applies similarly in the above statement cvShowImage as well.Be careful regarding this.*/
cvDestroyWindow( "mywindow" );/*Destroying the initialized Windows */
return 0;/*This statement is compiler specific and might change.
As i already said that I am using DEV C++ as my compiler*/
/*Now try to do the same program a thresholding Operation by an Open Cv function
called cvThreshold.Search for this function in the
documentation and use it.Have fun with technology.*/
/*The image will be saved in the same folder where the program exists*/
}
April 4, 2008
Thresholding Operation in OPENCV
Now lets speak about thresholding Operation in OpenCV.
Basic Idea of thresholding is a cut off or a limit..
As we know we can allow or not allow some pixels to go beyond a certain limit.This Thresholding Operation is very useful in many applications.So let’s discuss..
Here in this program i did not use CvAdaptiveThreshold.Simply because i got what i wanted to do on an image.Now you know the function from Opencv and also your own way to do it.Well your choice..
#include "cv.h"
#include "highgui.h"
#include "stdio.h"
int main() {
int height,width,step,channels;
uchar *data;
int i,j,k;
IplImage* frame=cvLoadImage("lena.jpg",1);
if(frame==NULL){ /*If image not fund then exit.
This is the function of this loop */
printf("the file doesnot exist");
exit(0);
}
height = frame->height;/*height is a member of IPLIMAGE structure
and hence it comes handy like this in such situations,
and same goes with below four statements*/
width = frame->width;
step = frame->widthStep;
channels = frame->nChannels;/*Number of channels in the image*/
data = (uchar *)frame->imageData;/*Image is treated as as unsigned char
data hence we use an unsigned char pointer to point to the same*/
for(i=0;i< =height-1;i++)
for(j=0;j <=width-1;j++)
for(k=0;k < 3;k++;)
if (data[i*step+j*channels+k] >=200)
data[i*step+j*channels+k]=255;
/*Here if the pixel is above the threshold(200) is moved to highest value
and the pixels below the threshold are left as it is*/
cvNamedWindow( "mywindow", CV_WINDOW_AUTOSIZE );/*this statement
will initiate a window named mywindow in autosize mode*/
cvShowImage("mywindow",frame);
/*THis statement will show the image in the window
made by the above statement*/
cvSaveImage("Thresholded_image.jpg",frame);/*This function will save the image */
/*as we can see name of the image is followed by the extension.. and the
second argument "frame" is the image which will be saved .This applies
similarly in the above statement cvShowImage as well.Be careful regarding this.*/
cvDestroyWindow( "mywindow" );/*Destroying the initialized Windows */
return 0;/*This statement is compiler specific and might change.
As i already said that I am using DEV C++ as my compiler*/
/*Now try to do the same program a thresholding Operation
by an OpenCV function called cvThreshold.
Search for this function in the
documentation and use it.Have fun with technology.*/
/*The image will be saved in the same folder
where the program exists*/
}
OpenCV Beginners
Dear friends,
This post speaks about how to make use of , or, in other words how to know where to look for data or the Information which you need.I am a member in the yahoo group of the Open CV and I found many beginner Questions popping up related to the camera settings and very basic questions such as pixel access and some others..
So friends after downloading and installing OPEN CV (more…)
Images in OpenCV
This post will speak about creating an image. A simple 8 bit monochrome image.As weknow monochrome image has a single channel and since it is an 8 bit image it has only 0 to 255(n-1)gray levels to represent.Which means (more…)
