CDMS/src/CDMS/swiatlow/ImageMapperII
diff -u -r1.4 -r1.5
--- ImageMapperII.java 2 Apr 2011 07:09:02 -0000 1.4
+++ ImageMapperII.java 13 Apr 2011 09:31:01 -0000 1.5
@@ -1,7 +1,9 @@
package CDMS.swiatlow.ImageMapperII;
+import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
+import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
@@ -17,8 +19,7 @@
public class ImageMapperII {
- private static final int INTERESTING_CUT = 10;
- private static final boolean LEVELLING_ON = false;
+ private static final int INTERESTING_CUT = 1;
private static final double pixWidth = 45.0;
private static final double pixHeight = 33.0;
@@ -33,17 +34,28 @@
private int nPixWidth;
private int nPixHeight;
+ private double xOffset;
+ private double yOffset;
+
+
private boolean[][] flag;
private BufferedImage image;
private BufferedWriter output;
+ private boolean doLowRes;
+ private String lowRes;
+
private int debug;
private int dPrintCounter=1;
- private static final int dPrint=0;
+ private int dPrint;
+ String outFolderBroken;
public ImageMapperII(String imageFile, String outFile, int debugFlag) throws IOException{
+ dPrint = 0;
+ doLowRes = false;
+ outFolderBroken = "/Users/maxinion/Documents/Work/CDMS/imagingII/out2-28/broken/";
//initialize variables, say hello
System.out.println("Welcome to CDMS ImageMapperII!\nI'll create a image map file from the inputted" +
@@ -71,6 +83,75 @@
System.out.println("nPixWidth = " + nPixWidth + " and nPixHeight = " + nPixHeight);
}
+ yOffset = 0; xOffset = 0;
+
+ SetGridOffset();
+
+ }
+
+ public void enableLowRes(String fileName){
+ doLowRes = true;
+
+ lowRes = fileName;
+
+ }
+
+ private void addLowRes(){
+ // will only be called if lowRes is init and lowRes file is ready to go, hopefully
+ // read in the low res input file, copy it to the output file
+
+ System.out.println("Adding low resolution!");
+
+ try {
+ BufferedReader reader = new BufferedReader(new FileReader(lowRes));
+ String line = null;
+ while ((line=reader.readLine()) != null) {
+ output.write(line);
+ output.newLine(); // Write system dependent end of line.
+ }
+
+ } catch (IOException e) {
+ System.err.println(e);
+ System.exit(1);
+ }
+
+ }
+
+ //alternative longer constructor, with full debugbroken stuff
+ public ImageMapperII(String imageFile, String outFile, int debugFlag, int printBroken, String outBroken) throws IOException{
+ this(imageFile, outFile, debugFlag);
+ dPrint = printBroken;
+ outFolderBroken = outBroken;
+ }
+
+ private void SetGridOffset(){
+
+ double minxI;
+ double minyJ;
+ double minx = 10000000;
+ double miny = 10000000;
+
+ for(int i = 0; i < nPixWidth; i++){
+ for(int j =0; j < nPixHeight; j++){
+ double[] converted = convertCoords(pixWidth*i, pixHeight*j);
+ if(Math.abs(converted[0]) < Math.abs(minx)){
+ minxI = i;
+ minx = converted[0];
+ }
+ if(Math.abs(converted[1]) < Math.abs(miny)){
+ minyJ = j;
+ miny = converted[1];
+ }
+
+ }
+ }
+
+ xOffset = -minx;
+ yOffset = -miny;
+ if(debug==1){
+ System.out.println("X offset " + minx + " Y Offset " +miny);
+ }
+
}
public void doAll() throws IOException{
@@ -142,13 +223,8 @@
}// end for j
}// end for i
- // add the few field levelling images that we want (if we actually want levelling included)
- if(LEVELLING_ON){
- List<double[]> fl = getFieldLevellingImages();
- for(int k = 0; k < fl.size(); k++)
- writeCoord(fl.get(k));
- }
-
+
+ if(doLowRes==true && debug==0) addLowRes();// only add lowRes to non-debug run; would screw up csv
if(debug==0) output.write("END_RUN\n");
output.close();
}
@@ -164,22 +240,6 @@
else if(debug==1) output.write(fmt1+","+fmt2+"\n");
}
- private List<double[]> getFieldLevellingImages(){
- List<double[]> out = new ArrayList<double[]>();
- // this list is good only for iZIP4 geometry: modify for others
-
- double[] o1 = {15.0, 3.5};
- double[] o2 = {-18.5, 3.5};
- double[] o3 = {6.0, -18.0};
-
- out.add(o1);
- out.add(o2);
- out.add(o3);
-
- if(debug==1) System.out.println("Adding field levelling!");
-
- return out;
- }
private double[] convertCoords(double xc, double yc){
@@ -200,8 +260,8 @@
double[] out = new double[2];
- out[0] = xc;
- out[1] = yc;
+ out[0] = xc + xOffset;
+ out[1] = yc + yOffset;
return out;
@@ -227,14 +287,7 @@
if(nColorPix > INTERESTING_CUT){
if(debug==1){
if(dPrint==1){ // fun debugging tool
- try {
- File outputfile = new File("/Users/maxinion/Documents/Work/CDMS/imagingII/out2-28/broken/b"+dPrintCounter+".jpg");
- ImageIO.write(sub, "jpg", outputfile);
- System.out.println("There are " + nColorPix + " interesting pixels in image " +dPrintCounter);
- dPrintCounter++;
- } catch (IOException e) {
- System.out.println("error writing out broken images!");
- }
+ debugBreak(sub, nColorPix);
}
}
return true;
@@ -243,8 +296,18 @@
return false;
}
+ private void debugBreak(BufferedImage sub, int nColorPix){
+ try {
+ File outputfile = new File(outFolderBroken+"b"+dPrintCounter+".jpg");
+ ImageIO.write(sub, "jpg", outputfile);
+ System.out.println("There are " + nColorPix + " interesting pixels in image " +dPrintCounter);
+ dPrintCounter++;
+ } catch (IOException e) {
+ System.out.println("error writing out broken images!");
+ }
+ }
- public void roughStitch() throws IOException{
+ public void roughStitch(String inString, String outFile) throws IOException{
System.out.println("Doing the rough stitching!");
image = null; // kill the stored image for memory reasons
@@ -258,14 +321,14 @@
for(int j=0; j < nPixHeight-1; j++){
System.out.println("At " + i + " and " + j + ": flag is " + flag[i][j]);
if(flag[i][j]){
- String imageFile = "/Users/maxinion/Desktop/MaxScanTestL09FullII/MaxScanTestL09FullII-"+count+".BMP";
+ String imageFile = inString+count+".BMP";
BufferedImage read = ImageIO.read(new File( imageFile ));
System.out.println("Reading " + imageFile);
double scaleFactor = 1/14.3;
- int xpos = 45 * i;
- int ypos = 33 * j;
+ int xpos = (int) pixWidth * i;
+ int ypos = (int) pixHeight * j;
AffineTransform at = AffineTransform.getTranslateInstance(0, 0);
at.setTransform(scaleFactor, 0, 0, scaleFactor, xpos, ypos);
@@ -277,7 +340,7 @@
}
}
- File outputfile = new File("/Users/maxinion/Desktop/stitched.png");
+ File outputfile = new File(outFile);
ImageIO.write(stitched, "png", outputfile);
}
}