Now it is high time for us to speak about filters.Before we do this first we have to understand what is frequency in an image. To understand the existence of frequency in an image we would have to look at a diagram below.
The diagram is as follows
AFter getting an idea about what is frequency in an image we would now work on how to make a filter first. Now assume in the above figure the first 2 values 20,21 are reduced to zero. What would happen is there would be a sudden spike in the value from zero to 220 which is a sudden change, a bigger change. Which means spike is more concentrated.If I change the value of 20,21 to 120,121 then the spike is not much concentrated. The transition from 120,121 to 220 is a bit smoother. The change is not ‘that’ apparent.
This is what I would want to teach you. Image smoothing in the above context means reducing the strength of crests and troughs.Now observe these numbers and draw a figure in your mind.
21,25,29,38,42,54,65,52,41,39,32,20
20,220,180,11,10,240,245,65,82,91,180
Observe the first line must be an image which is not sharp to watch.The numbers convert smoothly into each other when compared to the second line.Second line of numbers comprises of huge spikes.
So you might take some Images and make spikes in them.For example: add a scalar value to the numbers above the threshold,and deduct the same scalar value from numbers below ‘another’ threshold.
Well! I have done some thing else to explain follow the program below.
#include "math.h"
#include "conio.h"
#include "cv.h"
#include "highgui.h"
#include "stdio.h"
#define lcutoff 100
#define hcutoff 255
/*Making a high pass filter*/
int main()
{
int i,j,k;
double temp;
uchar *datar,*dataf;
IplImage *frame=cvLoadImage("monolena.jpg",1);
int heightr,widthr,stepr,channelsr;
IplImage *result=cvCreateImage( cvGetSize(frame), 8, 1 );
if(frame==NULL ) {
puts("unable to load the frame");exit(0);}
cvNamedWindow("original",CV_WINDOW_AUTOSIZE);
cvNamedWindow("Result",CV_WINDOW_AUTOSIZE);
int stepf,channelsf;
heightr = result->height;
widthr = result->width;
stepr=result->widthStep;
stepf=frame->widthStep;
channelsr=result->nChannels;
channelsf=frame->nChannels;
datar = (uchar *)result->imageData;
dataf = (uchar *)frame->imageData;
/*Do not get confused.Here i have just taken the first channel of the image regardless if the image
is multichannel*/
/*first copy the first channel into the result image.*/
for(i=0;i<heightr;i++) for(j=0;j<widthr;j++)
{
datar[i*stepr+j*channelsr]=dataf[i*stepf+j*channelsf];
}
/*Apply the filter in these for loops*/
for(i=0;i<heightr;i++) for(j=0;j<widthr;j++){
if(datar[i*stepr+j*channelsr]<lcutoff || datar[i*stepr+j*channelsr]>hcutoff)
datar[i*stepr+j*channelsr]=0;}
/*Any value in the image if less than the lower cutoff or higher than the higher cut off would get eliminated.
This can be used as a highpass,low pass,band pass filter also if you ponder for some time.*/
cvShowImage("Result", result);
cvShowImage("original", frame);
cvSaveImage("monolenafilter.jpg",result);
cvWaitKey(0);
cvDestroyWindow("original");
cvDestroyWindow("Result");
return 0;
}

Now if you are a good observer notice that there are sharp transitions in the grey level.We have hence implemented a high pass filter using spatial transformations in rather a crude way.

Dear Sir,
Is there anybody who can help me to solve following problem?
As a beginner I am facing one problem to separate or cut overlapping objects. If possible could
you please give me some ideas or programming codes regarding this.
If possible, Let me advice it will be highly appreciated.
Best regards,
Momin
Comment by Momin — December 17, 2010 @ 1:55 am |
Please attach an image and then we would knw or give an idea ….hot link an image…sample
Comment by colouredpages — December 17, 2010 @ 3:48 pm |