Re: [問題] 還是.bmp檔案的問題 ~"~
※ 引述《H45 (!H45)》之銘言:
: 本程式輸出的像素值有 (255, 255, 255), (255, 255, 0), (255, 0, 255),
: (0, 255, 255), (255, 0, 0), (0, 255, 0), (0, 0, 255), (0, 0, 0)
: 以上共有八種可能,所以這並不是二值影像。
try {
BufferedImage image = ImageIO.read(new File("lena256.bmp"));
final int width = image.getWidth();
final int height = image.getHeight();
for (int y=0; y<height; y++) {
for (int x=0; x<width; x++) {
int rgb = image.getRGB(x, y) & 0x00ffffff;
int red = (rgb & 0x00ff0000) >> 16;
int green = (rgb & 0x0000ff00) >> 8;
int blue = rgb & 0x000000ff;
if (red > 127 && green > 127 && blue > 127) {
rgb = 0x00ffffff;
} else {
rgb = 0x00000000;
}
image.setRGB(x, y, rgb);
}
}
ImageIO.write(image, "png", new File("binary.png"));
System.out.println("OK.");
} catch (IOException e) {
e.printStackTrace();
}
這個程式碼經測試與原篇的 Matlab 圖完全相同。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.116.247.13
推
10/22 19:28, , 1F
10/22 19:28, 1F
→
10/22 19:29, , 2F
10/22 19:29, 2F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 7 篇):