分析图像颜色的最佳方法是什么(Java)?

发布于 2024-09-08 23:21:27 字数 279 浏览 7 评论 0原文

我没有太多进行图像分析的经验,所以我想我应该问更多开明的人:)

基本上我想做的是分析图像并找出最常见的颜色是什么(这些显然是平均值)。

有人知道有效的方法吗?如果可能的话,我想避免使用任何第三方库,但至少一切都会被考虑。

就像我说的,我在图像分析方面没有太多经验,所以如果我不能正确理解您的答案,请耐心等待!

我尝试过谷歌,但似乎没有任何类似我想要的东西。也许我今天的 Google-Fu 还不够好。

我真的很感激你们能给的任何指点!

谢谢, 汤姆

I don't have much experience doing image analysis so I thought I'd ask more enlightened individuals :)

Basically what I want to do is analyse an image and work out what the most common colours are (these will be averages obviously).

Does anybody know of an effective way to do this? If at all possible I'd like to avoid using any third party libraries, but everything will be considered at least.

Like I said, I don't have much experience with image analysis so please be patient with me if I don't understand your answers properly!

I've tried Google but there doesn't seem to be anything resembling what I'm after. Maybe my Google-Fu just isn't good enough today.

I'd really appreciate any pointers you guys could give!

Thanks,
Tom

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

万劫不复 2024-09-15 23:21:27

关于如何做到这一点的粗略想法:
您可以使用 java.awt.image.PixelGrabber 从图像中逐像素抓取 RGB 整数的 2D 数组。

当你填充这个数组时,你可以按照你想要的方式进行遍历和排序(听起来这会占用大量内存),并执行简单的函数来对它们进行排序、对它们进行计数等

。 awt.Color 并使用 Color(int, int, int) 构造函数,使用这些颜色(作为视觉占位符)创建框,并在其下方显示出现次数。

要获取颜色的十六进制值,您可以使用如下所示的字符串:(

    String rgb = Integer.toHexString(color.getRGB());
    rgb = rgb.substring(2, rgb.length());

子字符串是必要的,否则您将获得 8 个字符)

希望这能让您走上正轨!

资源:颜色类图像类

A rough idea of how you might be able to do this:
You could use java.awt.image.PixelGrabber to grab a 2D array of RGB ints from the image, pixel by pixel.

When you have this array populated, you can go through and sort however you want (sounds like it would be memory-intensive), and perform simple functions to order them, count them, etc.

Then you could look at java.awt.Color and, using the Color(int, int, int) constructor, create boxes with those colors (as visual placeholders) with the number of occurrences appearing below it.

To get the hex values for the color, you can use a String like so:

    String rgb = Integer.toHexString(color.getRGB());
    rgb = rgb.substring(2, rgb.length());

(substring is necessary, otherwise you'd get 8 characters)

Hopefully this gets you on the right track!

Resources: Color Class, Image Class

就像说晚安 2024-09-15 23:21:27

考虑使用 RGB 而不是 XYZ 的“颜色立方体”。将立方体分割成子立方体,但使它们全部重叠。确保它们的尺寸都相同。一种易于记忆/计算的立方体图案是从 0-127、64-191、128-255 各个方向排列的立方体图案,总共有 27 个立方体。对于每个立方体,找出图像中属于它们的颜色。

随着立方体变得越来越小,结果的变化会越来越小,并开始收敛于最流行的颜色范围。一旦达到收敛,取范围的平均值即可获得“实际颜色”。

这就是我和我的老板在立方农场周围徘徊时所能了解的尽可能多的细节:-)

Consider a "color cube" with RGB instead of XYZ. Split the cube into subcubes, but make them all overlap. Ensure they are all the same size. An easy to remember/calculate cube-pattern would be one that goes from 0-127, 64-191, 128-255 in all directions, making for a total of 27 cubes. For each cube, find what colors in the image fall into them.

As you make the cubes smaller and smaller, the results will change less and less and begin to converge on the most popular color ranges. Once you have that convergence, take the average of the range to get the "actual color".

That's about as much detail as I can go into with my boss hovering around the cubefarm :-)

穿越时光隧道 2024-09-15 23:21:27

我知道您试图避免第三方库,但请看一下 OpenCV。他们有一些关于图像处理和分析的好东西。也许这对你有用。

I know your trying to avoid third party libraries, but do take a look at OpenCV. They have some good stuff w.r.t image manipulation and analysis. Maybe that can work for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文