Print

Print


Commit in CDMS/src/CDMS/ImageNavigatorII on MAIN
Stitcher.java+44-251.6 -> 1.7
first (test) run with flat field averaging, to be run on IZipG47_Side1_TES

CDMS/src/CDMS/ImageNavigatorII
Stitcher.java 1.6 -> 1.7
diff -u -r1.6 -r1.7
--- Stitcher.java	3 Aug 2010 19:32:05 -0000	1.6
+++ Stitcher.java	3 Aug 2010 22:18:16 -0000	1.7
@@ -1,7 +1,5 @@
 package CDMS.ImageNavigatorII;
 
-import java.awt.Graphics2D;
-import java.awt.geom.AffineTransform;
 import java.awt.image.*;
 import java.io.*;
 import javax.imageio.ImageIO;
@@ -18,6 +16,7 @@
  * 
  * File Structure:
  * 	>Image Set Folder
+ * 		>info.txt [file created by Stitcher to transfer data to Tiler]
  * 		>gmapviewer.htm	[the website navigator file!]
  * 		>resources	[do not touch these files, they are used by the Google API for the navigator]
  * 		>stitched_images	[stitched images will be saved here]
@@ -30,12 +29,13 @@
     public static void main(String[] args) throws IOException {
     	Date startDate = new Date();
 		//read in the file and create a list of command lines (split by SET_PART_REPEAT)(dont use arg 0)
-	    String imagePath = "/nfs/farm/g/ee/u15/cdms/CDMS_ImageNavigator/IZipG47_Side2_Al/";
-    	String savePath = "/nfs/farm/g/ee/u15/cdms/CDMS_ImageNavigatorII/IZipG47_Side2_Al/";
-	    String autorunFile = "Autorun_IZipG47_Side2_Al_23July10.txt";
-    	String imageFileName = "/"+"IZipG47_Side2_Al-#.png";
+	    String imagePath = "/nfs/farm/g/ee/u15/cdms/CDMS_ImageNavigator/IZipG47_Side1_TES/";
+    	String savePath = "/nfs/farm/g/ee/u15/cdms/CDMS_ImageNavigatorII/IZipG47_Side1_TES/";
+	    String autorunFile = "Autorun_IZipG47_Side1_TES_29July10.txt";
+    	String imageFileName = "/"+"IZipG47_Side1_TES-#.png";
         double theta = Math.atan(2/640);
 	    double pxSize = 1.397/1000;	//x75.3 magnification: 5.452um | x293 magnification: 1.397um
+	    int[] blanks = {4032,4040,7852,895,8313};
     	
 		String[] lines = getLines(imagePath+"/"+autorunFile);
 	    
@@ -68,15 +68,37 @@
         int tileH = 2048;
         double dX = moveX.get(0)/pxSize;
         double dY = (ymins.get(0)-ymins.get(1))/pxSize;
-        //find size of image holder and make holder
-        int holderW = (int)Math.ceil(imgW*Math.cos(theta)+imgH*Math.sin(theta));
-        int holderH = (int)Math.ceil(imgW*Math.sin(theta)+imgH*Math.cos(theta));
-        BufferedImage holder = new BufferedImage(holderW, holderH, image.getType());
         //find size of total stitched image
 	    double totalW = (maxCols-1)*dX + imgW*Math.cos(theta) + imgH*Math.sin(theta);
 	    double totalH = (lines.length-1)*dX + imgW*Math.sin(theta) + imgH*Math.cos(theta);
-        AffineTransform at;
 	    /*********************/
+	    
+	    //make flat field matrix averaging matrix
+	    int[][][] ff = new int[imgW][imgH][3];
+	    int rTot=0, gTot=0, bTot=0;
+	    for (int x=0; x<imgW; x++) {
+	    	for (int y=0; y<imgW; y++) {
+	    		int r=0, g=0, b=0;
+		    	for (int i=0;i<blanks.length; i++) {
+		    		image = ImageIO.read(new File(imagePath+"/"+imageFileName.replace("#",""+blanks[i])));
+    	            WritableRaster raster = image.getRaster();
+    	            r += raster.getSample(x, y, 0);
+    	            g += raster.getSample(x, y, 1);
+    	            b += raster.getSample(x, y, 2);
+		    	}
+		    	rTot += r;
+		    	gTot += g;
+		    	bTot += b;
+		    	ff[x][y][0] = Math.round(r/blanks.length);
+		    	ff[x][y][1] = Math.round(g/blanks.length);
+		    	ff[x][y][2] = Math.round(b/blanks.length);
+		    }
+	    }
+	    double rAvg = rTot/(imgW*imgH*blanks.length);
+	    double gAvg = gTot/(imgW*imgH*blanks.length);
+	    double bAvg = bTot/(imgW*imgH*blanks.length);
+	    
+	    //loop through all large tiles of stitched images
         for (int row=0;row<Math.ceil(totalH/tileH); row++) {
         	for (int col=0;col<Math.ceil(totalW/tileW); col++) {
         		System.out.println("new tile("+row+","+col+")");
@@ -86,9 +108,9 @@
         		BufferedImage toStore = new BufferedImage(tileW, tileH, image.getType());
         		WritableRaster toStoreRaster = toStore.getRaster().createCompatibleWritableRaster();
         		int[][] layers = new int[tileW][tileH];
-	            Graphics2D g2 = holder.createGraphics();
         		int lastImage = 0;
         		boolean draw = false;
+        		//loop through all images using cols and rows from the autorun file
         		for (int r=0; r<lines.length-1; r++) {
         	    	int nCols = cols.get(r)+1;
         	    	for (int c=0; c<nCols; c++) {
@@ -103,14 +125,12 @@
         	    		//if it is in the tile, make a square with the image tilted appropriately
         	        	if (drawX>minTileRenderX && drawX<maxTileRenderX && drawY>minTileRenderY && drawY<maxTileRenderY) {
     	        			image = ImageIO.read(new File(imagePath+"/"+imageFileName.replace("#",""+lastImage)));
-            	    		at = AffineTransform.getTranslateInstance(0, 0);
-            	            g2.drawRenderedImage(image, at);
             	            
-            	            WritableRaster holderRaster = holder.getRaster();
+            	            WritableRaster imgRaster = image.getRaster();
 	            	        
-            	            //write the square with the tilted image to toStore, averaging with any values already there
-            	            for (int y=0; y < holderH; ++y) {
-            	            	for (int x=0; x < holderW; ++x) {
+            	            //write the image to toStore, averaging with any values already there (for each cell write to pixel)
+            	            for (int y=0; y < imgH; ++y) {
+            	            	for (int x=0; x < imgW; ++x) {
             	            		int drawXtoStore = (int)Math.round(drawX-col*tileW+x);
 	            	                int drawYtoStore = (int)Math.round(drawY-row*tileH+y);
 	            	                if (drawXtoStore > 0 && drawXtoStore < tileW && drawYtoStore > 0 && drawYtoStore < tileH) {
@@ -118,14 +138,14 @@
 		            	                double sumG = toStoreRaster.getSample(drawXtoStore, drawYtoStore, 1);
 		            	                double sumB = toStoreRaster.getSample(drawXtoStore, drawYtoStore, 2);
 		            	                int z = layers[drawXtoStore][drawYtoStore];
-		            	                sumR = (z*sumR + holderRaster.getSample(x, y, 0))/(z+1);
-		            	                sumG = (z*sumG + holderRaster.getSample(x, y, 1))/(z+1);
-		            	                sumB = (z*sumB + holderRaster.getSample(x, y, 2))/(z+1);
+		            	                sumR = (z*sumR + imgRaster.getSample(x, y, 0))/(z+1);
+		            	                sumG = (z*sumG + imgRaster.getSample(x, y, 1))/(z+1);
+		            	                sumB = (z*sumB + imgRaster.getSample(x, y, 2))/(z+1);
 		            	                layers[drawXtoStore][drawYtoStore]++;
 		            	                if(sumR!=0 || sumG!=0 || sumB!=0) draw=true;
-	            	            		toStoreRaster.setSample(drawXtoStore, drawYtoStore, 0, sumR);
-	            	            		toStoreRaster.setSample(drawXtoStore, drawYtoStore, 1, sumG);
-	            	            		toStoreRaster.setSample(drawXtoStore, drawYtoStore, 2, sumB);
+	            	            		toStoreRaster.setSample(drawXtoStore, drawYtoStore, 0, sumR*rAvg/ff[x][y][0]);
+	            	            		toStoreRaster.setSample(drawXtoStore, drawYtoStore, 1, sumG*gAvg/ff[x][y][1]);
+	            	            		toStoreRaster.setSample(drawXtoStore, drawYtoStore, 2, sumB*bAvg/ff[x][y][2]);
 	            	                }
             	            	}
             	            }
@@ -134,7 +154,6 @@
         	        }
         	    }
         		if (draw==true) ImageIO.write(toStore, "PNG", new File(savePath+"/stitched_images/"+row+"_"+col+".png"));
-        		g2.dispose();
         	}
         }
 
CVSspam 0.2.8