diff --git a/experiment/simulation/build/1.png b/experiment/simulation/build/1.png
new file mode 100644
index 0000000..e674b8b
Binary files /dev/null and b/experiment/simulation/build/1.png differ
diff --git a/experiment/simulation/build/2.png b/experiment/simulation/build/2.png
new file mode 100644
index 0000000..5e0d768
Binary files /dev/null and b/experiment/simulation/build/2.png differ
diff --git a/experiment/simulation/build/allexec.sh b/experiment/simulation/build/allexec.sh
new file mode 100644
index 0000000..5bac0a7
--- /dev/null
+++ b/experiment/simulation/build/allexec.sh
@@ -0,0 +1,21 @@
+export OPENCV_INC=/usr/include/opencv
+export OPENCV_LIB=/usr/lib/
+export OPENCV_LIB_OPTS="-lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann"
+
+sudo apt-get update
+sudo apt-get install -y gcc
+sudo apt-get update
+gcc -I$OPENCV_INC codes/latest_affine.cpp -L$OPENCV_LIB $OPENCV_LIB_OPTS -o execs/affine.out
+gcc -I$OPENCV_INC codes/im_arith.cpp -L$OPENCV_LIB $OPENCV_LIB_OPTS -o execs/arith.out
+gcc -I$OPENCV_INC codes/im_dist.cpp -L$OPENCV_LIB $OPENCV_LIB_OPTS -o execs/dist.out
+gcc -I$OPENCV_INC codes/im_fourier.cpp -L$OPENCV_LIB $OPENCV_LIB_OPTS -o execs/fourier.out
+gcc -I$OPENCV_INC codes/im_hist.cpp -L$OPENCV_LIB $OPENCV_LIB_OPTS -o execs/hist.out
+gcc -I$OPENCV_INC codes/im_morphology.cpp -L$OPENCV_LIB $OPENCV_LIB_OPTS -o execs/morpho.out
+gcc -I$OPENCV_INC codes/im_nbrhood.cpp -L$OPENCV_LIB $OPENCV_LIB_OPTS -o execs/neigh.out
+gcc -I$OPENCV_INC codes/im_path.cpp -L$OPENCV_LIB $OPENCV_LIB_OPTS -o execs/path.out
+gcc -I$OPENCV_INC codes/im_point.cpp -L$OPENCV_LIB $OPENCV_LIB_OPTS -o execs/point.out
+gcc -I$OPENCV_INC codes/im_segment.cpp -L$OPENCV_LIB $OPENCV_LIB_OPTS -o execs/segment.out
+gcc -I$OPENCV_INC codes/im_colour.cpp -L$OPENCV_LIB $OPENCV_LIB_OPTS -o execs/colour.out
+gcc -I$OPENCV_INC codes/im_colourLin.cpp -L$OPENCV_LIB $OPENCV_LIB_OPTS -o execs/colour2.out
+gcc -I$OPENCV_INC codes/im_colhist.cpp -L$OPENCV_LIB $OPENCV_LIB_OPTS -o execs/colour3.out
+gcc -I$OPENCV_INC codes/im_colhist.cpp -L$OPENCV_LIB $OPENCV_LIB_OPTS -o execs/colhist.out
diff --git a/experiment/simulation/build/analyticstracking.php b/experiment/simulation/build/analyticstracking.php
new file mode 100644
index 0000000..b804dc5
--- /dev/null
+++ b/experiment/simulation/build/analyticstracking.php
@@ -0,0 +1,12 @@
+
+
+
\ No newline at end of file
diff --git a/experiment/simulation/build/assign.php b/experiment/simulation/build/assign.php
new file mode 100644
index 0000000..dc9d9b9
--- /dev/null
+++ b/experiment/simulation/build/assign.php
@@ -0,0 +1,87 @@
+
+
+
+
+
+ Assignment - Virtual Lab in Image Processing
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Obtain the figure of the right from the figure on the left.
+
+

"/>

"/>
+
+
+Click
here to try it out.
+
+
+
+
+
diff --git a/experiment/simulation/build/codes/HIST_backup.cpp b/experiment/simulation/build/codes/HIST_backup.cpp
new file mode 100755
index 0000000..e87d741
--- /dev/null
+++ b/experiment/simulation/build/codes/HIST_backup.cpp
@@ -0,0 +1,194 @@
+#include
+#include
+#include
+#include
+using namespace std;
+
+void create_histogram_image(IplImage* bin_img, IplImage* hist_img,int bins) {
+ CvHistogram *hist;
+
+ int fc = 256/bins;
+ int hist_size = 256/fc;
+ float range[]={0,256/fc};
+ float* ranges[] = { range };
+ float max_value = 0.0;
+ float w_scale = 0.0;
+
+ // create array to hold histogram values
+ hist = cvCreateHist(1, &hist_size, CV_HIST_ARRAY, ranges, 1);
+
+ // calculate histogram values
+ cvCalcHist( &bin_img, hist, 0, NULL );
+
+ // Get the minimum and maximum values of the histogram
+ cvGetMinMaxHistValue( hist, 0, &max_value, 0, 0 );
+
+ // set height by using maximim value
+ cvScale( hist->bins, hist->bins, ((float)hist_img->height)/max_value, 0 );
+
+ // calculate width
+ w_scale = ((float)hist_img->width)/hist_size;
+
+ // plot the histogram
+ for( int i = 0; i < hist_size; i++ ) {
+
+ cvRectangle( hist_img, cvPoint((int)i*w_scale , hist_img->height),
+ cvPoint((int)(i+1)*w_scale, hist_img->height - cvRound(cvGetReal1D(hist->bins,i))),
+ cvScalar(0), -1, 8, 0 );
+
+ }
+}
+IplImage* Pre_Process(IplImage* src,int bins)
+{
+ int c = cvGetSize(src).width;
+ int r = cvGetSize(src).height;
+
+ IplImage* final_img=cvCreateImage(cvSize(src->width,src->height),src->depth,src->nChannels);
+ cvZero(final_img);
+ for(int i=0;iwidth, source->height ), IPL_DEPTH_8U, 1 );
+ if(nbins!=256)
+ bin_img = Pre_Process(source,nbins);
+ else
+ bin_img = cvCloneImage(source);
+
+ int c = cvGetSize(bin_img).width;
+ int r = cvGetSize(bin_img).height;
+
+ IplImage *bin_img1 = cvCreateImage(cvSize( source->width/2, source->height/2 ), IPL_DEPTH_8U, 1 );
+ int mn4=300,mx4=-1,avg4=0;
+ for(int i=0;i mx4)
+ mx4 = s.val[0];
+ avg4+=s.val[0];
+ cvSet2D(bin_img1,i,j,s);
+ }
+ }
+ avg4 = 4*avg4/(r*c);
+
+ IplImage *hist_img = cvCreateImage(cvSize(300,300), 8, 1);
+ cvSet( hist_img, cvScalarAll(255), 0 );
+ create_histogram_image(bin_img1, hist_img,nbins);
+ char nam[30];
+ int n = sprintf(nam,"%s_1.%s",img_nm,img_typ);
+ cvSaveImage(nam,hist_img);
+
+ IplImage *bin_img2 = cvCreateImage(cvSize( source->width/2, source->height/2 ), IPL_DEPTH_8U, 1 );
+ int mn1=300,mx1=-1,avg1=0;
+ for(int i=0;i mx1)
+ mx1 = s.val[0];
+ avg1+=s.val[0];
+ cvSet2D(bin_img2,i,j-c/2,s);
+ }
+ }
+ avg1 = 4*avg1/(r*c);
+
+ hist_img = cvCreateImage(cvSize(300,300), 8, 1);
+ cvSet( hist_img, cvScalarAll(255), 0 );
+ create_histogram_image(bin_img2, hist_img,nbins);
+ n = sprintf(nam,"%s_2.%s",img_nm,img_typ);
+ cvSaveImage(nam,hist_img);
+
+ IplImage *bin_img3 = cvCreateImage(cvSize( source->width/2, source->height/2 ), IPL_DEPTH_8U, 1 );
+ int mn2=300,mx2=-1,avg2=0;
+ for(int i=r/2;i mx2)
+ mx2 = s.val[0];
+ avg2+=s.val[0];
+ cvSet2D(bin_img3,i-r/2,j,s);
+ }
+ }
+ avg2 = 4*avg2/(r*c);
+
+ hist_img = cvCreateImage(cvSize(300,300), 8, 1);
+ cvSet( hist_img, cvScalarAll(255), 0 );
+ create_histogram_image(bin_img3, hist_img,nbins);
+ n = sprintf(nam,"%s_3.%s",img_nm,img_typ);
+ cvSaveImage(nam,hist_img);
+
+
+ IplImage *bin_img4 = cvCreateImage(cvSize( source->width/2, source->height/2 ), IPL_DEPTH_8U, 1 );
+ int mn3=300,mx3=-1,avg3=0;
+ for(int i=r/2;i mx3)
+ mx3 = s.val[0];
+ avg3+=s.val[0];
+ cvSet2D(bin_img4,i-r/2,j-c/2,s);
+ }
+ }
+ avg3 = 4*avg3/(r*c);
+
+ hist_img = cvCreateImage(cvSize(300,300), 8, 1);
+ cvSet( hist_img, cvScalarAll(255), 0 );
+ create_histogram_image(bin_img4, hist_img,nbins);
+ n = sprintf(nam,"%s_4.%s",img_nm,img_typ);
+ cvSaveImage(nam,hist_img);
+
+ cvReleaseImage( &source );
+ cvReleaseImage( &hist_img );
+ cvReleaseImage( &bin_img );
+ cvReleaseImage( &bin_img1 );
+ cvReleaseImage( &bin_img2 );
+ cvReleaseImage( &bin_img3 );
+ cvReleaseImage( &bin_img4 );
+
+ cout<
+#include
+#include
+#include
+#include
+#include
+#include
+
+using namespace std;
+
+IplImage* imPATH(IplImage *img,int xs,int ys,int xd,int yd,int con)
+{
+ int c = cvGetSize(img).width;
+ int r = cvGetSize(img).height;
+
+ IplImage* final_img=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,3);
+ cvMerge(img,img,img,NULL,final_img);
+
+ int dst[r][c];
+ int srcx[r][c];
+ int srcy[r][c];
+ for(int i=0;i X;
+ queue Y;
+ srcx[xs][ys]=xs;
+ srcy[xs][ys]=ys;
+ X.push(xs);
+ Y.push(ys);
+ dst[xs][ys]=0;
+ int pth_found=0;
+
+ int xp,yp;
+ while(!X.empty())
+ {
+ xp = X.front();
+ yp = Y.front();
+/* cout<<"last "<=0)
+ s1 = cvGet2D(img,xp-1,yp);
+ if(con==8 and (xp -1 >= 0) and (yp+1 =0))
+ s7 = cvGet2D(img,xp+1,yp-1);
+
+ if(yp-1 >=0)
+ s4 = cvGet2D(img,xp,yp-1);
+ if(con==8 and (xp-1 >=0) and (yp-1 >=0))
+ s8 = cvGet2D(img,xp-1,yp-1);
+
+ if(s1.val[0] > 0)
+ {
+ if(dst[xp-1][yp] > dst[xp][yp] + 1)
+ {
+ dst[xp-1][yp]=dst[xp][yp]+1;
+ srcx[xp-1][yp]=xp;
+ srcy[xp-1][yp]=yp;
+ X.push(xp-1);
+ Y.push(yp);
+ }
+ }
+
+ if(s5.val[0] > 0)
+ {
+ if(dst[xp-1][yp+1] > dst[xp][yp] + 1)
+ {
+ dst[xp-1][yp+1]=dst[xp][yp]+1;
+ srcx[xp-1][yp+1]=xp;
+ srcy[xp-1][yp+1]=yp;
+ X.push(xp-1);
+ Y.push(yp+1);
+ }
+ }
+
+ if(s2.val[0] > 0)
+ {
+ if(dst[xp][yp+1] > dst[xp][yp] + 1)
+ {
+ dst[xp][yp+1]=dst[xp][yp]+1;
+ srcx[xp][yp+1]=xp;
+ srcy[xp][yp+1]=yp;
+ X.push(xp);
+ Y.push(yp+1);
+ }
+ }
+
+ if(s6.val[0] > 0)
+ {
+ if(dst[xp+1][yp+1] > dst[xp][yp] + 1)
+ {
+ dst[xp+1][yp+1]=dst[xp][yp]+1;
+ srcx[xp+1][yp+1]=xp;
+ srcy[xp+1][yp+1]=yp;
+ X.push(xp+1);
+ Y.push(yp+1);
+ }
+ }
+
+ if(s3.val[0] > 0)
+ {
+ if(dst[xp+1][yp] > dst[xp][yp] + 1)
+ {
+ dst[xp+1][yp]=dst[xp][yp]+1;
+ srcx[xp+1][yp]=xp;
+ srcy[xp+1][yp]=yp;
+ X.push(xp+1);
+ Y.push(yp);
+ }
+ }
+
+ if(s7.val[0] > 0)
+ {
+ if(dst[xp+1][yp-1] > dst[xp][yp] + 1)
+ {
+ dst[xp+1][yp-1]=dst[xp][yp]+1;
+ srcx[xp+1][yp-1]=xp;
+ srcy[xp+1][yp-1]=yp;
+ X.push(xp+1);
+ Y.push(yp-1);
+ }
+ }
+
+ if(s4.val[0] > 0)
+ {
+ if(dst[xp][yp-1] > dst[xp][yp] + 1)
+ {
+ dst[xp][yp-1]=dst[xp][yp]+1;
+ srcx[xp][yp-1]=xp;
+ srcy[xp][yp-1]=yp;
+ X.push(xp);
+ Y.push(yp-1);
+ }
+ }
+
+ if(s8.val[0] > 0)
+ {
+ if(dst[xp-1][yp-1] > dst[xp][yp] + 1)
+ {
+ dst[xp-1][yp-1]=dst[xp][yp]+1;
+ srcx[xp-1][yp-1]=xp;
+ srcy[xp-1][yp-1]=yp;
+ X.push(xp-1);
+ Y.push(yp-1);
+ }
+ }
+ }
+
+ int tx=xd,ty=yd;
+ if(!pth_found)
+ {
+// cout<<"path not found\n";
+ tx = xp;
+ ty = yp;
+// cout<<"point "<0 and sd.val[0]>0)
+ {
+ // cout<<"here :S \n";
+ IplImage* path_img=cvCreateImage(cvSize(c1,r1),IPL_DEPTH_8U,3);
+ path_img=imPATH(img1,xs,ys,xd,yd,con);
+ cvSaveImage(argv[2],path_img);
+ cvReleaseImage( &path_img );
+ }
+ cvReleaseImage( &img1 );
+ return 0;
+}
diff --git a/experiment/simulation/build/codes/coladaptivehist.sh b/experiment/simulation/build/codes/coladaptivehist.sh
new file mode 100755
index 0000000..5d4956c
--- /dev/null
+++ b/experiment/simulation/build/codes/coladaptivehist.sh
@@ -0,0 +1,4 @@
+ gcc -I/home/intel/opencv/include/opencv -L/home/intel/opencv/lib -lcv -lhighgui -lstdc++ -o coladaptivehist.out im_coladaptivehist.cpp
+./coladaptivehist.out colimg.jpg cimg.jpg 7 7 2 2
+#display cimg.jpg &
+#display colimg.jpg &
diff --git a/experiment/simulation/build/codes/colcon.out b/experiment/simulation/build/codes/colcon.out
new file mode 100755
index 0000000..05ce43c
Binary files /dev/null and b/experiment/simulation/build/codes/colcon.out differ
diff --git a/experiment/simulation/build/codes/colhist.out b/experiment/simulation/build/codes/colhist.out
new file mode 100755
index 0000000..1fb1b1d
Binary files /dev/null and b/experiment/simulation/build/codes/colhist.out differ
diff --git a/experiment/simulation/build/codes/colhist.sh b/experiment/simulation/build/codes/colhist.sh
new file mode 100755
index 0000000..ec7e27d
--- /dev/null
+++ b/experiment/simulation/build/codes/colhist.sh
@@ -0,0 +1,7 @@
+ gcc -I/home/intel/opencv/include/opencv -L/home/intel/opencv/lib -lcv -lhighgui -lstdc++ -o colhist.out im_colhist.cpp
+#./colhist.out colimg.jpg cimg.jpg 2 2
+#display cimg.jpg &
+#display colimg.jpg &
+#display p1.jpg &
+#display p2.jpg &
+#display p3.jpg &
diff --git a/experiment/simulation/build/codes/color.out b/experiment/simulation/build/codes/color.out
new file mode 100755
index 0000000..df1b988
Binary files /dev/null and b/experiment/simulation/build/codes/color.out differ
diff --git a/experiment/simulation/build/codes/color.sh b/experiment/simulation/build/codes/color.sh
new file mode 100755
index 0000000..35439bd
--- /dev/null
+++ b/experiment/simulation/build/codes/color.sh
@@ -0,0 +1,11 @@
+# gcc -I/home/intel/opencv/include/opencv -L/home/intel/opencv/lib -lcv -lhighgui -lstdc++ -o color.out im_color.cpp
+#./color.out colimg.jpg cimg.jpg 2
+gcc -I/home/intel/opencv/include/opencv -L/home/intel/opencv/lib -lcv -lhighgui -lstdc++ -o colcon.out im_colcon.cpp
+
+
+
+#display cimg.jpg &
+#display colimg.jpg &
+#display p1.jpg &
+#display p2.jpg &
+#display p3.jpg &
diff --git a/experiment/simulation/build/codes/colour.sh b/experiment/simulation/build/codes/colour.sh
new file mode 100755
index 0000000..329deea
--- /dev/null
+++ b/experiment/simulation/build/codes/colour.sh
@@ -0,0 +1,3 @@
+ gcc -I/home/intel/opencv/include/opencv -L/home/intel/opencv/lib -lcv -lhighgui -lstdc++ -o colour.out im_colour.cpp
+# gcc -I/home/intel/opencv/include/opencv -L/home/intel/opencv/lib -lcv -lhighgui -lstdc++ -o colour2.out im_colourLin.cpp
+# gcc -I/home/intel/opencv/include/opencv -L/home/intel/opencv/lib -lcv -lhighgui -lstdc++ -o colour3.out im_colhist.cpp
\ No newline at end of file
diff --git a/experiment/simulation/build/codes/colour2.out b/experiment/simulation/build/codes/colour2.out
new file mode 100755
index 0000000..de84a02
Binary files /dev/null and b/experiment/simulation/build/codes/colour2.out differ
diff --git a/experiment/simulation/build/codes/colpoint.out b/experiment/simulation/build/codes/colpoint.out
new file mode 100755
index 0000000..48dad59
Binary files /dev/null and b/experiment/simulation/build/codes/colpoint.out differ
diff --git a/experiment/simulation/build/codes/colpoint.sh b/experiment/simulation/build/codes/colpoint.sh
new file mode 100755
index 0000000..7875019
--- /dev/null
+++ b/experiment/simulation/build/codes/colpoint.sh
@@ -0,0 +1,4 @@
+ gcc -I/home/intel/opencv/include/opencv -L/home/intel/opencv/lib -lcv -lhighgui -lstdc++ -o colpoint.out im_colourLin.cpp
+./colpoint.out colimg.jpg cimg.jpg 1 100 150 1
+#display colimg.jpg
+#display cimg.jpg
diff --git a/experiment/simulation/build/codes/colunsharp.sh b/experiment/simulation/build/codes/colunsharp.sh
new file mode 100755
index 0000000..71125e9
--- /dev/null
+++ b/experiment/simulation/build/codes/colunsharp.sh
@@ -0,0 +1,6 @@
+ gcc -I/home/intel/opencv/include/opencv -L/home/intel/opencv/lib -lcv -lhighgui -lstdc++ -o unsharp.out im_unsharpmasking.cpp
+ ./unsharp.out desert.jpg UnsharpMasking.jpg
+display desert.jpg &
+#display smoothened.jpg &
+#display subtracted.jpg &
+display UnsharpMasking.jpg &
diff --git a/experiment/simulation/build/codes/dist.sh b/experiment/simulation/build/codes/dist.sh
new file mode 100755
index 0000000..b84d3fb
--- /dev/null
+++ b/experiment/simulation/build/codes/dist.sh
@@ -0,0 +1,2 @@
+ gcc -I/home/intel/opencv/include/opencv -L/home/intel/opencv/lib -lcv -lhighgui -lstdc++ -o dist.out im_dist.cpp
+mv dist.out ../execs/
diff --git a/experiment/simulation/build/codes/fourier.sh b/experiment/simulation/build/codes/fourier.sh
new file mode 100755
index 0000000..847463d
--- /dev/null
+++ b/experiment/simulation/build/codes/fourier.sh
@@ -0,0 +1,2 @@
+ gcc -I/usr/local/include/opencv -L/usr/local/lib -lcv -lhighgui -lstdc++ -o fourier.out im_fourier.cpp
+mv fourier.out ../execs/
\ No newline at end of file
diff --git a/experiment/simulation/build/codes/fourier_backup.cpp b/experiment/simulation/build/codes/fourier_backup.cpp
new file mode 100755
index 0000000..1034cf2
--- /dev/null
+++ b/experiment/simulation/build/codes/fourier_backup.cpp
@@ -0,0 +1,42 @@
+#include
+#include
+#include
+#include
+using namespace std;
+
+int main( int argc, char** argv )
+
+{
+ IplImage *source = cvLoadImage(argv[1],0);
+
+ cout<<"done this";
+
+ IplImage *bin_img = cvCreateImage(cvSize( source->width, source->height ), CV_64FC1, 1 );
+ bin_img = cvCloneImage(source);
+
+ int c = cvGetSize(bin_img).width;
+ int r = cvGetSize(bin_img).height;
+
+
+
+ if(1)
+ {
+ IplImage *four_img = cvCreateImage(cvSize( source->width, source->height ),CV_64FC1,2);
+ cvDFT( bin_img, four_img, CV_DXT_FORWARD, 0);
+ IplImage *ioutRe = cvCreateImage(cvSize( source->width, source->height ),CV_64FC1, 1);
+ IplImage *ioutIm = cvCreateImage(cvSize( source->width, source->height ),CV_64FC1, 1);
+ cvSplit(four_img, ioutRe, ioutIm, NULL, NULL);
+ cvSaveImage(argv[2],ioutRe);
+ cvSaveImage(argv[3],ioutIm);
+ cvReleaseImage( &ioutIm );
+ cvReleaseImage( &ioutRe );
+ cvReleaseImage( &source );
+ cvReleaseImage( &four_img );
+ cvReleaseImage( &bin_img );
+
+
+
+ }
+
+ return 0;
+}
diff --git a/experiment/simulation/build/codes/hist.sh b/experiment/simulation/build/codes/hist.sh
new file mode 100755
index 0000000..713fc90
--- /dev/null
+++ b/experiment/simulation/build/codes/hist.sh
@@ -0,0 +1,4 @@
+ gcc -I/usr/local/include/opencv -L/usr/local/lib -lcv -lhighgui -lstdc++ -o hist.out im_hist.cpp
+# display stock1.jpg
+#./hist.out
+#display hist_1.jpg
diff --git a/experiment/simulation/build/codes/im_advfourier.cpp b/experiment/simulation/build/codes/im_advfourier.cpp
new file mode 100644
index 0000000..2874a0d
--- /dev/null
+++ b/experiment/simulation/build/codes/im_advfourier.cpp
@@ -0,0 +1,128 @@
+#include
+#include
+#include
+#include
+#include
+
+using namespace std;
+
+#define PI 3.1428571
+#define MAXI 999999999
+
+int main(int argc, char ** argv)
+{
+ IplImage * im = cvLoadImage(argv[1],0);
+ IplImage * realInput = cvCreateImage( cvGetSize(im), IPL_DEPTH_64F, 1);
+ IplImage * imaginaryInput = cvCreateImage( cvGetSize(im), IPL_DEPTH_64F, 1);
+ IplImage * complexInput = cvCreateImage( cvGetSize(im), IPL_DEPTH_64F, 2);
+ CvMat* dft_A, tmp;
+ int theta = atoi(argv[2]);
+ int rad = atoi(argv[3]);
+ int deltheta = atoi(argv[4]);
+ int delrad = atoi(argv[5]);
+ double angle1 = theta-(deltheta/2);
+ double angle2 = theta+(deltheta/2);
+ double angle3 = 180+theta-(deltheta/2);
+ double angle4 = 180+theta+(deltheta/2);
+ double val1 = atan((angle1==90||angle1==270||angle1==-90||angle1==-270)?MAXI:tan(PI/180*angle1));
+ double val2 = atan((angle1==90||angle1==270||angle1==-90||angle1==-270)?MAXI:tan(PI/180*angle2));
+ double val3 = atan((angle1==90||angle1==270||angle1==-90||angle1==-270)?MAXI:tan(PI/180*angle3));
+ double val4 = atan((angle1==90||angle1==270||angle1==-90||angle1==-270)?MAXI:tan(PI/180*angle4));
+
+ int dft_M, dft_N;
+ cvScale(im, realInput, 1.0, 0.0);
+ cvZero(imaginaryInput);
+ cvMerge(realInput, imaginaryInput, NULL, NULL, complexInput);
+ dft_M = cvGetOptimalDFTSize( im->height - 1 );
+ dft_N = cvGetOptimalDFTSize( im->width - 1 );
+ dft_A = cvCreateMat( dft_M, dft_N, CV_64FC2 );
+ cvGetSubRect( dft_A, &tmp, cvRect(0,0, im->width, im->height));
+ cvCopy( complexInput, &tmp, NULL );
+ if( dft_A->cols > im->width )
+ {
+ cvGetSubRect( dft_A, &tmp, cvRect(im->width,0, dft_A->cols -
+ im->width, im->height));
+ cvZero( &tmp );
+ }
+ cvDFT( dft_A, dft_A, CV_DXT_FORWARD, complexInput->height );
+ IplImage * re = cvCreateImage(cvSize(dft_N,dft_M),IPL_DEPTH_64F,1);
+ IplImage * imag = cvCreateImage(cvSize(dft_N,dft_M),IPL_DEPTH_64F,1);
+ cvSplit(dft_A,re,imag,0,0);
+
+ int r = cvGetSize(imag).height;
+ int c = cvGetSize(imag).width;
+ double dist,row,col,val;
+ CvScalar s;
+ for (int i=0;i=val2 && (val>=val1||val<=val2)) || (val3>=val4 && (val>=val3||val<=val4)))
+ {
+ s.val[0]=0.0;
+ cvSet2D(imag,i,j,s);
+ }
+ else if ((val>=val1 && val<=val2) || (val>=val3 && val<=val4))
+ {
+ s.val[0]=0.0;
+ cvSet2D(imag,i,j,s);
+ }
+ }
+ }
+ }
+ }
+
+ cvNamedWindow("imaginary",0);
+ cvShowImage("imaginary",imag);
+
+ cvMerge(re,imag,NULL,NULL,dft_A);
+ cvDFT( dft_A, dft_A, CV_DXT_INVERSE_SCALE, dft_N);
+ cvScale(dft_A,dft_A,0.001);
+ cvSplit(dft_A,re,imag,0,0);
+ cvPow(re,re,2);
+ cvPow(imag,imag,2);
+ cvAdd(re,imag,re,NULL);
+ cvPow(re,re,0.5);
+ cvAddS( re, cvScalarAll(1.0), re, NULL ); // 1 + Mag
+ cvLog( re, re); // log(1 + Mag)
+ double m,M;
+ cvMinMaxLoc(re, &m, &M, NULL, NULL, NULL);
+ cvScale(re, re, 1.0/(M-m), 1.0*(-m)/(M-m));
+ IplImage * Output = cvCreateImage(cvGetSize(re),IPL_DEPTH_8U,1);
+ CvPoint minLoc, maxLoc;
+ double minVal = 0; double maxVal = 0;
+ cvMinMaxLoc(re, &minVal, &maxVal, &minLoc, &maxLoc, 0);
+ cvCvtScaleAbs(re,Output,255.0*(maxVal-minVal),0);
+ cvSaveImage("advfourier.jpg",Output);
+
+ cvNamedWindow("advfourier",0);
+ cvShowImage("advfourier",Output);
+
+ cvWaitKey(-1);
+
+ cvReleaseImage(&im);
+ cvReleaseImage(&realInput);
+ cvReleaseImage(&imaginaryInput);
+ cvReleaseImage(&complexInput);
+ cvReleaseImage(&re);
+ cvReleaseImage(&imag);
+ cvReleaseMat(&dft_A);
+ cvReleaseImage(&Output);
+ return 0;
+}
diff --git a/experiment/simulation/build/codes/im_affine.cpp b/experiment/simulation/build/codes/im_affine.cpp
new file mode 100755
index 0000000..e8f4732
--- /dev/null
+++ b/experiment/simulation/build/codes/im_affine.cpp
@@ -0,0 +1,128 @@
+#include
+#include
+#include
+#include
+
+using namespace std;
+
+IplImage *imtranslate(IplImage *src,int tx,int ty)
+{
+ IplImage *tmp=cvCreateImage(cvSize(src->width,src->height),IPL_DEPTH_8U,1);
+/* if(tx==0 and ty==0)
+ {
+ tmp= cvCloneImage(src);
+ return tmp;
+ }
+*/
+ for(int i=0;i< src->height-1-ty;i++)
+ {
+ for(int j=0;jwidth-1-tx;j++)
+ {
+ CvScalar s1;
+ s1= cvGet2D(src,i,j);
+ cvSet2D(tmp,i+ty,j+tx,s1);
+ }
+
+ }
+ return tmp;
+
+}
+
+IplImage *imscale_rotate(IplImage *src,float angl,float scale,int flag)
+{
+ CvPoint2D32f srcTri[3], dstTri[3];
+ CvMat* rot_mat = cvCreateMat(2,3,CV_32FC1);
+ CvMat* warp_mat = cvCreateMat(2,3,CV_32FC1);
+ IplImage *dst;
+ dst = cvCloneImage( src );
+
+ srcTri[0].x = 0;
+ srcTri[0].y = 0;
+ srcTri[1].x = src->width - 1;
+ srcTri[1].y = 0;
+ srcTri[2].x = 0;
+ srcTri[2].y = src->height - 1;
+
+ dstTri[0].x = 0;
+ dstTri[0].y = 0;
+ dstTri[1].x = src->width - 1;
+ dstTri[1].y = 0;
+ dstTri[2].x = 0;
+ dstTri[2].y = src->height - 1;
+
+ cvGetAffineTransform( srcTri, dstTri, warp_mat );
+ cvWarpAffine( src, dst, warp_mat,flag);
+ cvCopy ( dst, src );
+
+
+ // Compute rotation matrix
+ CvPoint2D32f center = cvPoint2D32f( src->width/2, src->height/2 );
+ cv2DRotationMatrix( center, angl, scale, rot_mat );
+
+ // Do the transformation
+ cvWarpAffine( src, dst, rot_mat );
+ return dst;
+}
+
+int main(int argc,char* argv[])
+{
+ // Set up variables
+
+ IplImage *src, *dst;
+
+ // Load image
+ src=cvLoadImage(argv[1]);
+
+
+
+ char *img_nm,*img_typ;
+ img_nm = strtok (argv[2],".");
+ img_typ = strtok (NULL, ".");
+
+ // get angle of rotation, translation(%) and scale value for the transformation
+
+ float angl;
+ int tx,ty;
+ float scale;
+
+ angl = atof(argv[3]);
+ tx = atoi(argv[4]);
+ ty = atoi(argv[5]);
+ scale = atof(argv[6]);
+ scale = pow(2,scale);
+/*
+ cvNamedWindow( name, 1 );
+ cvShowImage( name,src);
+ cvWaitKey(0);
+ return 0;
+*/
+ int flag[3];
+ flag[0] = CV_INTER_NN+CV_WARP_FILL_OUTLIERS;
+ flag[1] = CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS;
+ flag[2] = CV_INTER_CUBIC+CV_WARP_FILL_OUTLIERS;
+
+
+ for(int i = 0;i<3;i++)
+ {
+ dst = cvCloneImage( src );
+// tmp=cvCreateImage(cvSize(src->width,src->height),IPL_DEPTH_8U,1);
+ dst->origin = src->origin;
+ cvZero( dst );
+ if(tx==0 and ty==0)
+ dst = imscale_rotate(src,angl,scale,flag[i]);
+ else
+ dst = imtranslate(src,tx,ty);
+// src = cvCloneImage(tmp);
+
+ char nm[50];
+ int n = sprintf(nm,"%s%d.%s",img_nm,i+1,img_typ);
+ cvSaveImage(nm,dst);
+ }
+
+ cvReleaseImage( &src );
+// cvReleaseImage( &tmp );
+ cvReleaseImage( &dst );
+
+ return 0;
+}
+
diff --git a/experiment/simulation/build/codes/im_arith.cpp b/experiment/simulation/build/codes/im_arith.cpp
new file mode 100755
index 0000000..2b8cdc2
--- /dev/null
+++ b/experiment/simulation/build/codes/im_arith.cpp
@@ -0,0 +1,425 @@
+#include
+#include
+#include
+#include
+#include
+#include
+
+using namespace std;
+
+IplImage* imADD(IplImage *img1,IplImage *img2,int map_fn)
+{
+ int c = cvGetSize(img1).width;
+ int r = cvGetSize(img1).height;
+
+ IplImage* final_img=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+ if(map_fn==1)
+ {
+ for(int i=0;i 255)
+ grval=255;
+ s.val[0] = grval;
+ cvSet2D(final_img,i,j,s);
+ }
+ }
+
+ }
+ else if(map_fn==2)
+ {
+ int min_val=100000;
+ int max_val=-300;
+
+ for(int i=0;i max_val)
+ max_val = grval;
+ if(grval < min_val)
+ min_val = grval;
+ }
+ }
+ for(int i=0;i max_val)
+ max_val = grval;
+ if(grval < min_val)
+ min_val = grval;
+ }
+ }
+ for(int i=0;i max_val)
+ max_val = grval;
+ if(grval < min_val)
+ min_val = grval;
+ }
+ }
+ for(int i=0;i 255)
+ grval=255;
+ s.val[0] = grval;
+ cvSet2D(final_img,i,j,s);
+ }
+ }
+
+ }
+ else if(map_fn==2)
+ {
+ int min_val=100000;
+ int max_val=-300;
+
+ for(int i=0;i max_val)
+ max_val = grval;
+ if(grval < min_val)
+ min_val = grval;
+ }
+ }
+ for(int i=0;i 255.0)
+ grval=255;
+ s.val[0] = (int)(grval);
+ cvSet2D(final_img,i,j,s);
+ }
+ }
+
+ }
+ else if(map_fn==2)
+ {
+ double min_val=1000000;
+ double max_val=-300;
+
+ for(int i=0;i max_val)
+ max_val = grval;
+ if(grval < min_val)
+ min_val = grval;
+ }
+ }
+// cout<
+#include
+#include
+#include
+#include
+#include
+
+using namespace std;
+
+IplImage* adapthist(IplImage* pln, int arg3, int arg4)
+{
+ int c=cvGetSize(pln).width;
+ int r=cvGetSize(pln).height;
+
+ IplImage *p4=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+
+ CvScalar s,s1;
+ int cdf[256]={0};
+ int hst[256]={0};
+ int count;
+ for (int i=0;i "< input should be 1 or 2 or 3
+// and argv[6] tells which color model to select --> input should be "1" for RGB, "2" for HSV, and "3" for CMY
+
+int main(int argc, char* argv[])
+{
+ IplImage *source=cvLoadImage(argv[1],1);
+
+ int c=cvGetSize(source).width;
+ int r=cvGetSize(source).height;
+
+ IplImage* final_img=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,3);
+ IplImage* out_img=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,3);
+ IplImage *p1=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+ IplImage *p2=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+ IplImage *p3=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+ IplImage *p4=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+ IplImage *p5=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+ IplImage *p6=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+
+ if (atoi(argv[6])==1)
+ {
+ CvScalar s,t;
+ t.val[0]=0;
+ t.val[1]=0;
+ t.val[2]=0;
+ for (int i=0;i
+#include
+#include
+#include
+#include
+#include
+
+using namespace std;
+
+
+
+int main(int argc, char* argv[])
+{
+ IplImage *source=cvLoadImage(argv[1],1);
+
+
+ int c=cvGetSize(source).width;
+ int r=cvGetSize(source).height;
+ IplImage *p1=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+ IplImage *p2=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+ IplImage *p3=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+ IplImage* out_img=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,3);
+
+ CvScalar s,t;
+ t.val[0]=0;
+ t.val[1]=0;
+ t.val[2]=0;
+ for (int i=0;i
+#include
+#include
+#include
+#include
+#include
+
+using namespace std;
+
+IplImage* adapthist(IplImage* pln, int arg3, int arg4)
+{
+ int c=cvGetSize(pln).width;
+ int r=cvGetSize(pln).height;
+
+ IplImage *p4=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+
+
+ IplImage *temp=cvCreateImage(cvSize(arg3,arg4),IPL_DEPTH_8U,1);
+
+ CvScalar s;
+ for (int ii=0;ii=x)?0:x); ii=y)?0:y); jj input should be 1 or 2 or 3
+// and argv[4] tells which color model to select --> input should be "1" for RGB, "2" for HSV, and "3" for CMY
+// argv[6] and argv[7] tell the kernel size -> LXB
+
+int main(int argc, char* argv[])
+{
+ IplImage *source=cvLoadImage(argv[1],1);
+
+ int c=cvGetSize(source).width;
+ int r=cvGetSize(source).height;
+
+ IplImage* final_img=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,3);
+ IplImage* out_img=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,3);
+ IplImage *p1=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+ IplImage *p2=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+ IplImage *p3=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+ IplImage *p4=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+ IplImage *p5=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+ IplImage *p6=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+
+ if (atoi(argv[4])==1)
+ {
+ CvScalar s,t;
+ t.val[0]=0;
+ t.val[1]=0;
+ t.val[2]=0;
+ for (int i=0;i
+#include
+#include
+#include
+#include
+#include
+
+using namespace std;
+
+
+
+int main(int argc, char* argv[])
+{
+ IplImage *source=cvLoadImage(argv[1],1);
+
+ int c=cvGetSize(source).width;
+ int r=cvGetSize(source).height;
+
+ IplImage* out_img=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,3);
+ IplImage *p1=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+ IplImage *p2=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+ IplImage *p3=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+
+ if(atoi(argv[3])==1)
+ {
+ cout<<"splitting the original image to RGB planes"<
+#include
+#include
+#include
+#include
+#include
+using namespace std;
+int main(int argc, char* argv[])
+{
+ IplImage *source=cvLoadImage(argv[1],1);
+ int c=cvGetSize(source).width;
+ int r=cvGetSize(source).height;
+ IplImage* out_img=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,3);
+ IplImage *p1=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+ IplImage *p2=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+ IplImage *p3=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+ char *img_nm,*img_typ;
+ img_nm = strtok (argv[2],".");
+ img_typ = strtok (NULL, ".");
+ if(atoi(argv[3])==1 || atoi(argv[3])==5)
+ {
+ // converting the RGB image to HSV
+ // cout<<"converting the RGB image to HSV"<
+#include
+#include
+#include
+#include
+#include
+#include
+
+using namespace std;
+
+IplImage* Contrast_Stretch(IplImage *src,float a,float b, int arg)
+{
+ int c = cvGetSize(src).width;
+ int r = cvGetSize(src).height;
+
+ IplImage* final_img=cvCreateImage(cvSize(src->width,src->height),src->depth,src->nChannels);
+ cvZero(final_img);
+
+ for(int i=0;i 255)
+ grval1 = 255;
+ else if(grval1 < 0)
+ grval1 = 0;
+ s.val[0] = grval1;
+ }
+
+ if (arg==2 || arg==3 || arg==6 || arg==7)
+ {
+ int grval2 = (int)(tan(a*3.14/180)*s1.val[1] + b);
+ if(grval2 > 255)
+ grval2 = 255;
+ else if(grval2 < 0)
+ grval2 = 0;
+ s.val[1] = grval2;
+ }
+
+ if (arg==4 || arg==5 || arg==6 || arg==7)
+ {
+ int grval3 = (int)(tan(a*3.14/180)*s1.val[2] + b);
+ if(grval3 > 255)
+ grval3 = 255;
+ else if(grval3 < 0)
+ grval3 = 0;
+ s.val[2] = grval3;
+ }
+
+ cvSet2D(final_img,i,j,s);
+
+ }
+ }
+ return final_img;
+}
+
+// argv[7] will tells on which plane the proc. needs to be done --> input should be 1 or 2 or 3
+// and argv[8] tells which color model to select --> input should be "1" for RGB, "2" for HSV, and "3" for CMY
+
+int main(int argc,char *argv[])
+{
+ int p[3];
+ p[0] = CV_IMWRITE_JPEG_QUALITY;
+ p[1] = 90;
+ p[2] = 0;
+
+ char *img_nm,*img_typ;
+ IplImage* source = cvLoadImage(argv[1],1);
+ IplImage* dst;
+ IplImage* dst1;
+
+ char *pch,*rem,*f_img;
+ pch = strtok (argv[1],"/");
+ while (pch != NULL)
+ {
+ f_img = pch;
+ pch = strtok (NULL, "/");
+
+ }
+
+ img_nm = strtok (f_img,".");
+ img_typ = strtok (NULL, ".");
+ cout<<"hello worldhhhh"<width,src->height),src->depth,src->nChannels);
+ dst1=cvCreateImage(cvSize(src->width,src->height),src->depth,src->nChannels);
+ dst1=Contrast_Stretch(src,a,b,atoi(argv[3]));
+
+
+ cvSplit(dst1,p1,p2,p3,0);
+
+ if (atoi(argv[6])==1)
+ {
+ // processing the image in RGB
+ CvScalar s,t;
+ t.val[0]=0;
+ t.val[1]=0;
+ t.val[2]=0;
+ for (int i=0;i
+#include
+#include
+#include
+#include
+#include
+#include
+
+using namespace std;
+
+
+IplImage* Log_Image(IplImage *src,int cn, int arg)
+{
+ int c = cvGetSize(src).width;
+ int r = cvGetSize(src).height;
+
+ IplImage* final_img=cvCreateImage(cvSize(src->width,src->height),src->depth,src->nChannels);
+ cvZero(final_img);
+ for(int i=0;i 255)
+ grval1= 255;
+ if(grval1 < 0)
+ grval1 = 0;
+ s.val[0] = grval1;
+ }
+
+ if (arg==2 || arg==3 || arg==6 || arg==7)
+ {
+ int grval2 = s1.val[1];
+ grval2 = cn*log10(1 + grval2);
+ if(grval2 > 255)
+ grval2= 255;
+ if(grval2 < 0)
+ grval2 = 0;
+ s.val[1] = grval2;
+ }
+
+ if (arg==4 || arg==5 || arg==6 || arg==7)
+ {
+ int grval3 = s1.val[2];
+ grval3 = cn*log10(1 + grval3);
+ if(grval3 > 255)
+ grval3= 255;
+ if(grval3 < 0)
+ grval3 = 0;
+ s.val[2] = grval3;
+ }
+
+ cvSet2D(final_img,i,j,s);
+ }
+ }
+ return final_img;
+}
+
+IplImage* Contrast_Stretch(IplImage *src,float a,float b, int arg)
+{
+ int c = cvGetSize(src).width;
+ int r = cvGetSize(src).height;
+
+ IplImage* final_img=cvCreateImage(cvSize(src->width,src->height),src->depth,src->nChannels);
+ cvZero(final_img);
+ for(int i=0;i 255)
+ grval1 = 255;
+ else if(grval1 < 0)
+ grval1 = 0;
+ s.val[0] = grval1;
+ }
+
+ if (arg==2 || arg==3 || arg==6 || arg==7)
+ {
+ int grval2 = (int)(tan(a*3.14/180)*s1.val[1] + b);
+ if(grval2 > 255)
+ grval2 = 255;
+ else if(grval2 < 0)
+ grval2 = 0;
+ s.val[1] = grval2;
+ }
+
+ if (arg==4 || arg==5 || arg==6 || arg==7)
+ {
+ int grval3 = (int)(tan(a*3.14/180)*s1.val[2] + b);
+ if(grval3 > 255)
+ grval3 = 255;
+ else if(grval3 < 0)
+ grval3 = 0;
+ s.val[2] = grval3;
+ }
+
+ cvSet2D(final_img,i,j,s);
+
+ }
+ }
+ return final_img;
+}
+
+IplImage* Clipped_Image(IplImage *src,float a,float b,float beta, int arg)
+{
+ int c = cvGetSize(src).width;
+ int r = cvGetSize(src).height;
+
+ IplImage* final_img=cvCreateImage(cvSize(src->width,src->height),src->depth,src->nChannels);
+ cvZero(final_img);
+ for(int i=0;i (int)(b))
+ grval1 = 255;
+ else
+ grval1 = (int)(beta * grval1);
+ if(grval1 > 255)
+ grval1 = 255;
+ s.val[0] = grval1;
+ }
+
+ if (arg==2 || arg==4 || arg==5 || arg==7)
+ {
+ int grval2 = (int)(s1.val[1]);
+ if(grval2 < (int)(a))
+ grval2 = 0;
+ else if(grval2 > (int)(b))
+ grval2 = 255;
+ else
+ grval2 = (int)(beta * grval2);
+ if(grval2 > 255)
+ grval2 = 255;
+ s.val[1] = grval2;
+ }
+
+ if (arg==3 || arg==5 || arg==6 || arg==7)
+ {
+ int grval3 = (int)(s1.val[2]);
+ if(grval3 < (int)(a))
+ grval3 = 0;
+ else if(grval3 > (int)(b))
+ grval3 = 255;
+ else
+ grval3 = (int)(beta * grval3);
+ if(grval3 > 255)
+ grval3 = 255;
+ s.val[2] = grval3;
+ }
+
+ cvSet2D(final_img,i,j,s);
+ }
+ }
+ return final_img;
+}
+
+IplImage* Windowed_Image(IplImage *src,float a,float b,float beta, int arg)
+{
+ int c = cvGetSize(src).width;
+ int r = cvGetSize(src).height;
+
+ IplImage* final_img=cvCreateImage(cvSize(src->width,src->height),src->depth,src->nChannels);
+ cvZero(final_img);
+ for(int i=0;i (int)(b)))
+ grval1 = 0;
+ else
+ grval1 = (int)(beta * grval1);
+ if(grval1 > 255)
+ grval1 = 255;
+ s.val[0] = grval1;
+ }
+
+ if (arg==2 || arg==4 || arg==5 || arg==7)
+ {
+ int grval2 = (int)(s1.val[1]);
+ if((grval2 < (int)(a)) or (grval2 > (int)(b)))
+ grval2 = 0;
+ else
+ grval2 = (int)(beta * grval2);
+ if(grval2 > 255)
+ grval2 = 255;
+ s.val[1] = grval2;
+ }
+
+ if (arg==3 || arg==5 || arg==6 || arg==7)
+ {
+ int grval3 = (int)(s1.val[2]);
+ if((grval3 < (int)(a)) or (grval3 > (int)(b)))
+ grval3 = 0;
+ else
+ grval3 = (int)(beta * grval3);
+ if(grval3 > 255)
+ grval3 = 255;
+ s.val[2] = grval3;
+ }
+
+ cvSet2D(final_img,i,j,s);
+ }
+ }
+ return final_img;
+}
+
+ // argv[7] will tells on which plane the proc. needs to be done --> input should be 1 or 2 or 3
+ // and argv[8] tells which color model to select --> input should be "1" for RGB, "2" for HSV, and "3" for CMY
+
+
+int main(int argc,char *argv[])
+{
+ int p[3];
+ p[0] = CV_IMWRITE_JPEG_QUALITY;
+ p[1] = 90;
+ p[2] = 0;
+
+ char *img_nm,*img_typ;
+ IplImage* src = cvLoadImage(argv[1],1);
+ IplImage* dst;
+
+ char *pch,*rem,*f_img;
+ pch = strtok (argv[1],"/");
+ while (pch != NULL)
+ {
+ f_img = pch;
+ pch = strtok (NULL, "/");
+
+ }
+
+ img_nm = strtok (f_img,".");
+ img_typ = strtok (NULL, ".");
+
+
+// cout<<"2\n";
+ float a,b;
+ a = atof(argv[3]);
+ b = atof(argv[4]);
+ dst=cvCreateImage(cvSize(src->width,src->height),src->depth,src->nChannels);
+ dst=Contrast_Stretch(src,a,b,atoi(argv[5]));
+
+ cvSaveImage(argv[2],dst);
+
+ int c=cvGetSize(src).width;
+ int r=cvGetSize(src).height;
+ IplImage* p1=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+ IplImage* p2=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+ IplImage* p3=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+ cvSplit(src,p1,p2,p3,0);
+ cvSaveImage("p1.jpg",p1);
+ cvSaveImage("p2.jpg",p2);
+ cvSaveImage("p3.jpg",p3);
+ cvSplit(dst,p1,p2,p3,0);
+ cvSaveImage("newp1.jpg",p1);
+ cvSaveImage("newp2.jpg",p2);
+ cvSaveImage("newp3.jpg",p3);
+ cvReleaseImage( &p1 );
+ cvReleaseImage( &p2 );
+ cvReleaseImage( &p3 );
+
+ cvReleaseImage( &src );
+ cvReleaseImage( &dst);
+ return 0;
+}
diff --git a/experiment/simulation/build/codes/im_colunsharpmasking.cpp b/experiment/simulation/build/codes/im_colunsharpmasking.cpp
new file mode 100755
index 0000000..2b39eed
--- /dev/null
+++ b/experiment/simulation/build/codes/im_colunsharpmasking.cpp
@@ -0,0 +1,52 @@
+#include
+#include
+#include
+#include
+#include
+#include
+
+using namespace std;
+
+void UnsharpMasking(IplImage *src, char* out_img)
+{
+ IplImage *UnsharpMaskingImage = cvCreateImage(cvGetSize(src), src->depth, src-> nChannels);
+ IplImage *temp1 = cvCreateImage(cvGetSize(src), src->depth, src-> nChannels);
+ IplImage *temp2 = cvCreateImage(cvGetSize(src), src->depth, src-> nChannels);
+
+ cvSmooth( src, temp1, CV_GAUSSIAN, 27, 27);
+ cvSub( src,temp1, temp2, NULL );
+
+ int c = cvGetSize(src).width;
+ int r = cvGetSize(src).height;
+
+ CvScalar s1;
+
+ for (int i=0;inChannels<
+#include
+#include
+#include
+#include
+#include
+#include
+
+using namespace std;
+int maxi(int a, int b)
+{
+ return a>b?a:b;
+}
+
+IplImage *imCityBlock2(IplImage *img,int x1,int y1)
+{
+ int c = cvGetSize(img).width;
+ int r = cvGetSize(img).height;
+
+ IplImage* final_img=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+
+ float scale;
+ int maxd;
+ maxd = maxi( maxi(x1+y1, x1+abs(y1-c) ), maxi(abs(x1-r)+y1, abs(x1-r)+abs(y1-c)) );
+ scale=255.0/maxd;
+
+ CvScalar s;
+ for (int i=0;i=0 && y2=0)
+ cvSet2D(final_img,x2,y2,s);
+
+ y2=y1-d;
+ // cout<=0 && y2=0)
+ cvSet2D(final_img,x2,y2,s);
+ }
+
+ return final_img;
+}
+
+IplImage *imChessBoard(IplImage *img,int x1,int y1,int dist)
+{
+ int c = cvGetSize(img).width;
+ int r = cvGetSize(img).height;
+
+ IplImage* final_img=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,3);
+ cvMerge(img,img,img,NULL,final_img);
+
+ int x2,y2;
+ CvScalar s;
+
+ s.val[0]=255;
+ cvSet2D(final_img,x1,y1,s);
+ s.val[0]=0;
+
+ s.val[1]=255;
+ for (y2=y1-dist; y2<=y1+dist; y2++)
+ {
+ x2=x1+dist;
+ if (x2=0 && y2=0)
+ cvSet2D(final_img,x2,y2,s);
+
+ x2=x1-dist;
+ if (x2=0 && y2=0)
+ cvSet2D(final_img,x2,y2,s);
+ }
+ for (x2=x1-dist; x2<=x1+dist;x2++)
+ {
+ y2=y1+dist;
+ if (x2=0 && y2=0)
+ cvSet2D(final_img,x2,y2,s);
+
+ y2=y1-dist;
+ if (x2=0 && y2=0)
+ cvSet2D(final_img,x2,y2,s);
+ }
+
+ return final_img;
+}
+
+IplImage* imEuclidean(IplImage *img,int x1,int y1,int dist)
+{
+ int c = cvGetSize(img).width;
+ int r = cvGetSize(img).height;
+
+ IplImage* final_img=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,3);
+ cvMerge(img,img,img,NULL,final_img);
+
+ int x2,y2,d;
+ CvScalar s;
+
+ s.val[0]=255;
+ cvSet2D(final_img,x1,y1,s);
+ s.val[0]=0;
+
+ s.val[1]=255;
+ for (x2=x1-dist; x2<=x1+dist; x2++)
+ {
+ d=(int)sqrt( (dist*dist) - ((x1-x2)*(x1-x2)) );
+ y2=y1+d;
+ if (x2=0 && y2=0)
+ cvSet2D(final_img,x2,y2,s);
+
+ y2=y1-d;
+ if (x2=0 && y2=0)
+ cvSet2D(final_img,x2,y2,s);
+ }
+
+ return final_img;
+}
+
+
+int main(int argc,char* argv[])
+{
+ int choice = atoi (argv[1]) ;
+
+ if(choice==1) {
+ int x1 = atoi(argv[2]);
+ int y1 = atoi(argv[3]);
+ int x2 = atoi(argv[4]);
+ int y2 = atoi(argv[5]);
+ if(atoi(argv[6])==1)
+ {
+ // city block
+
+ cout<
+#include
+//#include "stdafx.h"
+#include
+#include
+#include
+
+#define PI 3.1428571
+#define MAXI 999999999
+
+// Rearrange the quadrants of Fourier image so that the origin is at
+// the image center
+// src & dst arrays of equal size & type
+void cvShiftDFT(CvArr * src_arr, CvArr * dst_arr )
+{
+ CvMat * tmp;
+ CvMat q1stub, q2stub;
+ CvMat q3stub, q4stub;
+ CvMat d1stub, d2stub;
+ CvMat d3stub, d4stub;
+ CvMat * q1, * q2, * q3, * q4;
+ CvMat * d1, * d2, * d3, * d4;
+
+ CvSize size = cvGetSize(src_arr);
+ CvSize dst_size = cvGetSize(dst_arr);
+ int cx, cy;
+
+ if(src_arr==dst_arr){
+ tmp = cvCreateMat(size.height/2, size.width/2,
+ cvGetElemType(src_arr));
+ }
+
+ cx = size.width/2;
+ cy = size.height/2; // image center
+
+ q1 = cvGetSubRect( src_arr, &q1stub, cvRect(0,0,cx, cy) );
+ q2 = cvGetSubRect( src_arr, &q2stub, cvRect(cx,0,cx,cy) );
+ q3 = cvGetSubRect( src_arr, &q3stub, cvRect(cx,cy,cx,cy) );
+ q4 = cvGetSubRect( src_arr, &q4stub, cvRect(0,cy,cx,cy) );
+ d1 = cvGetSubRect( src_arr, &d1stub, cvRect(0,0,cx,cy) );
+ d2 = cvGetSubRect( src_arr, &d2stub, cvRect(cx,0,cx,cy) );
+ d3 = cvGetSubRect( src_arr, &d3stub, cvRect(cx,cy,cx,cy) );
+ d4 = cvGetSubRect( src_arr, &d4stub, cvRect(0,cy,cx,cy) );
+
+ if(src_arr!=dst_arr){
+ cvCopy(q3, d1, 0);
+ cvCopy(q4, d2, 0);
+ cvCopy(q1, d3, 0);
+ cvCopy(q2, d4, 0);
+ }
+ else{
+ cvCopy(q3, tmp, 0);
+ cvCopy(q1, q3, 0);
+ cvCopy(tmp, q1, 0);
+ cvCopy(q4, tmp, 0);
+ cvCopy(q2, q4, 0);
+ cvCopy(tmp, q2, 0);
+ }
+}
+
+int main(int argc, char ** argv)
+{
+ if(atoi(argv[1])==1)
+ {
+ IplImage * im;
+ IplImage * im1;
+ IplImage * realInput;
+ IplImage * imaginaryInput;
+ IplImage * complexInput;
+
+ int dft_M, dft_N;
+ CvMat* dft_A, tmp;
+ IplImage * image_Re;
+ IplImage * image_Im;
+ IplImage * image_Re2;
+ IplImage * image_Im2;
+ double m, M;
+
+ im1 = cvLoadImage( argv[2],0 );
+ im = cvLoadImage( argv[2], CV_LOAD_IMAGE_GRAYSCALE );
+ if( !im )
+ return -1;
+
+ realInput = cvCreateImage( cvGetSize(im), IPL_DEPTH_64F, 1);
+ imaginaryInput = cvCreateImage( cvGetSize(im), IPL_DEPTH_64F, 1);
+ complexInput = cvCreateImage( cvGetSize(im), IPL_DEPTH_64F, 2);
+
+ cvScale(im, realInput, 1.0, 0.0);
+ cvZero(imaginaryInput);
+ cvMerge(realInput, imaginaryInput, NULL, NULL, complexInput);
+
+ dft_M = cvGetOptimalDFTSize( im->height - 1 );
+ dft_N = cvGetOptimalDFTSize( im->width - 1 );
+
+ dft_A = cvCreateMat( dft_M, dft_N, CV_64FC2 );
+ image_Re = cvCreateImage( cvSize(dft_N, dft_M), IPL_DEPTH_64F, 1);
+ image_Im = cvCreateImage( cvSize(dft_N, dft_M), IPL_DEPTH_64F, 1);
+ image_Re2 = cvCreateImage( cvSize(dft_N, dft_M), IPL_DEPTH_64F, 1);
+ image_Im2 = cvCreateImage( cvSize(dft_N, dft_M), IPL_DEPTH_64F, 1);
+
+ // copy A to dft_A and pad dft_A with zeros
+ cvGetSubRect( dft_A, &tmp, cvRect(0,0, im->width, im->height));
+ cvCopy( complexInput, &tmp, NULL );
+ if( dft_A->cols > im->width )
+ {
+ cvGetSubRect( dft_A, &tmp, cvRect(im->width,0, dft_A->cols -
+ im->width, im->height));
+ cvZero( &tmp );
+ }
+
+
+ cvDFT( dft_A, dft_A, CV_DXT_FORWARD, complexInput->height );
+
+ // Split Fourier in real and imaginary parts
+ cvSplit( dft_A, image_Re, image_Im, 0, 0 );
+ cvCopyImage(image_Re,image_Re2);
+ cvCopyImage(image_Im,image_Im2);
+
+ // Compute the magnitude of the spectrum Mag = sqrt(Re^2 + Im^2)
+ cvPow( image_Re, image_Re, 2.0);
+ cvPow( image_Im, image_Im, 2.0);
+ cvAdd( image_Re, image_Im, image_Re, NULL);
+ cvPow( image_Re, image_Re, 0.5 );
+
+ // compute the phase of the spectrum Phase = atan(Re/Im)
+ int r=cvGetSize(image_Re).height;
+ int c=cvGetSize(image_Re).width;
+ CvScalar s1,s2;
+ for (int i=0;iheight );
+ cvScale(dft_A,dft_A,0.001);
+
+ // Split Fourier in real and imaginary parts
+ cvSplit( dft_A, image_Re, image_Im, 0, 0 );
+
+ // Compute the magnitude of the spectrum Mag = sqrt(Re^2 + Im^2)
+ cvPow( image_Re, image_Re, 2.0);
+ cvPow( image_Im, image_Im, 2.0);
+ cvAdd( image_Re, image_Im, image_Re, NULL);
+ cvPow( image_Re, image_Re, 0.5 );
+
+ // Compute log(1 + Mag)
+ cvAddS( image_Re, cvScalarAll(1.0), image_Re, NULL ); // 1 + Mag
+ cvLog( image_Re, image_Re ); // log(1 + Mag)
+
+ cvMinMaxLoc(image_Re, &m, &M, NULL, NULL, NULL);
+ cvScale(image_Re, image_Re, 1.0/(M-m), 1.0*(-m)/(M-m));
+ minVal = 0; maxVal = 0;
+ cvMinMaxLoc(image_Re, &minVal, &maxVal, &minLoc, &maxLoc, 0);
+ cvCvtScaleAbs(image_Re,image_Re1,255.0*(maxVal-minVal),0);
+ //cvNamedWindow("inverse",0);
+ //cvShowImage("inverse",image_Re1);
+ //cvWaitKey(-1);
+
+ cvReleaseImage(&image_Re);
+ cvReleaseImage(&image_Re1);
+ cvReleaseImage(&image_Im);
+ cvReleaseImage(&im);
+ cvReleaseImage(&im1);
+ cvReleaseImage(&realInput);
+ cvReleaseImage(&imaginaryInput);
+ cvReleaseImage(&complexInput);
+ cvReleaseMat(&dft_A);
+ }
+ else if(atoi(argv[1])==2)
+ {
+ IplImage * magImage = cvLoadImage(argv[2],0);
+ IplImage * phaseImage = cvLoadImage(argv[3],0);
+ IplImage * realInput = cvCreateImage( cvGetSize(magImage), IPL_DEPTH_64F, 1);
+ IplImage * imaginaryInput = cvCreateImage( cvGetSize(magImage), IPL_DEPTH_64F, 1);
+ IplImage * complexInput = cvCreateImage( cvGetSize(magImage), IPL_DEPTH_64F, 2);
+ IplImage * realInput2 = cvCreateImage( cvGetSize(phaseImage), IPL_DEPTH_64F, 1);
+ IplImage * imaginaryInput2 = cvCreateImage( cvGetSize(phaseImage), IPL_DEPTH_64F, 1);
+ IplImage * complexInput2 = cvCreateImage( cvGetSize(phaseImage), IPL_DEPTH_64F, 2);
+
+ cvScale(magImage, realInput, 1.0, 0.0);
+ cvZero(imaginaryInput);
+ cvMerge(realInput, imaginaryInput, NULL, NULL, complexInput);
+ int dft_M = cvGetOptimalDFTSize( (magImage->height > phaseImage->height?magImage->height:phaseImage->height) - 1 );
+ int dft_N = cvGetOptimalDFTSize( (magImage->width > phaseImage->width?magImage->width:phaseImage->width) - 1 );
+ CvMat* dft_A, tmp;
+ dft_A = cvCreateMat( dft_M, dft_N, CV_64FC2 );
+ cvGetSubRect( dft_A, &tmp, cvRect(0,0, magImage->width, magImage->height));
+ cvCopy( complexInput, &tmp, NULL );
+ if( dft_A->cols > magImage->width )
+ {
+ cvGetSubRect( dft_A, &tmp, cvRect(magImage->width,0, dft_A->cols -
+ magImage->width, magImage->height));
+ cvZero( &tmp );
+ }
+ cvDFT( dft_A, dft_A, CV_DXT_FORWARD, complexInput->height );
+ IplImage * re = cvCreateImage( cvSize(dft_N,dft_M), IPL_DEPTH_64F, 1);
+ IplImage * im = cvCreateImage( cvSize(dft_N,dft_M), IPL_DEPTH_64F, 1);
+ IplImage * mag = cvCreateImage( cvSize(dft_N,dft_M), IPL_DEPTH_64F, 1);
+ cvSplit( dft_A, re, im, 0, 0 );
+ cvPow( re, re, 2.0);
+ cvPow( im, im, 2.0);
+ cvAdd( re, im, mag, NULL);
+ cvPow( mag, mag, 0.5 );
+
+ cvScale(phaseImage, realInput2, 1.0, 0.0);
+ cvZero(imaginaryInput2);
+ cvMerge(realInput2, imaginaryInput2, NULL, NULL, complexInput2);
+ //int dft_M2 = cvGetOptimalDFTSize( phaseImage->height - 1 );
+ //int dft_N2 = cvGetOptimalDFTSize( phaseImage->width - 1 );
+ CvMat* dft_A2, tmp2;
+ dft_A2 = cvCreateMat( dft_M, dft_N, CV_64FC2 );
+ cvGetSubRect( dft_A2, &tmp2, cvRect(0,0, phaseImage->width, phaseImage->height));
+ cvCopy( complexInput2, &tmp2, NULL );
+ if( dft_A2->cols > phaseImage->width )
+ {
+ cvGetSubRect( dft_A2, &tmp2, cvRect(phaseImage->width,0, dft_A2->cols -
+ phaseImage->width, phaseImage->height));
+ cvZero( &tmp2 );
+ }
+ cvDFT( dft_A2, dft_A2, CV_DXT_FORWARD, complexInput2->height );
+ cvSplit( dft_A2, re, im, 0, 0 );
+
+
+ IplImage *realOutput = cvCreateImage(cvSize(dft_N,dft_M),IPL_DEPTH_64F,1);
+ IplImage *imagOutput = cvCreateImage(cvSize(dft_N,dft_M),IPL_DEPTH_64F,1);
+ IplImage *complexOutput = cvCreateImage(cvSize(dft_N,dft_M),IPL_DEPTH_64F,2);
+ int r=cvGetSize(mag).height;
+ int c=cvGetSize(mag).width;
+ CvScalar s1,s2,s3,s4;
+ for (int i=0;iheight );
+ cvScale(dft_A,dft_A,0.001);
+ cvSplit( dft_A, realOutput, imagOutput, 0, 0 );
+ cvPow( realOutput, realOutput, 2.0);
+ cvPow( imagOutput, imagOutput, 2.0);
+ cvAdd( realOutput, imagOutput, realOutput, NULL);
+ cvPow( realOutput, realOutput, 0.5 );
+ cvAddS( realOutput, cvScalarAll(1.0), realOutput, NULL ); // 1 + Mag
+ cvLog( realOutput, realOutput ); // log(1 + Mag)
+ double m,M;
+ cvMinMaxLoc(realOutput, &m, &M, NULL, NULL, NULL);
+ cvScale(realOutput, realOutput, 1.0/(M-m), 1.0*(-m)/(M-m));
+ IplImage * Output = cvCreateImage(cvGetSize(realOutput),IPL_DEPTH_8U,1);
+ CvPoint minLoc, maxLoc;
+ double minVal = 0; double maxVal = 0;
+ cvMinMaxLoc(realOutput, &minVal, &maxVal, &minLoc, &maxLoc, 0);
+ cvCvtScaleAbs(realOutput,Output,255.0*(maxVal-minVal),0);
+ cvSaveImage(argv[4],Output);
+ //cvNamedWindow("impofphase",0);
+ //cvShowImage("impofphase",Output);
+ //cvWaitKey(-1);
+
+
+ cvReleaseImage(&re);
+ cvReleaseImage(&im);
+ cvReleaseImage(&mag);
+ cvReleaseImage(&magImage);
+ cvReleaseImage(&phaseImage);
+ cvReleaseImage(&realInput);
+ cvReleaseImage(&imaginaryInput);
+ cvReleaseImage(&complexInput);
+ cvReleaseImage(&realOutput);
+ cvReleaseImage(&imagOutput);
+ cvReleaseImage(&complexOutput);
+ cvReleaseImage(&Output);
+ cvReleaseMat(&dft_A);
+ }
+ else if(atoi(argv[1])==3)
+ {
+ IplImage * im = cvLoadImage(argv[2],0);
+ IplImage * realInput = cvCreateImage( cvGetSize(im), IPL_DEPTH_64F, 1);
+ IplImage * imaginaryInput = cvCreateImage( cvGetSize(im), IPL_DEPTH_64F, 1);
+ IplImage * complexInput = cvCreateImage( cvGetSize(im), IPL_DEPTH_64F, 2);
+ CvMat* dft_A, tmp;
+ int theta = atoi(argv[4]);
+ int rad = atoi(argv[5]);
+ int deltheta = atoi(argv[6]);
+ int delrad = atoi(argv[7]);
+ double angle1 = theta-(deltheta/2);
+ double angle2 = theta+(deltheta/2);
+ double angle3 = 180+theta-(deltheta/2);
+ double angle4 = 180+theta+(deltheta/2);
+ double val1 = atan((angle1==90||angle1==270||angle1==-90||angle1==-270)?MAXI:tan(PI/180*angle1));
+ double val2 = atan((angle1==90||angle1==270||angle1==-90||angle1==-270)?MAXI:tan(PI/180*angle2));
+ double val3 = atan((angle1==90||angle1==270||angle1==-90||angle1==-270)?MAXI:tan(PI/180*angle3));
+ double val4 = atan((angle1==90||angle1==270||angle1==-90||angle1==-270)?MAXI:tan(PI/180*angle4));
+
+ int dft_M, dft_N;
+ cvScale(im, realInput, 1.0, 0.0);
+ cvZero(imaginaryInput);
+ cvMerge(realInput, imaginaryInput, NULL, NULL, complexInput);
+ dft_M = cvGetOptimalDFTSize( im->height - 1 );
+ dft_N = cvGetOptimalDFTSize( im->width - 1 );
+ dft_A = cvCreateMat( dft_M, dft_N, CV_64FC2 );
+ cvGetSubRect( dft_A, &tmp, cvRect(0,0, im->width, im->height));
+ cvCopy( complexInput, &tmp, NULL );
+ if( dft_A->cols > im->width )
+ {
+ cvGetSubRect( dft_A, &tmp, cvRect(im->width,0, dft_A->cols -
+ im->width, im->height));
+ cvZero( &tmp );
+ }
+ cvDFT( dft_A, dft_A, CV_DXT_FORWARD, complexInput->height );
+ IplImage * re = cvCreateImage(cvSize(dft_N,dft_M),IPL_DEPTH_64F,1);
+ IplImage * imag = cvCreateImage(cvSize(dft_N,dft_M),IPL_DEPTH_64F,1);
+ cvSplit(dft_A,re,imag,0,0);
+
+ int r = cvGetSize(imag).height;
+ int c = cvGetSize(imag).width;
+ double dist,row,col,val;
+ CvScalar s;
+ for (int i=0;i=val2 && (val>=val1||val<=val2)) || (val3>=val4 && (val>=val3||val<=val4)))
+ {
+ s.val[0]=0.0;
+ cvSet2D(imag,i,j,s);
+ cvSet2D(re,i,j,s);
+ }
+ else if ((val>=val1 && val<=val2) || (val>=val3 && val<=val4))
+ {
+ s.val[0]=0.0;
+ cvSet2D(imag,i,j,s);
+ cvSet2D(re,i,j,s);
+ }
+ }
+ }
+ }
+ }
+
+ //cvNamedWindow("imaginary",0);
+ //cvShowImage("imaginary",imag);
+ //cvNamedWindow("real",0);
+ //cvShowImage("real",re);
+
+ cvMerge(re,imag,NULL,NULL,dft_A);
+ cvDFT( dft_A, dft_A, CV_DXT_INVERSE_SCALE, dft_N);
+ cvScale(dft_A,dft_A,0.001);
+ cvSplit(dft_A,re,imag,0,0);
+ cvPow(re,re,2);
+ cvPow(imag,imag,2);
+ cvAdd(re,imag,re,NULL);
+ cvPow(re,re,0.5);
+ cvAddS( re, cvScalarAll(1.0), re, NULL ); // 1 + Mag
+ cvLog( re, re); // log(1 + Mag)
+ double m,M;
+ cvMinMaxLoc(re, &m, &M, NULL, NULL, NULL);
+ cvScale(re, re, 1.0/(M-m), 1.0*(-m)/(M-m));
+ IplImage * Output = cvCreateImage(cvGetSize(re),IPL_DEPTH_8U,1);
+ CvPoint minLoc, maxLoc;
+ double minVal = 0; double maxVal = 0;
+ cvMinMaxLoc(re, &minVal, &maxVal, &minLoc, &maxLoc, 0);
+ cvCvtScaleAbs(re,Output,255.0*(maxVal-minVal),0);
+ cvSaveImage(argv[3],Output);
+
+ //cvNamedWindow("advfourier",0);
+ //cvShowImage("advfourier",Output);
+
+ //cvWaitKey(-1);
+
+ cvReleaseImage(&im);
+ cvReleaseImage(&realInput);
+ cvReleaseImage(&imaginaryInput);
+ cvReleaseImage(&complexInput);
+ cvReleaseImage(&re);
+ cvReleaseImage(&imag);
+ cvReleaseMat(&dft_A);
+ cvReleaseImage(&Output);
+ }
+
+ return 0;
+}
diff --git a/experiment/simulation/build/codes/im_hist.cpp b/experiment/simulation/build/codes/im_hist.cpp
new file mode 100755
index 0000000..2b17cd9
--- /dev/null
+++ b/experiment/simulation/build/codes/im_hist.cpp
@@ -0,0 +1,339 @@
+#include
+#include
+#include
+#include
+using namespace std;
+
+IplImage* adapthist(IplImage* pln, int arg3, int arg4)
+{
+ int c=cvGetSize(pln).width;
+ int r=cvGetSize(pln).height;
+
+ IplImage *p4=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+
+ IplImage *temp=cvCreateImage(cvSize(arg3,arg4),IPL_DEPTH_8U,1);
+
+ CvScalar s;
+ for (int ii=0;ii=x)?0:x); ii=y)?0:y); jjbins, hist->bins, ((float)hist_img->height)/max_value, 0 );
+
+ // calculate width
+ w_scale = ((float)hist_img->width)/hist_size;
+
+ // plot the histogram
+ for( int i = 0; i < hist_size; i++ ) {
+
+ cvRectangle( hist_img, cvPoint((int)i*w_scale , hist_img->height),
+ cvPoint((int)(i+1)*w_scale, hist_img->height - cvRound(cvGetReal1D(hist->bins,i))),
+ CV_RGB(255,255,0), -1, 8, 0 );
+
+ }
+}
+IplImage* Pre_Process(IplImage* src,int bins)
+{
+ int c = cvGetSize(src).width;
+ int r = cvGetSize(src).height;
+
+ IplImage* final_img=cvCreateImage(cvSize(src->width,src->height),src->depth,src->nChannels);
+ cvZero(final_img);
+ for(int i=0;iwidth, source->height ), IPL_DEPTH_8U, 1 );
+ if(nbins!=256)
+ bin_img = Pre_Process(source,nbins);
+ else
+ bin_img = cvCloneImage(source);
+
+ int c = cvGetSize(bin_img).width;
+ int r = cvGetSize(bin_img).height;
+
+
+ if(atoi(argv[3])==1)
+ {
+ int mn=300,mx=-1,avg=0;
+ for(int i=0;i mx)
+ mx = s1.val[0];
+ avg+=s1.val[0];
+ }
+ }
+ avg = avg/(r*c);
+ IplImage *hist_img = cvCreateImage(cvSize(300,300), 8,3);
+ cvSet( hist_img, cvScalarAll(200), 0 );
+ create_histogram_image(bin_img, hist_img,nbins);
+ char nam[30];
+ int n = sprintf(nam,"%s.%s",img_nm,img_typ);
+ cvSaveImage(nam,hist_img);
+ cvReleaseImage( &source );
+ cvReleaseImage( &hist_img );
+ cvReleaseImage( &bin_img );
+ cout<width/2, source->height/2 ), IPL_DEPTH_8U, 1 );
+ int mn4=300,mx4=-1,avg4=0;
+ for(int i=0;i mx4)
+ mx4 = s1.val[0];
+ avg4+=s1.val[0];
+ cvSet2D(bin_img1,i,j,s);
+ }
+ }
+ avg4 = 4*avg4/(r*c);
+
+ IplImage *hist_img = cvCreateImage(cvSize(300,300), 8, 3);
+ cvSet( hist_img, cvScalarAll(200), 0 );
+ create_histogram_image(bin_img1, hist_img,nbins);
+ char nam[30];
+ int n = sprintf(nam,"%s1.%s",img_nm,img_typ);
+ cvSaveImage(nam,hist_img);
+
+ IplImage *bin_img2 = cvCreateImage(cvSize( source->width/2, source->height/2 ), IPL_DEPTH_8U, 1 );
+ int mn1=300,mx1=-1,avg1=0;
+ for(int i=0;i mx1)
+ mx1 = s1.val[0];
+ avg1+=s1.val[0];
+
+ cvSet2D(bin_img2,i,j-c/2,s);
+ }
+ }
+ avg1 = 4*avg1/(r*c);
+
+ hist_img = cvCreateImage(cvSize(300,300), 8, 3);
+ cvSet( hist_img, cvScalarAll(200), 0 );
+ create_histogram_image(bin_img2, hist_img,nbins);
+ n = sprintf(nam,"%s2.%s",img_nm,img_typ);
+ cvSaveImage(nam,hist_img);
+
+ IplImage *bin_img3 = cvCreateImage(cvSize( source->width/2, source->height/2 ), IPL_DEPTH_8U, 1 );
+ int mn2=300,mx2=-1,avg2=0;
+ for(int i=r/2;i mx2)
+ mx2 = s1.val[0];
+ avg2+=s1.val[0];
+ cvSet2D(bin_img3,i-r/2,j,s);
+ }
+ }
+ avg2 = 4*avg2/(r*c);
+
+ hist_img = cvCreateImage(cvSize(300,300), 8, 3);
+ cvSet( hist_img, cvScalarAll(200), 0 );
+ create_histogram_image(bin_img3, hist_img,nbins);
+ n = sprintf(nam,"%s3.%s",img_nm,img_typ);
+ cvSaveImage(nam,hist_img);
+
+
+ IplImage *bin_img4 = cvCreateImage(cvSize( source->width/2, source->height/2 ), IPL_DEPTH_8U, 1 );
+ int mn3=300,mx3=-1,avg3=0;
+ for(int i=r/2;i mx3)
+ mx3 = s1.val[0];
+ avg3+=s1.val[0];
+ cvSet2D(bin_img4,i-r/2,j-c/2,s);
+ }
+ }
+ avg3 = 4*avg3/(r*c);
+
+ hist_img = cvCreateImage(cvSize(300,300), 8,3);
+ cvSet( hist_img, cvScalarAll(200), 0 );
+ create_histogram_image(bin_img4, hist_img,nbins);
+ n = sprintf(nam,"%s4.%s",img_nm,img_typ);
+ cvSaveImage(nam,hist_img);
+
+ cvReleaseImage( &source );
+ cvReleaseImage( &hist_img );
+ cvReleaseImage( &bin_img );
+ cvReleaseImage( &bin_img1 );
+ cvReleaseImage( &bin_img2 );
+ cvReleaseImage( &bin_img3 );
+ cvReleaseImage( &bin_img4 );
+
+ cout<
+#include
+#include
+#include
+using namespace std;
+
+void create_histogram_image(IplImage* bin_img, IplImage* hist_img,int bins) {
+ CvHistogram *hist;
+
+ int fc = 256/bins;
+ int hist_size = 256/fc;
+ float range[]={0,256/fc};
+ float* ranges[] = { range };
+ float max_value = 0.0;
+ float w_scale = 0.0;
+
+ // create array to hold histogram values
+ hist = cvCreateHist(1, &hist_size, CV_HIST_ARRAY, ranges, 1);
+
+ // calculate histogram values
+ cvCalcHist( &bin_img, hist, 0, NULL );
+
+ // Get the minimum and maximum values of the histogram
+ cvGetMinMaxHistValue( hist, 0, &max_value, 0, 0 );
+
+ // set height by using maximim value
+ cvScale( hist->bins, hist->bins, ((float)hist_img->height)/max_value, 0 );
+
+ // calculate width
+ w_scale = ((float)hist_img->width)/hist_size;
+
+ // plot the histogram
+ for( int i = 0; i < hist_size; i++ ) {
+
+ cvRectangle( hist_img, cvPoint((int)i*w_scale , hist_img->height),
+ cvPoint((int)(i+1)*w_scale, hist_img->height - cvRound(cvGetReal1D(hist->bins,i))),
+ CV_RGB(255,255,0), -1, 8, 0 );
+
+ }
+}
+IplImage* Pre_Process(IplImage* src,int bins)
+{
+ int c = cvGetSize(src).width;
+ int r = cvGetSize(src).height;
+
+ IplImage* final_img=cvCreateImage(cvSize(src->width,src->height),src->depth,src->nChannels);
+ cvZero(final_img);
+ for(int i=0;iwidth, source->height ), IPL_DEPTH_8U, 1 );
+ if(nbins!=256)
+ bin_img = Pre_Process(source,nbins);
+ else
+ bin_img = cvCloneImage(source);
+
+ int c = cvGetSize(bin_img).width;
+ int r = cvGetSize(bin_img).height;
+
+
+ if(atoi(argv[4])==1)
+ {
+ int mn=300,mx=-1,avg=0;
+ for(int i=0;i mx)
+ mx = s1.val[0];
+ avg+=s1.val[0];
+ }
+ }
+ avg = avg/(r*c);
+ IplImage *hist_img = cvCreateImage(cvSize(300,300), 8,3);
+ cvSet( hist_img, cvScalarAll(200), 0 );
+ create_histogram_image(bin_img, hist_img,nbins);
+ char nam[50];
+ int n = sprintf(nam,"%s.%s",img_nm,img_typ);
+ cvSaveImage(nam,hist_img);
+ cvReleaseImage( &source );
+ cvReleaseImage( &hist_img );
+ cvReleaseImage( &bin_img );
+ cout<width/2, bin_img->height/2 ),bin_img->depth,bin_img->nChannels );
+ int mn4=300,mx4=-1,avg4=0;
+ for(int i=0;i mx4)
+ mx4 = s1.val[0];
+ avg4+=s1.val[0];
+ cvSet2D(bin_img1,i,j,s1);
+ }
+ }
+ avg4 = 4*avg4/(r*c);
+
+
+
+ IplImage *hist_img = cvCreateImage(cvSize(300,300), 8, 3);
+ cvSet( hist_img, cvScalarAll(200), 0 );
+ create_histogram_image(bin_img1, hist_img,nbins);
+ char nam[50];
+ int n = sprintf(nam,"%s1.%s",img_nm,img_typ);
+ cvSaveImage(nam,hist_img);
+
+// IplImage *bin_img2 = cvCreateImage(cvSize( source->width/2, source->height/2 ), IPL_DEPTH_8U, 1 );
+ IplImage *bin_img2 = cvCreateImage(cvSize( bin_img->width/2, bin_img->height/2 ),bin_img->depth,bin_img->nChannels );
+ int mn1=300,mx1=-1,avg1=0;
+ for(int i=0;i mx1)
+ mx1 = s1.val[0];
+ avg1+=s1.val[0];
+
+ cvSet2D(bin_img2,i,j-c/2,s1);
+ }
+ }
+ avg1 = 4*avg1/(r*c);
+
+
+ hist_img = cvCreateImage(cvSize(300,300), 8, 3);
+ cvSet( hist_img, cvScalarAll(200), 0 );
+ create_histogram_image(bin_img2, hist_img,nbins);
+ n = sprintf(nam,"%s2.%s",img_nm,img_typ);
+ cvSaveImage(nam,hist_img);
+
+ IplImage *bin_img3 = cvCreateImage(cvSize( source->width/2, source->height/2 ), IPL_DEPTH_8U, 1 );
+ int mn2=300,mx2=-1,avg2=0;
+ for(int i=r/2;i mx2)
+ mx2 = s1.val[0];
+ avg2+=s1.val[0];
+ cvSet2D(bin_img3,i-r/2,j,s1);
+ }
+ }
+ avg2 = 4*avg2/(r*c);
+
+ hist_img = cvCreateImage(cvSize(300,300), 8, 3);
+ cvSet( hist_img, cvScalarAll(200), 0 );
+ create_histogram_image(bin_img3, hist_img,nbins);
+ n = sprintf(nam,"%s3.%s",img_nm,img_typ);
+ cvSaveImage(nam,hist_img);
+
+
+ IplImage *bin_img4 = cvCreateImage(cvSize( source->width/2, source->height/2 ), IPL_DEPTH_8U, 1 );
+ int mn3=300,mx3=-1,avg3=0;
+ for(int i=r/2;i mx3)
+ mx3 = s1.val[0];
+ avg3+=s1.val[0];
+ cvSet2D(bin_img4,i-r/2,j-c/2,s1);
+ }
+ }
+ avg3 = 4*avg3/(r*c);
+
+
+ hist_img = cvCreateImage(cvSize(300,300), 8,3);
+ cvSet( hist_img, cvScalarAll(200), 0 );
+ create_histogram_image(bin_img4, hist_img,nbins);
+ n = sprintf(nam,"%s4.%s",img_nm,img_typ);
+ cvSaveImage(nam,hist_img);
+
+ cout<
+#include
+#include
+#include
+#include
+
+using namespace std;
+
+int main(int argc, char ** argv)
+{
+ IplImage * magImage = cvLoadImage(argv[1],0);
+ IplImage * phaseImage = cvLoadImage(argv[2],0);
+ IplImage * realInput = cvCreateImage( cvGetSize(magImage), IPL_DEPTH_64F, 1);
+ IplImage * imaginaryInput = cvCreateImage( cvGetSize(magImage), IPL_DEPTH_64F, 1);
+ IplImage * complexInput = cvCreateImage( cvGetSize(magImage), IPL_DEPTH_64F, 2);
+
+ cvScale(magImage, realInput, 1.0, 0.0);
+ cvZero(imaginaryInput);
+ cvMerge(realInput, imaginaryInput, NULL, NULL, complexInput);
+ int dft_M = cvGetOptimalDFTSize( magImage->height - 1 );
+ int dft_N = cvGetOptimalDFTSize( magImage->width - 1 );
+ CvMat* dft_A, tmp;
+ dft_A = cvCreateMat( dft_M, dft_N, CV_64FC2 );
+
+ cvGetSubRect( dft_A, &tmp, cvRect(0,0, magImage->width, magImage->height));
+ cvCopy( complexInput, &tmp, NULL );
+ if( dft_A->cols > magImage->width )
+ {
+ cvGetSubRect( dft_A, &tmp, cvRect(magImage->width,0, dft_A->cols -
+ magImage->width, magImage->height));
+ cvZero( &tmp );
+ }
+
+ cvDFT( dft_A, dft_A, CV_DXT_FORWARD, complexInput->height );
+ IplImage * re = cvCreateImage( cvSize(dft_N,dft_M), IPL_DEPTH_64F, 1);
+ IplImage * im = cvCreateImage( cvSize(dft_N,dft_M), IPL_DEPTH_64F, 1);
+ IplImage * mag = cvCreateImage( cvSize(dft_N,dft_M), IPL_DEPTH_64F, 1);
+ cvSplit( dft_A, re, im, 0, 0 );
+ cvPow( re, re, 2.0);
+ cvPow( im, im, 2.0);
+ cvAdd( re, im, mag, NULL);
+ cvPow( mag, mag, 0.5 );
+
+ cvScale(phaseImage, realInput, 1.0, 0.0);
+ cvZero(imaginaryInput);
+ cvMerge(realInput, imaginaryInput, NULL, NULL, complexInput);
+ //int dft_M = cvGetOptimalDFTSize( im->height - 1 );
+ //int dft_N = cvGetOptimalDFTSize( im->width - 1 );
+ //cvMat* dft_A = cvCreateMat( dft_M, dft_N, CV_64FC2 );
+ //cvMat tmp;
+ cvGetSubRect( dft_A, &tmp, cvRect(0,0, phaseImage->width, phaseImage->height));
+ cvCopy( complexInput, &tmp, NULL );
+ if( dft_A->cols > phaseImage->width )
+ {
+ cvGetSubRect( dft_A, &tmp, cvRect(phaseImage->width,0, dft_A->cols -
+ phaseImage->width, phaseImage->height));
+ cvZero( &tmp );
+ }
+ cvDFT( dft_A, dft_A, CV_DXT_FORWARD, complexInput->height );
+ cvSplit( dft_A, re, im, 0, 0 );
+
+
+ IplImage *realOutput = cvCreateImage(cvSize(dft_N,dft_M),IPL_DEPTH_64F,1);
+ IplImage *imagOutput = cvCreateImage(cvSize(dft_N,dft_M),IPL_DEPTH_64F,1);
+ IplImage *complexOutput = cvCreateImage(cvSize(dft_N,dft_M),IPL_DEPTH_64F,2);
+ int r=cvGetSize(mag).height;
+ int c=cvGetSize(mag).width;
+ CvScalar s1,s2,s3,s4;
+ for (int i=0;iheight );
+ cvScale(dft_A,dft_A,0.001);
+ cvSplit( dft_A, realOutput, imagOutput, 0, 0 );
+ cvPow( realOutput, realOutput, 2.0);
+ cvPow( imagOutput, imagOutput, 2.0);
+ cvAdd( realOutput, imagOutput, realOutput, NULL);
+ cvPow( realOutput, realOutput, 0.5 );
+ cvAddS( realOutput, cvScalarAll(1.0), realOutput, NULL ); // 1 + Mag
+ cvLog( realOutput, realOutput ); // log(1 + Mag)
+ double m,M;
+ cvMinMaxLoc(realOutput, &m, &M, NULL, NULL, NULL);
+ cvScale(realOutput, realOutput, 1.0/(M-m), 1.0*(-m)/(M-m));
+ IplImage * Output = cvCreateImage(cvGetSize(realOutput),IPL_DEPTH_8U,1);
+ CvPoint minLoc, maxLoc;
+ double minVal = 0; double maxVal = 0;
+ cvMinMaxLoc(realOutput, &minVal, &maxVal, &minLoc, &maxLoc, 0);
+ cvCvtScaleAbs(realOutput,Output,255.0*(maxVal-minVal),0);
+ cvSaveImage("impofphase.jpg",Output);
+
+
+ cvReleaseImage(&re);
+ cvReleaseImage(&im);
+ cvReleaseImage(&mag);
+ cvReleaseImage(&magImage);
+ cvReleaseImage(&phaseImage);
+ cvReleaseImage(&realInput);
+ cvReleaseImage(&imaginaryInput);
+ cvReleaseImage(&complexInput);
+ cvReleaseImage(&realOutput);
+ cvReleaseImage(&imagOutput);
+ cvReleaseImage(&complexOutput);
+ cvReleaseImage(&Output);
+ cvReleaseMat(&dft_A);
+
+ return 0;
+}
diff --git a/experiment/simulation/build/codes/im_logical.cpp b/experiment/simulation/build/codes/im_logical.cpp
new file mode 100755
index 0000000..f6e92f7
--- /dev/null
+++ b/experiment/simulation/build/codes/im_logical.cpp
@@ -0,0 +1,154 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+using namespace std;
+
+IplImage* imOR(IplImage *img1,IplImage *img2)
+{
+ int c = cvGetSize(img1).width;
+ int r = cvGetSize(img1).height;
+
+ IplImage* final_img=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+ for(int i=0;i 0) or (s2.val[0] > 0))
+ grval = 255;
+ s.val[0] = grval;
+ cvSet2D(final_img,i,j,s);
+ }
+ }
+ return final_img;
+}
+
+IplImage* imAND(IplImage *img1,IplImage *img2)
+{
+ int c = cvGetSize(img1).width;
+ int r = cvGetSize(img1).height;
+
+ IplImage* final_img=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+ for(int i=0;i 0) and (s2.val[0] > 0))
+ grval = 255;
+ // cout<
+#include
+#include
+#include
+#include
+#include
+
+using namespace std;
+
+// argv[2] indicates Operation
+// argv[3] indicates Shape
+// argv[3] indicates Size
+
+int main(int argc, char* argv[])
+{
+ IplImage* source = cvLoadImage(argv[1],0);
+
+ int col = cvGetSize(source).width;
+ int row = cvGetSize(source).height;
+
+ IplImage* temp = cvCreateImage(cvSize(col,row),IPL_DEPTH_8U,1);
+ IplImage* dest = cvCreateImage(cvSize(col,row),IPL_DEPTH_8U,1);
+
+ int a=atoi(argv[3]);
+ int b=atoi(argv[4]);
+ int c=atoi(argv[5]);
+
+ IplConvKernel* se;
+
+ if (b==1)
+ {
+ if (c==1)
+ se = cvCreateStructuringElementEx( 3, 3, 1, 1, CV_SHAPE_ELLIPSE, 0 );
+ else if (c==2)
+ se = cvCreateStructuringElementEx( 5, 5, 2, 2, CV_SHAPE_ELLIPSE, 0 );
+ else if (c==3)
+ se = cvCreateStructuringElementEx( 7, 7, 2, 2, CV_SHAPE_ELLIPSE, 0 );
+ }
+ else if (b==2)
+ {
+ if (c==1)
+ se = cvCreateStructuringElementEx( 3, 3, 1, 1, CV_SHAPE_RECT, 0 );
+ else if (c==2)
+ se = cvCreateStructuringElementEx( 5, 5, 2, 2, CV_SHAPE_RECT, 0 );
+ else if (c==3)
+ se = cvCreateStructuringElementEx( 7, 7, 2, 2, CV_SHAPE_RECT, 0 );
+ }
+ else if (b==3)
+ {
+ if (c==1)
+ se = cvCreateStructuringElementEx( 3, 3, 1, 1, CV_SHAPE_ELLIPSE, 0 );
+ else if (c==2)
+ se = cvCreateStructuringElementEx( 5, 5, 2, 2, CV_SHAPE_ELLIPSE, 0 );
+ else if (c==3)
+ se = cvCreateStructuringElementEx( 7, 7, 2, 2, CV_SHAPE_ELLIPSE, 0 );
+ }
+
+ if (a==1)
+ {
+ cvErode(source,dest,se,1);
+ }
+ else if (a==2)
+ {
+ cvDilate(source,dest,se,1);
+ }
+ else if (a==3)
+ {
+ cvErode(source,temp,se,1);
+ cvDilate(temp,dest,se,1);
+ }
+ else if (a==4)
+ {
+ cvDilate(source,temp,se,1);
+ cvErode(temp,dest,se,1);
+ }
+
+ CvScalar s1,s2;
+ for (int i=0;i
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+using namespace std;
+
+float sum=0;
+int parm;
+
+IplImage* linear(IplImage *img, float arr[][7])
+{
+ int c = cvGetSize(img).width;
+ int r = cvGetSize(img).height;
+
+ IplImage* final_img=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,img->nChannels);
+ for(int xp=0;xp=0 && xp-(parm/2)+i=0 && yp-(parm/2)+jnChannels);
+ for(int xp=0;xp grvals;
+
+ CvScalar s,s2;
+ s = cvGet2D(img,xp,yp);
+ for(int i=0;i=0 && xp-(parm/2)+i=0 && yp-(parm/2)+jdepth, src-> nChannels);
+ IplImage *temp1 = cvCreateImage(cvGetSize(src), src->depth, src-> nChannels);
+ IplImage *temp2 = cvCreateImage(cvGetSize(src), src->depth, src-> nChannels);
+
+ cvSmooth( src, temp1, CV_GAUSSIAN, 27, 27);
+ cvSub( src,temp1, temp2, NULL );
+
+ int c = cvGetSize(src).width;
+ int r = cvGetSize(src).height;
+
+ CvScalar s1,s2,s3;
+ for (int i=0;inChannels);
+ if(parm==2) {
+ parm=atoi(argv[4]);
+ nbrd_img=medn_filt(img1);
+ }
+ else {
+ for(int i=0;i
+#include
+#include
+#include
+#include
+#include
+#include
+
+using namespace std;
+
+IplImage* imPATH(IplImage *img,int xs,int ys,int xd,int yd,int con,int gr)
+{
+ int c = cvGetSize(img).width;
+ int r = cvGetSize(img).height;
+
+ IplImage* final_img=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,3);
+ cvMerge(img,img,img,NULL,final_img);
+
+ int dst[r][c];
+ int srcx[r][c];
+ int srcy[r][c];
+ for(int i=0;i X;
+ queue Y;
+ srcx[xs][ys]=xs;
+ srcy[xs][ys]=ys;
+ X.push(xs);
+ Y.push(ys);
+ dst[xs][ys]=0;
+ int pth_found=0;
+
+ int xp,yp;
+ while(!X.empty())
+ {
+ xp = X.front();
+ yp = Y.front();
+/* cout<<"last "<=0)
+ s1 = cvGet2D(img,xp-1,yp);
+ if(con==8 and (xp -1 >= 0) and (yp+1 =0))
+ s7 = cvGet2D(img,xp+1,yp-1);
+
+ if(yp-1 >=0)
+ s4 = cvGet2D(img,xp,yp-1);
+ if(con==8 and (xp-1 >=0) and (yp-1 >=0))
+ s8 = cvGet2D(img,xp-1,yp-1);
+
+ if(s1.val[0] ==gr)
+ {
+ if(dst[xp-1][yp] > dst[xp][yp] + 1)
+ {
+ dst[xp-1][yp]=dst[xp][yp]+1;
+ srcx[xp-1][yp]=xp;
+ srcy[xp-1][yp]=yp;
+ X.push(xp-1);
+ Y.push(yp);
+ }
+ }
+
+
+ if(s2.val[0] ==gr)
+ {
+ if(dst[xp][yp+1] > dst[xp][yp] + 1)
+ {
+ dst[xp][yp+1]=dst[xp][yp]+1;
+ srcx[xp][yp+1]=xp;
+ srcy[xp][yp+1]=yp;
+ X.push(xp);
+ Y.push(yp+1);
+ }
+ }
+
+
+ if(s3.val[0] ==gr)
+ {
+ if(dst[xp+1][yp] > dst[xp][yp] + 1)
+ {
+ dst[xp+1][yp]=dst[xp][yp]+1;
+ srcx[xp+1][yp]=xp;
+ srcy[xp+1][yp]=yp;
+ X.push(xp+1);
+ Y.push(yp);
+ }
+ }
+
+
+ if(s4.val[0] ==gr)
+ {
+ if(dst[xp][yp-1] > dst[xp][yp] + 1)
+ {
+ dst[xp][yp-1]=dst[xp][yp]+1;
+ srcx[xp][yp-1]=xp;
+ srcy[xp][yp-1]=yp;
+ X.push(xp);
+ Y.push(yp-1);
+ }
+ }
+
+ if(s5.val[0] ==gr)
+ {
+ if(dst[xp-1][yp+1] > dst[xp][yp] + 1)
+ {
+ dst[xp-1][yp+1]=dst[xp][yp]+1;
+ srcx[xp-1][yp+1]=xp;
+ srcy[xp-1][yp+1]=yp;
+ X.push(xp-1);
+ Y.push(yp+1);
+ }
+ }
+
+ if(s6.val[0] ==gr)
+ {
+ if(dst[xp+1][yp+1] > dst[xp][yp] + 1)
+ {
+ dst[xp+1][yp+1]=dst[xp][yp]+1;
+ srcx[xp+1][yp+1]=xp;
+ srcy[xp+1][yp+1]=yp;
+ X.push(xp+1);
+ Y.push(yp+1);
+ }
+ }
+
+ if(s7.val[0] ==gr)
+ {
+ if(dst[xp+1][yp-1] > dst[xp][yp] + 1)
+ {
+ dst[xp+1][yp-1]=dst[xp][yp]+1;
+ srcx[xp+1][yp-1]=xp;
+ srcy[xp+1][yp-1]=yp;
+ X.push(xp+1);
+ Y.push(yp-1);
+ }
+ }
+
+ if(s8.val[0] ==gr)
+ {
+ if(dst[xp-1][yp-1] > dst[xp][yp] + 1)
+ {
+ dst[xp-1][yp-1]=dst[xp][yp]+1;
+ srcx[xp-1][yp-1]=xp;
+ srcy[xp-1][yp-1]=yp;
+ X.push(xp-1);
+ Y.push(yp-1);
+ }
+ }
+ }
+
+ int tx=xd,ty=yd;
+ if(!pth_found)
+ {
+ cout<<"Path not found\n";
+ tx = xp;
+ ty = yp;
+// cout<<"point "<
+#include
+#include
+#include
+#include
+#include
+#include
+
+using namespace std;
+
+IplImage* imPATH(IplImage *img,int xs,int ys,int xd,int yd)
+{
+ int c = cvGetSize(img).width;
+ int r = cvGetSize(img).height;
+
+ IplImage* final_img=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+
+ int dst[r][c];
+ for(int i=0;i X;
+ queue Y;
+ srcx[xs][ys]=xs;
+ srcy[xs][ys]=ys;
+ X.push(xs);
+ Y.push(ys);
+ dst[xs][ys]=0;
+ int pth_found=0;
+
+ int xp,yp;
+ while(!X.empty())
+ {
+ xp = X.front();
+ yp = Y.front();
+// cout<=0)
+ s1 = cvGet2D(img,xp-1,yp);
+ if(yp+1 < c)
+ s2 = cvGet2D(img,xp,yp+1);
+ if(xp+1 < r)
+ s3 = cvGet2D(img,xp+1,yp);
+ if(yp-1 >=0)
+ s4 = cvGet2D(img,xp,yp-1);
+ if(s1.val[0] > 0)
+ {
+ if(dst[xp-1][yp] > dst[xp][yp] + 1)
+ {
+ dst[xp-1][yp]=dst[xp][yp]+1;
+ srcx[xp-1][yp]=xp;
+ srcy[xp-1][yp]=yp;
+ X.push(xp-1);
+ Y.push(yp);
+ }
+ }
+ if(s2.val[0] > 0)
+ {
+ if(dst[xp][yp+1] > dst[xp][yp] + 1)
+ {
+ dst[xp][yp+1]=dst[xp][yp]+1;
+ srcx[xp][yp+1]=xp;
+ srcy[xp][yp+1]=yp;
+ X.push(xp);
+ Y.push(yp+1);
+ }
+ }
+ if(s3.val[0] > 0)
+ {
+ if(dst[xp+1][yp] > dst[xp][yp] + 1)
+ {
+ dst[xp+1][yp]=dst[xp][yp]+1;
+ srcx[xp+1][yp]=xp;
+ srcy[xp+1][yp]=yp;
+ X.push(xp+1);
+ Y.push(yp);
+ }
+ }
+ if(s4.val[0] > 0)
+ {
+ if(dst[xp][yp-1] > dst[xp][yp] + 1)
+ {
+ dst[xp][yp-1]=dst[xp][yp]+1;
+ srcx[xp][yp-1]=xp;
+ srcy[xp][yp-1]=yp;
+ X.push(xp);
+ Y.push(yp-1);
+ }
+ }
+ }
+
+ if(!pth_found)
+ {
+ cout<<"path not found\n";
+ xd = xp;
+ yd = yp;
+ cout<0 and sd.val[0]>0)
+ {
+ // cout<<"here :S \n";
+ IplImage* path_img=cvCreateImage(cvSize(c1,r1),IPL_DEPTH_8U,1);
+ path_img=imPATH(img1,xs,ys,xd,yd);
+ cvSaveImage(argv[2],path_img);
+ cvReleaseImage( &path_img );
+ }
+ cvReleaseImage( &img1 );
+ return 0;
+}
diff --git a/experiment/simulation/build/codes/im_path_bw.cpp b/experiment/simulation/build/codes/im_path_bw.cpp
new file mode 100755
index 0000000..0da8e0e
--- /dev/null
+++ b/experiment/simulation/build/codes/im_path_bw.cpp
@@ -0,0 +1,271 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+using namespace std;
+
+IplImage* imPATH(IplImage *img,int xs,int ys,int xd,int yd,int con)
+{
+ int c = cvGetSize(img).width;
+ int r = cvGetSize(img).height;
+
+ IplImage* final_img=cvCreateImage(cvSize(c,r),IPL_DEPTH_8U,1);
+
+ int dst[r][c];
+ int srcx[r][c];
+ int srcy[r][c];
+ for(int i=0;i X;
+ queue Y;
+ srcx[xs][ys]=xs;
+ srcy[xs][ys]=ys;
+ X.push(xs);
+ Y.push(ys);
+ dst[xs][ys]=0;
+ int pth_found=0;
+
+ int xp,yp;
+ while(!X.empty())
+ {
+ xp = X.front();
+ yp = Y.front();
+/* cout<<"last "<=0)
+ s1 = cvGet2D(img,xp-1,yp);
+ if(con==8 and (xp -1 >= 0) and (yp+1 =0))
+ s7 = cvGet2D(img,xp+1,yp-1);
+
+ if(yp-1 >=0)
+ s4 = cvGet2D(img,xp,yp-1);
+ if(con==8 and (xp-1 >=0) and (yp-1 >=0))
+ s8 = cvGet2D(img,xp-1,yp-1);
+
+ if(s1.val[0] > 0)
+ {
+ if(dst[xp-1][yp] > dst[xp][yp] + 1)
+ {
+ dst[xp-1][yp]=dst[xp][yp]+1;
+ srcx[xp-1][yp]=xp;
+ srcy[xp-1][yp]=yp;
+ X.push(xp-1);
+ Y.push(yp);
+ }
+ }
+
+ if(s5.val[0] > 0)
+ {
+ if(dst[xp-1][yp+1] > dst[xp][yp] + 1)
+ {
+ dst[xp-1][yp+1]=dst[xp][yp]+1;
+ srcx[xp-1][yp+1]=xp;
+ srcy[xp-1][yp+1]=yp;
+ X.push(xp-1);
+ Y.push(yp+1);
+ }
+ }
+
+ if(s2.val[0] > 0)
+ {
+ if(dst[xp][yp+1] > dst[xp][yp] + 1)
+ {
+ dst[xp][yp+1]=dst[xp][yp]+1;
+ srcx[xp][yp+1]=xp;
+ srcy[xp][yp+1]=yp;
+ X.push(xp);
+ Y.push(yp+1);
+ }
+ }
+
+ if(s6.val[0] > 0)
+ {
+ if(dst[xp+1][yp+1] > dst[xp][yp] + 1)
+ {
+ dst[xp+1][yp+1]=dst[xp][yp]+1;
+ srcx[xp+1][yp+1]=xp;
+ srcy[xp+1][yp+1]=yp;
+ X.push(xp+1);
+ Y.push(yp+1);
+ }
+ }
+
+ if(s3.val[0] > 0)
+ {
+ if(dst[xp+1][yp] > dst[xp][yp] + 1)
+ {
+ dst[xp+1][yp]=dst[xp][yp]+1;
+ srcx[xp+1][yp]=xp;
+ srcy[xp+1][yp]=yp;
+ X.push(xp+1);
+ Y.push(yp);
+ }
+ }
+
+ if(s7.val[0] > 0)
+ {
+ if(dst[xp+1][yp-1] > dst[xp][yp] + 1)
+ {
+ dst[xp+1][yp-1]=dst[xp][yp]+1;
+ srcx[xp+1][yp-1]=xp;
+ srcy[xp+1][yp-1]=yp;
+ X.push(xp+1);
+ Y.push(yp-1);
+ }
+ }
+
+ if(s4.val[0] > 0)
+ {
+ if(dst[xp][yp-1] > dst[xp][yp] + 1)
+ {
+ dst[xp][yp-1]=dst[xp][yp]+1;
+ srcx[xp][yp-1]=xp;
+ srcy[xp][yp-1]=yp;
+ X.push(xp);
+ Y.push(yp-1);
+ }
+ }
+
+ if(s8.val[0] > 0)
+ {
+ if(dst[xp-1][yp-1] > dst[xp][yp] + 1)
+ {
+ dst[xp-1][yp-1]=dst[xp][yp]+1;
+ srcx[xp-1][yp-1]=xp;
+ srcy[xp-1][yp-1]=yp;
+ X.push(xp-1);
+ Y.push(yp-1);
+ }
+ }
+ }
+
+ int tx,ty;
+ if(!pth_found)
+ {
+// cout<<"path not found\n";
+ tx = xp;
+ ty = yp;
+// cout<<"point "<0 and sd.val[0]>0)
+ {
+ // cout<<"here :S \n";
+ IplImage* path_img=cvCreateImage(cvSize(c1,r1),IPL_DEPTH_8U,1);
+ path_img=imPATH(img1,xs,ys,xd,yd,con);
+ cvSaveImage(argv[2],path_img);
+ cvReleaseImage( &path_img );
+ }
+ cvReleaseImage( &img1 );
+ return 0;
+}
diff --git a/experiment/simulation/build/codes/im_point.cpp b/experiment/simulation/build/codes/im_point.cpp
new file mode 100755
index 0000000..a4fc731
--- /dev/null
+++ b/experiment/simulation/build/codes/im_point.cpp
@@ -0,0 +1,185 @@
+#include
+#include
+#include
+#include
+#include
+
+using namespace std;
+
+IplImage* Log_Image(IplImage *src,int cn)
+{
+ int c = cvGetSize(src).width;
+ int r = cvGetSize(src).height;
+
+ IplImage* final_img=cvCreateImage(cvSize(src->width,src->height),src->depth,src->nChannels);
+ cvZero(final_img);
+ for(int i=0;i 255)
+ grval= 255;
+ if(grval < 0)
+ grval = 0;
+ s.val[0] = grval;
+ cvSet2D(final_img,i,j,s);
+ }
+ }
+ return final_img;
+}
+
+IplImage* Contrast_Stretch(IplImage *src,float a,float b)
+{
+ int c = cvGetSize(src).width;
+ int r = cvGetSize(src).height;
+
+ IplImage* final_img=cvCreateImage(cvSize(src->width,src->height),src->depth,src->nChannels);
+ cvZero(final_img);
+ for(int i=0;i 255)
+ grval = 255;
+ else if(grval < 0)
+ grval = 0;
+ s.val[0] = grval;
+ cvSet2D(final_img,i,j,s);
+
+ }
+ }
+ return final_img;
+}
+
+IplImage* Clipped_Image(IplImage *src,float a,float b,float beta)
+{
+ int c = cvGetSize(src).width;
+ int r = cvGetSize(src).height;
+
+ IplImage* final_img=cvCreateImage(cvSize(src->width,src->height),src->depth,src->nChannels);
+ cvZero(final_img);
+ for(int i=0;i (int)(b))
+ grval = 255;
+ else
+ grval = (int)(beta * grval);
+ if(grval > 255)
+ grval = 255;
+ s.val[0] = grval;
+ cvSet2D(final_img,i,j,s);
+ }
+ }
+ return final_img;
+}
+
+IplImage* Windowed_Image(IplImage *src,float a,float b,float beta)
+{
+ int c = cvGetSize(src).width;
+ int r = cvGetSize(src).height;
+
+ IplImage* final_img=cvCreateImage(cvSize(src->width,src->height),src->depth,src->nChannels);
+ cvZero(final_img);
+ for(int i=0;i (int)(b)))
+ grval = 0;
+ else
+ grval = (int)(beta * grval);
+ if(grval > 255)
+ grval = 255;
+ s.val[0] = grval;
+ cvSet2D(final_img,i,j,s);
+ }
+ }
+ return final_img;
+}
+
+int main(int argc,char *argv[])
+{
+ int p[3];
+ p[0] = CV_IMWRITE_JPEG_QUALITY;
+ p[1] = 90;
+ p[2] = 0;
+
+ char *img_nm,*img_typ;
+ IplImage* src = cvLoadImage(argv[1],0);
+ IplImage* dst;
+
+ char *pch,*rem,*f_img;
+ pch = strtok (argv[1],"/");
+ while (pch != NULL)
+ {
+ f_img = pch;
+ pch = strtok (NULL, "/");
+
+ }
+
+ img_nm = strtok (f_img,".");
+ img_typ = strtok (NULL, ".");
+
+
+ if(atoi(argv[3])==1)
+ {
+// cout<<"2\n";
+ float a,b;
+ a = atof(argv[4]);
+ b = atof(argv[5]);
+ dst=cvCreateImage(cvSize(src->width,src->height),src->depth,src->nChannels);
+ dst=Contrast_Stretch(src,a,b);
+ }
+ if(atoi(argv[3])==2)
+ {
+// cout<<"3\n";
+ int c;
+ c = atof(argv[4]);
+ dst=cvCreateImage(cvSize(src->width,src->height),src->depth,src->nChannels);
+ dst=Log_Image(src,c);
+ }
+
+ if(atoi(argv[3])==3)
+ {
+ float a,b,beta;
+ a = atof(argv[4]);
+ b = atof(argv[5]);
+ beta = atof(argv[6]);
+ dst=cvCreateImage(cvSize(src->width,src->height),src->depth,src->nChannels);
+ dst=Clipped_Image(src,a,b,beta);
+ }
+
+ if(atoi(argv[3])==4)
+ {
+ float a,b,beta;
+ a = atof(argv[4]);
+ b = atof(argv[5]);
+ float slope = atof(argv[6]);
+ dst=cvCreateImage(cvSize(src->width,src->height),src->depth,src->nChannels);
+ dst=Windowed_Image(src,a,b,slope);
+ }
+
+
+
+ cvSaveImage(argv[2],dst);
+ cvReleaseImage( &src );
+ cvReleaseImage( &dst);
+ return 0;
+}
diff --git a/experiment/simulation/build/codes/im_resample.cpp b/experiment/simulation/build/codes/im_resample.cpp
new file mode 100755
index 0000000..5c21e23
--- /dev/null
+++ b/experiment/simulation/build/codes/im_resample.cpp
@@ -0,0 +1,91 @@
+#include
+#include
+#include
+#include