www.pudn.com > img_process_java.zip > AffineShape.java
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import java.awt.event.*;
import java.util.*;
import java.lang.Math;
import java.awt.Frame;
import javax.media.jai.*;
import javax.media.jai.JAI;
import java.io.IOException;
import java.lang.reflect.Array;
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.*;
import javax.media.jai.widget.ImageCanvas;
import java.awt.geom.*;
public class AffineShape
{
//Usage: java AffineShape
//e.g. java AffineShape shapeindex\shape\*.* | circle.jpg
public static void main(String[] args)
{
float x_scale[] = {0.8f, 0.8f, 1.1f, 0.6f};
float x_shear[] = {0.5f, 0.2f, 0.2f, 0.0f};
float y_scale[] = {1.0f, 1.1f, 0.8f, 0.6f};
float y_shear[] = {0.2f, -0.3f, -0.4f, 0.0f};
StringTokenizer stk;
String outputFile;
AffineTransformShape afs = null;
for (int n = 0; n < args.length; n++)
{
afs = new AffineTransformShape(args[n]);
System.out.println("\ninput image: " + args[n]);
stk = new StringTokenizer(args[n], ".");
outputFile = stk.nextToken() + "_";
for(int i=0; i<4; i++)
afs.affine(x_scale[i], x_shear[i], y_shear[i], y_scale[i], outputFile+i);
afs.flip(outputFile+4);
afs.mirror(outputFile+5);
}
System.exit(0);
}
}
class AffineTransformShape
{
int data1[][]; //original shape image
int data2[][]; //processed shape image
public int Xdim, Ydim, Xdim_copy, Ydim_copy;
Vector coordinates;
Vector copy_coord = new Vector();
Vector recCoordinates; //Fourier reconstructed shape coordinates
int perimeter;
int perimeter_copy;
Image image;
String filename;
FileOutputStream stream;
public AffineTransformShape(String filename)
{
this.filename = filename;
getImageData(filename);
//thresholding(); //thresholding gray leve image into black and white
preProcessing();
contour();
//make copies of original shape feature
copy_coord = coordinates;
perimeter_copy = perimeter;
Xdim_copy = Xdim;
Ydim_copy = Ydim;
}
//display image of default format--.gif and .jpg
void getImageData(String filename)
{
int pixels[];//to hold real pixel values;
PixelGrabber grabber = null;
PlanarImage planarImage = JAI.create("fileload", filename);
image = planarImage.getAsBufferedImage(); //planar image to awt image
Xdim = planarImage.getWidth();
Ydim = planarImage.getHeight();
pixels = new int[Xdim*Ydim];
data1 = new int[Ydim+10][Xdim+10]; //two dim buffer for processing convenience in shape
for(int y=0; y 200) //thresholding
data1[y][x] = 0;
else
data1[y][x] = 255;
//get rid of isolated noise points
for(y=5; y max_x)
max_x = data_x[i];
if(data_y[i]max_y)
max_y = data_y[i];
}
if(min_x>5) min_x -= 5;
if(min_y>5) min_y -= 5;
max_x += 5; max_y += 5;
//System.out.println("\nupper left of the shape: " + min_x + ", " + min_y );
//System.out.println("\nbottom right of the shape: " + max_x + ", " + max_y );
Xdim = max_x-min_x;
Ydim = max_y-min_y;
//System.out.println("\nnew image size: " + Xdim + ", " + Ydim + "\n");
Polygon pg = new Polygon(data_x, data_y, perimeter_copy);
//creating a silhouette of the shape
for(y=min_y; y=0)?((y+dy[i])%Ydim):(Ydim-y-dy[i])]
[((x+dx[i])>=0)?((x+dx[i])%Xdim):(Xdim-x-dx[i])] == 0)
neib++;
//System.out.print(neib + ", ");
if(neib<4)
data2[y][x] = 255;
}
}
*/
contour(); //trancing filled shape to get connected boundary
new_perimeter = coordinates.size();
for(y=0; y