gpt4 book ai didi

java - 如何分别获取图像的rgb矩阵?

转载 作者:搜寻专家 更新时间:2023-11-01 02:12:28 25 4
gpt4 key购买 nike

我有一个图像数据库,我想将这些图像的 RGB 矩阵分别存储在 mysql 数据库中(例如:redMatrix_column、greenMatrix_column、blueMatrix_column)。在 matlab 中,我可以使用 imread() 函数单独获取 RBG 矩阵。如何在 java 中执行此操作?谢谢你的帮助。

最佳答案

这是获取颜色分量的方式:

public class GetImageColorComponents {
public static void main(String... args) throws Exception {
BufferedImage img = ImageIO.read(GetImageColorComponents.class
.getResourceAsStream("/image.png"));
int[] colors = new int[img.getWidth() * img.getHeight()];
img.getRGB(0, 0, img.getWidth(), img.getHeight(), colors, 0, img.getWidth());

int[] red = new int[colors.length];
int[] green = new int[colors.length];
int[] blue = new int[colors.length];

for (int i = 0; i < colors.length; i++) {
Color color = new Color(colors[i]);
red[i] = color.getRed();
green[i] = color.getGreen();
blue[i] = color.getBlue();
}
}
}

参见 this gist有关在 MySQL 数据库中保存和检索字节的完整示例。

关于java - 如何分别获取图像的rgb矩阵?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15848267/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com