CDMS/src/CDMS/ImageNavigatorII
diff -u -r1.9 -r1.10
--- Stitcher.java 9 Sep 2010 16:11:11 -0000 1.9
+++ Stitcher.java 9 Dec 2010 19:43:03 -0000 1.10
@@ -36,6 +36,7 @@
String savePath = "/"+getArg(inFile, "save_path");
String autorunFile = getArg(inFile, "autorun_file");
String imageFileName = "/"+getArg(inFile, "image_name");
+ double theta = 0; try {theta = Double.parseDouble(getArg(inFile,"theta")); } catch (Exception e) {}
double pxSize = 0.001397; try {pxSize = Double.parseDouble(getArg(inFile,"pixel_size")); } catch (Exception e) {}
String[] blanksList = getArg(inFile, "blanks").split(",");
int[] blanks = new int[blanksList.length];
@@ -44,9 +45,7 @@
}
int tileW = 2048; try{tileW = Integer.parseInt(getArg(inFile, "tile_width"));} catch (Exception e) {}
int tileH = 2048; try{tileH = Integer.parseInt(getArg(inFile, "tile_height"));} catch (Exception e) {}
-
- String outFile = "";
-
+
//read in the file and create a list of command lines (split by SET_PART_REPEAT)(dont use arg 0)
String[] lines = getLines(imagePath+"/"+autorunFile,"SET_PART_REPEAT");
@@ -78,8 +77,8 @@
double dX = moveX.get(0)/pxSize;
double dY = (ymins.get(0)-ymins.get(1))/pxSize;
//find size of total stitched image
- double totalW = (maxCols-1)*dX + imgW;
- double totalH = (lines.length-1)*dX + imgH;
+ 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);
/*********************/
//make flat field matrix averaging matrix
@@ -132,9 +131,6 @@
int[][] layers = new int[tileW][tileH];
int lastImage = 0;
boolean draw = false;
- boolean foundCenter = false;
- String centerX = "n/a";
- String centerY = "n/a";
//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;
@@ -144,20 +140,13 @@
double maxTileRenderX = (col+1)*tileW+imgW;
double minTileRenderY = row*tileW-imgH;
double maxTileRenderY = (row+1)*tileW+imgH;
- double drawX = c*dX+(xmins.get(r)-xMin)/pxSize;
- double drawY = r*dY;
+ double drawX = c*dX*Math.cos(theta)+(xmins.get(r)-xMin)/pxSize;
+ double drawY = r*dY+c*dX*Math.sin(theta);
lastImage++;
//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)));
WritableRaster imgRaster = image.getRaster();
-
- //find coordinates of center of tile
- if (foundCenter == false) {
- centerX = ""+( (xmins.get(r)/pxSize+c*dX) - (drawX-col*tileW) + tileW/2 );
- centerY = ""+( ymins.get(r) - (drawY-row*tileH) +tileH/2 );
- foundCenter = true;
- }
//write the image to toStore, averaging with any values already there (for each cell write to pixel)
for (int y=0; y < imgH; ++y) {
@@ -185,7 +174,6 @@
}
}
if (draw==true) ImageIO.write(toStore, "PNG", new File(savePath+"/stitched_images/"+row+"_"+col+".png"));
- outFile += (""+row+"_"+col+"\t"+centerX+"\t"+centerY+"\n");
}
}
@@ -193,11 +181,6 @@
System.out.println("\nRuntime: "+(endDate.getTime()-startDate.getTime())/1000/60);
//writes data needed for Tiler.java to info.txt
try {
- BufferedWriter outprint = new BufferedWriter(new FileWriter(savePath+"/out.txt"));
- outprint.write(outFile);
- outprint.close();
- } catch (IOException e) {System.out.println("Could not create out.txt:\n"+e);}//writes stats about each tile to out.txt
- try {
BufferedWriter outprint = new BufferedWriter(new FileWriter(savePath+"/info.txt"));
outprint.write(Math.ceil(totalW/tileW)+"\n"+Math.ceil(totalH/tileH)+"\n"+tileW+"\n"+tileH+"\n"+savePath);
outprint.close();
CDMS/src/CDMS/ImageNavigatorII
diff -u -r1.5 -r1.6
--- Tiler.java 30 Jul 2010 23:32:09 -0000 1.5
+++ Tiler.java 9 Dec 2010 19:43:03 -0000 1.6
@@ -22,6 +22,8 @@
*
* File Structure:
* >Image Set Folder
+ * >info.txt [file created by Stitcher to transfer data to Tiler]
+ * >input.txt [lots of parameters you can set]
* >gmapviewer.htm [the website navigator file!]
* >original_images [place the autorun.txt file and images in this folder before running Stitcher.java]
* >resources [do not touch these files, they are used by the Google API for the navigator]
@@ -34,13 +36,15 @@
public class Tiler {
public static void main(String[] args) throws IOException {
Date startDate = new Date();
+ //read input.txt and get values from args
+ String[] inFile = getLines("./input.txt","\n");
+ String path = "/"+getArg(inFile, "save_path");
+ int tileW = 2048; try{tileW = Integer.parseInt(getArg(inFile, "tile_width"));} catch (Exception e) {}
+ int tileH = 2048; try{tileH = Integer.parseInt(getArg(inFile, "tile_height"));} catch (Exception e) {}
- String[] lines = getLines("./info.txt");
- int numXimgs = Integer.parseInt(lines[0]);
- int numYimgs = Integer.parseInt(lines[1]);
- int imgW = Integer.parseInt(lines[2]);
- int imgH = Integer.parseInt(lines[3]);
- String path = lines[4];
+ String[] lines = getLines("./info.txt", "\n");
+ int numXimgs = (int)Double.parseDouble(lines[1]);
+ int numYimgs = (int)Double.parseDouble(lines[2]);
/*String path = "/nfs/farm/g/ee/u15/cdms/CDMS_ImageNavigatorII/wilenc/IZipG47_Side1_Al/";
int numXimgs = 27;
@@ -67,15 +71,15 @@
//get info on imgs
//BufferedImage img = ImageIO.read(new File(path+"/stitched_images/"+"/0_0.png"));
- //int imgW = img.getWidth();
- //int imgH = img.getHeight();
+ //int tileW = img.getWidth();
+ //int tileH = img.getHeight();
//find max zoom level
double totalSize = 10000;
int maxZoom = 0;
while (totalSize > tileSize) {
maxZoom++;
- totalSize = Math.max(imgW*numXimgs, imgH*numYimgs)/Math.pow(2, maxZoom);
+ totalSize = Math.max(tileW*numXimgs, tileH*numYimgs)/Math.pow(2, maxZoom);
}
System.out.println("Max Zoom Level: "+maxZoom);
@@ -86,8 +90,8 @@
FileWriter fstream = new FileWriter(path+"/tiles/detectorTiles.txt");
BufferedWriter outFile = new BufferedWriter(fstream);
String outText = "name\tdetectorTiles"+
- "\r\nwidth\t"+(numXimgs*imgW)+
- "\r\nheight\t"+(numYimgs*imgH)+
+ "\r\nwidth\t"+(numXimgs*tileW)+
+ "\r\nheight\t"+(numYimgs*tileH)+
"\r\nmaxzoom\t"+maxZoom+
"\r\ntilesize\t"+tileSize+
"\r\nscale\t"+(int)scale+
@@ -100,8 +104,8 @@
//loop through all zoom levels
for (int zoom=lowestZoom; zoom<=maxZoom; zoom++) {
- double totalW = imgW*numXimgs/Math.pow(2, maxZoom-zoom);
- double totalH = imgH*numYimgs/Math.pow(2, maxZoom-zoom);
+ double totalW = tileW*numXimgs/Math.pow(2, maxZoom-zoom);
+ double totalH = tileH*numYimgs/Math.pow(2, maxZoom-zoom);
int numXtiles = (int)Math.ceil(totalW/tileSize);
int numYtiles = (int)Math.ceil(totalH/tileSize);
//loop through all the tiles for specified zoom level, continuing for only ones in the specified thread
@@ -117,15 +121,15 @@
for (int xImg=0; xImg<numXimgs; xImg++) {
//does the img belong in the tile?
double scaleFactor = 1/Math.pow(2, maxZoom-zoom);
- int xpos = (int)Math.ceil(xImg*imgW*scaleFactor)-col*tileSize;
- int ypos = (int)Math.ceil(yImg*imgH*scaleFactor)-row*tileSize;
- if (xpos>=(-imgW*scaleFactor) && xpos<tileSize && ypos>=(-imgH*scaleFactor) && ypos<tileSize) {
+ int xpos = (int)Math.ceil(xImg*tileW*scaleFactor)-col*tileSize;
+ int ypos = (int)Math.ceil(yImg*tileH*scaleFactor)-row*tileSize;
+ if (xpos>=(-tileW*scaleFactor) && xpos<tileSize && ypos>=(-tileH*scaleFactor) && ypos<tileSize) {
BufferedImage img;
try {
img = ImageIO.read(new File(path+"/stitched_images/"+yImg+"_"+xImg+".png"));
draw = true;
} catch (Exception e) {
- img = new BufferedImage(imgW,imgH,BufferedImage.TYPE_INT_RGB);
+ img = new BufferedImage(tileW,tileH,BufferedImage.TYPE_INT_RGB);
}
AffineTransform at = AffineTransform.getTranslateInstance(0, 0);
at.setTransform(scaleFactor, 0, 0, scaleFactor, xpos, ypos);
@@ -147,9 +151,38 @@
Date endDate = new Date();
System.out.println("\nRuntime: "+(endDate.getTime()-startDate.getTime())/1000/60);
}
+
+
- //takes an input path and returns a list of values split by the SET_PART-REPEAT
- public static String[] getLines(String path) {
+ //takes an input of lines, searches through them for the desired argument name, and returns its value
+ public static String getArg(String[] lines, String argument) {
+ String arg = null;
+ for (int line=0; line<lines.length; line++) {
+ String[] lineText = lines[line].replaceAll(" ", "").split("\t");
+ int i=0;
+ boolean next = false;
+ while (true) {
+ String token = "";
+ try {
+ token = lineText[i];
+ } catch (Exception e) { break; }
+ if (token.indexOf('#')!=-1) {
+ token = token.substring(0,token.indexOf('#'));
+ break;
+ }
+ if (token.equals( argument) ) next = true;
+ else if (!token.equals("") && next==true) {
+ arg = token;
+ break;
+ }
+ i++;
+ }
+ }
+ return arg;
+ }
+
+ //takes an input path and returns a list of values split by the SET_PART-REPEAT
+ public static String[] getLines(String path, String splitPhrase) {
try {
BufferedReader in = new BufferedReader(new FileReader(path));
String str;
@@ -158,8 +191,9 @@
text += "\n"+str;
}
in.close();
- String[] lines = text.split("SET_PART_REPEAT");
+ String[] lines = text.split(splitPhrase);
return lines;
- } catch (IOException e) {System.out.println("File could not be read"); return null;}
+ } catch (IOException e) {System.out.println("File could not be read:\n"+e); return null;}
}
+
}