C:\ece595_06\class16>java Demo1 convolution mask 1 2 1 2 4 2 1 2 1 Elapsed time 1.29632 milliseconds Elapsed time 1.83318 milliseconds My Convolve 5 23 46 69 92 116 139 162 185 209 226 5 23 51 88 121 141 152 165 185 209 226 5 29 80 142 185 196 187 180 188 209 226 5 46 129 199 226 228 218 201 195 209 226 5 62 165 224 232 232 229 215 200 209 226 5 62 165 224 232 232 229 215 200 209 226 5 46 129 199 226 228 218 201 195 209 226 5 29 80 142 185 196 187 180 188 209 226 5 23 51 88 121 141 152 165 185 209 226 5 23 46 69 92 116 139 162 185 209 226 5 23 46 69 92 116 139 162 185 209 226 ConvolveOp 0 0 0 0 0 0 0 0 0 0 0 0 23 51 88 121 141 152 165 185 209 0 0 29 80 142 185 196 187 180 188 209 0 0 46 129 199 226 228 218 201 195 209 0 0 62 165 224 232 232 229 215 200 209 0 0 62 165 224 232 232 229 215 200 209 0 0 46 129 199 226 228 218 201 195 209 0 0 29 80 142 185 196 187 180 188 209 0 0 23 51 88 121 141 152 165 185 209 0 0 23 46 69 92 116 139 162 185 209 0 0 0 0 0 0 0 0 0 0 0 0
C:\ece595_06\class16>java Demo1 bld.jpg convolution mask 1 2 1 2 4 2 1 2 1 Elapsed time 63.1925 milliseconds Elapsed time 12.3867 milliseconds
original image | Grayscale filter | ConvolveOp filter |
Demo1.java
import java.awt.image.*; import java.awt.color.*; import java.io.*; import javax.imageio.*; import javax.swing.JFrame; public class Demo1 { public static void main(String [] args) { String filename = "test3.png"; if (args.length>0) filename = args[0]; showImage f1 = new showImage(filename); f1.setLocation(10,10); f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); int w = f1.getWidth(); int h = f1.getHeight(); int mask[][] = { {1, 2, 1},{2, 4, 2},{1, 2, 1} }; Convolve c = new Convolve(mask); c.setScale(16); c.showMatrix(mask,"convolution mask"); long start = System.nanoTime(); BufferedImage out1 = c.doConvolve(f1.img); long etime = System.nanoTime() - start; double elapsed_time = 1e-6*(double)etime; System.out.format("%nElapsed time %g milliseconds%n",elapsed_time); showImage f2 = new showImage(out1,"my Convolve"); f2.setLocation(200,10); float [] fm = {0.0625f, 0.125f, 0.0625f, 0.125f, 0.250f, 0.125f, 0.0625f, 0.125f, 0.0625f}; Kernel k = new Kernel(3, 3, fm); ConvolveOp op = new ConvolveOp(k, ConvolveOp.EDGE_ZERO_FILL, null); /* * EDGE_NO_OP * Pixels at the edge of the source image are copied to the corresponding pixels in the destination without modification. * * EDGE_ZERO_FILL * Pixels at the edge of the destination image are set to zero. */ start = System.nanoTime(); BufferedImage out2 = op.filter(f1.img, null); etime = System.nanoTime() - start; elapsed_time = 1e-6*(double)etime; System.out.format("%nElapsed time %g milliseconds%n",elapsed_time); showImage f3 = new showImage(out2,"ConvolveOp"); f3.setLocation(10,200); if (args.length==0) { listImage.listGray(f2.img,"My Convolve"); listImage.listGray(f3.img,"ConvolveOp"); } else { f2.writeImage("demo1a","jpg"); f3.writeImage("demo1b","jpg"); } } }
Maintained by John Loomis, updated Tue Oct 15 16:04:51 2013