import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.image.*; import java.io.*; import java.util.Random; import java.util.Scanner; import javax.imageio.ImageIO; import javax.swing.JFrame; import Jama.*; public class run_cexec_affine_students { static int SIFT_MAX=10000; // Maximum no. of SIFT descriptors in an image static int MATCH_NO=1000; //This is the no. of matching pairs between two images static double sift_arr_1[][]=new double[SIFT_MAX][132]; static double sift_arr_2[][]=new double[SIFT_MAX][132]; //132 is the total no. of features corresponding to one SIFT descriptor. //First four values are the x-y coordinates,scale,orientation of the point //and the rest 128 integer values are descriptors static int no_sift_1=0; static int no_sift_2=0; static int no_sift=0; //These values indicate the no. of SIFT features for the two images static double match_arr[][]=new double[MATCH_NO][4]; //This array is used to store the matching points between two images //The first two fields are x,y coordinates from the first image and //the last two fields are x,y coordinates from the second image //MATCH_NO is the no. of matching pairs between two images static double best_arr[][]=new double[3][4]; //This array is used to store the best three matching points and based on //them, the homography is actually found out.These points are shown on RED in the //final output images. static double best_arr_nn[][]=new double[3][4]; //This array is used to store the best three matching points after nearest neighborhood //and based on them, the homography is actually found out.These points are shown on RED in the //final output images. static BufferedImage img1 = null; static BufferedImage img2 = null; static BufferedImage img1_rgb = null; static BufferedImage img2_rgb = null; static BufferedImage img1_rgb_nn = null; static BufferedImage img2_rgb_nn = null; static String filename1,filename2; public static BufferedImage setPixel (BufferedImage image, int x, int y ) { Graphics g = image.getGraphics( ); Color color=Color.GREEN; g.setColor( color ); g.fillRect( x, y, 3, 3 ); return image; } public static BufferedImage setMatchPixel (BufferedImage image, int x, int y ,int ind) { Graphics g = image.getGraphics( ); Color color=Color.WHITE; if(ind==1){ color=Color.RED; } if(ind==2){ color=Color.BLUE; } g.setColor( color ); g.fillRect( x, y, 10, 10 ); return image; } private static BufferedImage copyBufferedImage (BufferedImage source) { BufferedImage target = new BufferedImage(source.getWidth(), source.getHeight(), source.getType()); Graphics g = target.getGraphics(); g.drawImage(source, 0, 0, null); return target; } public static void readImage(){ final String dir = "data/"; final String dir1 = "/home/arijit/Documents/TAFOLDERSPRING10/siftpp/data/"; //ABOVE, ENTER THE NAME OF THE DIRECTORY WHERE WE HAVE THE IMAGES System.out.println ("Enter the first image file name:"); Scanner scan = new Scanner (System.in); filename1 = scan.next(); String str1 = new String(dir+filename1+".pgm"); File file1 = new File(dir1+filename1+".jpg"); File file1rgb = new File(dir1+filename1+"-rgb.jpg"); System.out.println ("Enter the second image file name(this one will be augmented to the end of the first image):"); filename2 = scan.next(); String str2 = new String(dir+filename2+".pgm"); File file2 = new File(dir1+filename2+".jpg"); File file2rgb = new File(dir1+filename2+"-rgb.jpg"); try { img1 = ImageIO.read(file1); } catch (IOException e) {System.out.println("Image1 not read"); } try { img2 = ImageIO.read(file2); } catch (IOException e) {System.out.println("Image2 not read"); } try { img1_rgb = ImageIO.read(file1rgb); } catch (IOException e) {System.out.println("Image1-rgb not read"); } try { img2_rgb = ImageIO.read(file2rgb); } catch (IOException e) {System.out.println("Image2-rgb not read"); } try{ Runtime rt = Runtime.getRuntime(); String[]callAndArgs={"./glx/sift", str1}; File f=new File("/home/arijit/Documents/TAFOLDERSPRING10/siftpp/"); //ENTER THE siftpp directory path above Process proc=rt.exec(callAndArgs,null,f); System.out.println("I am readimg image1"); InputStream inputstream = proc.getInputStream(); InputStreamReader inputstreamreader = new InputStreamReader(inputstream); BufferedReader bufferedreader = new BufferedReader(inputstreamreader); String line; while ((line = bufferedreader.readLine()) != null) { System.out.println(line); } System.out.println("I have read image1"); } catch(Exception e){System.out.println("I am in catch block");} try{ Runtime rt = Runtime.getRuntime(); String[]callAndArgs={"./glx/sift", str2}; File f=new File("/home/arijit/Documents/TAFOLDERSPRING10/siftpp/"); //ENTER THE siftpp directory path above Process proc=rt.exec(callAndArgs,null,f); System.out.println("I am now reading image2"); // put a BufferedReader on the ls output InputStream inputstream = proc.getInputStream(); InputStreamReader inputstreamreader = new InputStreamReader(inputstream); BufferedReader bufferedreader = new BufferedReader(inputstreamreader); // read the ls output String line; while ((line = bufferedreader.readLine()) != null) { System.out.println(line); } System.out.println("I have read image2"); } catch(Exception e){System.out.println("I am in catch block");} } static double[][] readFile(String filename) throws IOException { double temp_arr[][]=new double[SIFT_MAX][132]; int i=0,j=0; Reader r = new BufferedReader(new FileReader(filename)); StreamTokenizer stok = new StreamTokenizer(r); stok.parseNumbers(); double sum = 0; stok.nextToken(); while (stok.ttype != StreamTokenizer.TT_EOF) { if (stok.ttype == StreamTokenizer.TT_NUMBER) { sum += stok.nval; temp_arr[i][j]=stok.nval; //System.out.println(temp_arr[i][j]); j++; if(j==132) {j=0;i++;} } else System.out.println("Nonnumber: " + stok.sval); stok.nextToken(); } no_sift=i; return temp_arr; } public static void main(String[] arg)throws IOException{ for(int i=0;i