2005年9月25日 星期日

創意工場 MIT


  Pepper White的這本創意工場MIT(原名 The Idea Factory: Learning to Think at MIT),好像是一本很有名的書呢,不過我是在書店看到才知道有這本書的,花了不短的時間才把它看完,因為作者是機械研究所的,領域和我實在差得太遠,所以書裡面有很多專業的描述其實我看不太懂,不過翻譯的吳程遠先生翻得不錯,起碼算得上通順,而且也把專有名詞翻譯得頗為正確,比起"藍色駭客"的譯者好多了。

  這本書主要在探討幾個問題:第一,在MIT唸書的滋味如何?第二,到底怎麼"學習思考"?第三,機械式思考的限制何在?在MIT唸書的滋味,書裡已經描述地很詳盡,而且也很殘忍了(雖然還有人認為描述不夠殘忍),想要逼出一個人的潛能和極限,這樣的訓練是必要的,對於每一件事情都能夠由最底層開始,有最深入的了解,這才是做科學研究的方法,作者在書中提到,他剛進入MIT的時候,跑去問Gyftopoulos(翟夫妥普羅斯)教授關於熱力學的問題,但是卻被教授反問了一連串底層的細節,White支支晤晤地答不出來,遭到教授的嚴厲指責:"很明顯你還沒準備好參加這樣的討論,我是個大忙人,而如果你還沒有準備好,沒有把你的問題整理好,請再不要踏進這裡來"。這樣嚴格且認真的教學態度影響了他們所教育的學生,也改變了他們做事與唸書的態度。而我呢?做得到嗎?每次問問題之前,都有好好地努力過,把所有的細節和觀念釐清,確定沒有辦法靠自己解決的時候才求助於老師嗎?我想,在這方面,我也還差得很遠,起碼比當時White的境界還要不如許多。

2005年9月13日 星期二

[Java] Read RGB values from raw image file


import java.io.*;

public class ReadRawImage {

private byte[] all;
/*
* Channel[0] for red channel, Channel[1] for green channel, Channel[2]
* for blue channel
*/
private int[][][] Channel;

private FileInputStream stream = null;

public ReadRawImage(File raw_image, int width, int height) {
try {
/* Read the raw image file into memory */
stream = new FileInputStream(raw_image);
all = new byte[width * height * 3];
Channel = new int[3][][];
stream.read(all);

/* dispatch pixel values to each array of channel */
ByteArrayInputStream bytestream = new ByteArrayInputStream(all);

byte [] temp = new byte[width * height];

bytestream.read(temp, 0, width * height);
Channel[0] = new int[height][width];
for(int i = 0; i < width * height; i++) {
/*
* extends the byte value to integer value by
* performing the "and" operation with 0x000000ff
*/
Channel[0][i / width][i%width] = temp[i] & 0x000000ff;
}

bytestream.read(temp, 0, width * height);
Channel[1] = new int[height][width];
for(int i = 0; i < width * height; i++) {
Channel[1][i / width][i%width] = temp[i] & 0x000000ff;
}

bytestream.read(temp, 0, width * height);
Channel[2] = new int[height][width];
for(int i = 0; i < width * height; i++) {
Channel[2][i / width][i%width] = temp[i] & 0x000000ff;
}

}catch(Exception e) {
e.printStackTrace();
}
}

public int[][][] getRGBValue() {
return Channel;
}
}