r = [200 0 0], g = [0 200 0]; b = [ 0 0 200] in color image
C:\ece595_06\image>java Test1 Elapsed time 20.9157 milliseconds 360 x 120 Area 0.0432000 megapixels Time per megapixel 484.159 milliseconds pixel ff656565 101 java.awt.Color[r=101,g=101,b=101] pixel ffadadad 173 java.awt.Color[r=173,g=173,b=173] pixel ff353535 53 java.awt.Color[r=53,g=53,b=53] C:\ece595_06\image>java Test1 Elapsed time 19.1097 milliseconds 360 x 120 Area 0.0432000 megapixels Time per megapixel 442.355 milliseconds ...
Test1.java
import java.awt.*; import java.awt.image.*; import java.awt.color.*; import java.io.*; import javax.imageio.*; import javax.swing.*; public class Test1 { public static void case2(BufferedImage img) { int w = 30; int p; Color c; for (int n=0; n<12; n++) { p = img.getRGB(15+w*n,60); c = new Color(p); System.out.format("pixel %x%n",p); System.out.println(c); } } public static void case1(BufferedImage img) { int w = 120; int p; Color c; for (int n=0; n<3; n++) { p = img.getRGB(60+w*n,60); c = new Color(p); System.out.format("pixel %x %d%n",p, p&0xFF); System.out.println(c); } } public static void main(String[] args) { String [] filenames = {"test.png", "test2.png"}; int ncase = 0; if (args.length>0) ncase = Integer.parseInt(args[0]); showImage f1 = new showImage(filenames[ncase]); f1.setLocation(100,100); f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); int w = f1.getWidth(); int h = f1.getHeight(); ColorConvertOp op = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null); long start = System.nanoTime(); BufferedImage grayImage = op.filter(f1.img, null); long etime = System.nanoTime() - start; double elapsed_time = 1e-6*(double)etime; System.out.format("Elapsed time %g milliseconds%n",elapsed_time); double area = f1.img.getWidth()*f1.img.getHeight()*1e-6; System.out.format("%d x %d Area %g megapixels%n",f1.img.getWidth(), f1.img.getHeight(), area); System.out.format("Time per megapixel %g milliseconds%n",elapsed_time/area); showImage f2 = new showImage(grayImage,"gray version"); f2.setLocation(120+w,100); if (ncase==0) case1(grayImage); else case2(grayImage); f2.writeImage("gray","png"); } }
Maintained by John Loomis, updated Wed Oct 09 19:58:05 2013