簡體   English   中英

Java - 從圖像中獲取像素值矩陣

[英]Java - Get a matrix of pixel values from an image

晚上好,

我正在使用 BufferedImage 在 Java 中加載圖像。 我想將這個 Object 轉換為一個簡單的二維矩陣,其中每個單元格都是一個 8 位像素值(從 0 到 255)。 這需要處理灰度圖像,也需要處理 RGB 圖像(在這種情況下,output 需要 3 個矩陣,每個通道一個,或單個 3D 矩陣)。 這類似於 MatLab 處理圖像的方式。

任何人都可以幫助我嗎?

謝謝

你可以嘗試這樣的事情:

BufferedImage bf = //Assuming you have a buffered image
int[][] R = new int[bf.getWidth()][bf.getHeight()];
int[][] G = //Same as for R
int[][] B = //Same as for R

for(int r = 0; r < bf.getWidth(); r++)
{
     for(int c = 0; c < bf.getHeight() c++)
     {
           //Uses the Java color class to do the conversion from int to RGB
           Color temp = new Color(bf.getRGB(r, c));
           R[r][c] = temp.getRed();
           G[r][c] = temp.getGreen();
           B[r][c] = temp.getBlue();
     }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM