用于确定最接近颜色匹配的 Mysql 算法

发布于 2024-08-31 14:20:56 字数 1669 浏览 3 评论 0原文

我正在尝试创建一个真正的马赛克应用程序。目前,我有一张马赛克图像(即马赛克所基于的图像)以及来自我的 iPhoto 库的约 4000 张图像(充当图像库)。我已经完成了研究并分析了马赛克图像。我已将其转换为 64x64 切片,每个切片 8 个像素。我计算了每个切片的平均颜色并断言 r、g、b 和亮度 (亮度(感知选项 1)= (0.299*R + 0.587*G + 0.114*B)) 值。我对图像库中的每张照片都做了同样的事情。

马赛克切片表看起来像这样。

slice_id, slice_image_id, slice_slice_id, slice_image_column, slice_image_row, slice_colour_hex, slice_rgb_red, slice_rgb_blue, slice_rgb_green, slice_rgb_brightness

图片库表看起来像这样。

upload_id, upload_file, upload_colour_hex, upload_rgb_red, upload_rgb_green, upload_rgb_blue, upload_rgb_brightness

所以基本上我将切片表中的图像切片读入 PHP,然后根据颜色十六进制从库表中提取适当的图像。我的问题是,我已经这样做太久了,可能喝了太多能量饮料,所以注意力不集中,如果不存在适当的十六进制代码,我无法找出最近的颜色邻居的方法。

关于完美查询有什么想法吗?

注意:我知道逐个拉出切片并不理想,但是马赛克只是定期重建,因此 mysql 负载的突然爆发并不会真正困扰我,但是如果我们有一种方法可以一次拉出所有图像这也将是一笔巨大的奖金。

更新亮度比较。

带亮度

alt text
(来源:buggedcom.co.uk< /a>)

无亮度

alt text
(来源:buggedcom.co.uk< /a>)

I'm attempting to create a true mosaic application. At the moment I have one mosaic image, ie the one the mosaic is based on and about 4000 images from my iPhoto library that act as the image library. I have already done my research and analysed the mosaic image. I've converted it into 64x64 slices each of 8 pixels. I've calculated the average colour for each slice and assertain the r, g, b and brightness (Luminance (perceived option 1) = (0.299*R + 0.587*G + 0.114*B)) value. I have done the same for each of the image library photos.

The mosaic slices table looks like so.

slice_id, slice_image_id, slice_slice_id, slice_image_column, slice_image_row, slice_colour_hex, slice_rgb_red, slice_rgb_blue, slice_rgb_green, slice_rgb_brightness

The image library table looks like so.

upload_id, upload_file, upload_colour_hex, upload_rgb_red, upload_rgb_green, upload_rgb_blue, upload_rgb_brightness

So basically I'm reading the image slices from the slices table into PHP and then pulling out the appropriate images from the library table based on the colour hexs. My trouble is that I've been on this too long and probably had too many energy drinks so am not concentrating properly, I can't figure out the way to pick out the nearest colour neighbor if the appropriate hex code doesn't exist.

Any ideas on the perfect query?

NB: I know pulling out the slices one by one is not ideal however the mosaic is only rebuilt periodically so a sudden burst in the mysql load doesn't really bother me, however if there us a way to pull the images out all at once that would also be a massive bonus.

Update Brightness Comparisons.

With Brightness

alt text
(source: buggedcom.co.uk)

Without Brightness

alt text
(source: buggedcom.co.uk)

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

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

发布评论

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

评论(2

清风疏影 2024-09-07 14:20:56

最小化颜色之间差异(就其 RGB 分量而言)的一种方法是单独最小化每个分量的差异。因此,您正在寻找最低的条目

(targetRed - rowRed)^2 + (targetGreen - rowGreen)^2 + (targetBlue - rowBlue)^2

One way to minimize the difference between the colours (in terms of their RGB components) is you would individually minimize the difference in each component. Thus you're looking for the entry with lowest

(targetRed - rowRed)^2 + (targetGreen - rowGreen)^2 + (targetBlue - rowBlue)^2
我还不会笑 2024-09-07 14:20:56

我认为您最好使用 HSL 而不是 RGB 作为色彩空间。从 RGB 计算 HSL 的公式可在互联网上找到(以及链接的维基百科文章中),它们可能会为您提供计算最佳匹配所需的信息。

I think that you may be better off using HSL instead of RGB as color space. Formulas to compute HSL from RGB are available on the internet (and in the linked Wikipedia article), they may give you what you need to compute the best match.

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