MATLAB: 0 2 6 13 23 37 54 75 103 133 168 208 from png file Java: 0 22 42 64 85 106 127 148 170 191 212 233
C:\ece595_06\image>java Test3 file: gray2.png pixel 0xff000000 0 java.awt.Color[r=0,g=0,b=0] pixel 0xff161616 22 java.awt.Color[r=22,g=22,b=22] pixel 0xff2a2a2a 42 java.awt.Color[r=42,g=42,b=42] pixel 0xff404040 64 java.awt.Color[r=64,g=64,b=64] pixel 0xff555555 85 java.awt.Color[r=85,g=85,b=85] pixel 0xff6a6a6a 106 java.awt.Color[r=106,g=106,b=106] pixel 0xff7f7f7f 127 java.awt.Color[r=127,g=127,b=127] pixel 0xff949494 148 java.awt.Color[r=148,g=148,b=148] pixel 0xffaaaaaa 170 java.awt.Color[r=170,g=170,b=170] pixel 0xffbfbfbf 191 java.awt.Color[r=191,g=191,b=191] pixel 0xffd4d4d4 212 java.awt.Color[r=212,g=212,b=212] pixel 0xffe9e9e9 233 java.awt.Color[r=233,g=233,b=233]
Test3.java
import java.awt.*; import java.awt.image.*; import java.awt.color.*; import java.io.*; import javax.imageio.*; import javax.swing.JFrame; public class Test3 { public static void main(String[] args) { String filename = "gray2.png"; if (args.length>0) filename = args[0]; System.out.println("file: " + filename); showImage f1 = new showImage(filename); f1.setLocation(100,100); f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); int w = 30; int p; Color c; for (int n=0; n<12; n++) { p = f1.img.getRGB(15+w*n,60); c = new Color(p); System.out.format("pixel 0x%x %d %n",p, p&0xFF); System.out.println(c); } } }
Maintained by John Loomis, updated Thu Oct 10 11:53:57 2013