www.pudn.com > img_process_java.zip > ShapeIndex.java


import java.io.*; 
import java.net.URL; 
import javax.media.jai.*; 
import java.net.MalformedURLException; 
import java.lang.Math; 
import java.io.Serializable; 
import java.lang.reflect.Array; 
import java.lang.Math; 
import java.awt.Frame; 
import javax.media.jai.JAI; 
import java.io.IOException; 
import java.awt.image.ColorModel; 
import javax.media.jai.iterator.*; 
import java.awt.image.renderable.ParameterBlock; 
import com.sun.media.jai.codec.FileSeekableStream; 
import javax.media.jai.widget.ScrollingImagePanel; 
                       
public class ShapeIndex 
{ 
   public static void main(String[] args) 
   { 
      ObjectInputStream fileIn=null; 
      ObjectOutputStream fileOut=null; 
 
      AddShapeElement imgIndex=new AddShapeElement(5,6); 
 
      for (int i = 1; i < args.length; i++) 
      { 
         URL url=null; 
          
         try {url=new URL(args[0] + "/" + args[i].replace('\\', '/'));} 
         catch (MalformedURLException e) {} 
 
         PlanarImage img=JAI.create("fileload", args[i]); 
		 ShapeFeature sf = new ShapeFeature(img); 
         float feat[]= sf.FD; 
         ShapeElement imgFeat=new ShapeElement(feat, url); 
         imgIndex.addIndex(imgFeat); 
 
         System.out.println(url); 
      } 
 
      try 
      { 
         fileOut=new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream("texture.dat"))); 
         fileOut.writeObject(imgIndex); 
         System.out.println("Data has been saved to file."); 
      } 
      catch (Exception e) 
      { 
         System.out.println("Error encountered while writing file."); 
      } 
      try 
      { 
         fileOut.close(); 
      } 
      catch (Exception e) {} 
 
   } 
} 
 
class ShapeElement implements Serializable 
{ 
   private float Feature[]; 
   private URL imgURL; 
 
   public ShapeElement(float newFeature[], URL newURL) 
   { 
      imgURL=newURL; 
      Feature=newFeature; 
   } 
 
   public float[] getFeature() 
   { 
      return(Feature); 
   } 
 
   public URL getURL() 
   { 
      return imgURL; 
   } 
 
   public void setFeature(float newFeature[]) 
   { 
      Feature=newFeature; 
   } 
 
   public void setURL(URL newURL) 
   { 
      imgURL=newURL; 
   } 
 
   public double getDistance(ShapeElement imgFeature) 
   { 
      if (Array.getLength(Feature)==Array.getLength(imgFeature.getFeature())) 
      { 
         double distance=0; 
         for (int i=0;i1) 
            for (int i=0;i