package ip.gabor;
import ip.gui.NumImage;
import ip.gui.ConvolutionUtils;
import java.awt.*;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import futils.Out;
import graphics.ImageUtils;
public class FilterCanvas extends Canvas {
private Image image;
private short g[][];
public FilterCanvas(Image img) {
image = img;
this.setSize(image.getWidth(this), image.getHeight(this));
g = graphics.ImageUtils.getGreenFromImage(image, this);
}
public FilterCanvas() {
image = NumImage.getImage();
setSize(image.getWidth(this), image.getHeight(this));
g = graphics.ImageUtils.getGreenFromImage(image, this);
}
public int getGreenValueAt(Point p) {
int x = p.x;
int y = p.y;
if (x >= g.length) x = g.length - 1;
if (y >= g[0].length) y = g[0].length - 1;
if (x < 0) x = 0;
if (y < 0) y = 0;
return g[x][y];
}
public void drawImage() {
this.repaint();
}
public Image getImage() {
return image;
}
public void setImage(Image img) {
image = img;
setSize(image.getWidth(this), image.getHeight(this));
g = graphics.ImageUtils.getGreenFromImage(image, this);
}
public void paint(Graphics graphics) {
if (image != null)
graphics.drawImage(image, 0, 0, getWidth(), getHeight(), this);
}
public void convolution(Image img, float k[][]) {
short orig[][] = graphics.ImageUtils.getGreenFromImage(img, this);
orig = ConvolutionUtils.convolve(orig, k);
image = graphics.ImageUtils.getImageFromShort(orig);
setSize(image.getWidth(this), image.getHeight(this));
repaint();
}
public void saveAsJava(File f) {
try {
FileWriter fw =
new FileWriter(f);
PrintWriter pw =
new PrintWriter(fw);
Out.saveAsJava(pw, image, this);
pw.flush();
fw.close();
} catch (Exception e) {
}
}
}