/* Threshold: extract 3D coordinates below a given grayscale value from a set of images First Use: Compile with: javac Threshold.java Use: java Threshold > Copyright (C) 2008 Ruggero Scorcioni (rscorcio at gmu dot edu) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ import java.awt.image.*; import java.io.*; import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; import java.lang.Math.*; public class Threshold { //set max output size public static final int MAXPOINT=10000; //thickness in pixel of each section public static final int ZJUMP=10; Image img; int imgX=0,imgY=0; int[] pixel; static int st,en,th; //return the color of pixel at coord x,y public int pixelValue( int x, int y) { return pixel[x+imgX*y]; } //load all pixels into the 'pixel' array public void readJPG(String name){ int color; try { img = Toolkit.getDefaultToolkit().getImage(name); PixelGrabber grabber = new PixelGrabber(img, 0, 0, -1, -1, false); if (grabber.grabPixels()) { imgX = grabber.getWidth(); imgY = grabber.getHeight(); pixel = (int[]) grabber.getPixels(); } } catch (Exception e) { System.err.println(e.getMessage()); } } public void extractPixel(){ int r,g,b,gr,alpha,c,count=0,ratio=0; //2 iterations: first to compute how many pixel available and // second to print for(int i=0;i<2;i++){ if(i==1){ //at second iteration compute the correct sampling ratio ratio=count/MAXPOINT+1; if(ratio<=0){ ratio=1; } } for(int l=st;l<=en;l++){ System.err.print(l+" "); //load all pixel from one image readJPG("_oi7_aligned."+l+".png"); for(int x=0;x> 16) & 0xff; g = (c >> 8) & 0xff; b = c & 0xff; alpha = (c >> 24) & 0xff; //compute grayscale value gr=(int)(0.3*r+0.59*g+0.11*b); if(gr0){ count++; //print 3D coord at correct sampling ratio at second iteration if(i==1 && (count % ratio)==0){ int z=l*ZJUMP; System.out.print(x+"\t"+y+"\t"+z+"\n"); } } } } } } } public static void main (String args[]) { String nam=args[0]; String nam2=args[1]; String nam3=args[2]; //start # image st=new Integer(nam).intValue(); //end # image en=new Integer(nam2).intValue(); //Threshold value th=new Integer(nam3).intValue(); Threshold t =new Threshold(); t.extractPixel(); } }