如何减少位图以一组已知的RGB颜色 [英] How do I reduce a bitmap to a known set of RGB colours

查看:122
本文介绍了如何减少位图以一组已知的RGB颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于一个爱好的项目,我要建立一个程序,给定当图像的位图将创建一个十字绣图案为PDF。我将使用可可/目标C在Mac上。

For a hobby project I'm going to build a program that when given an image bitmap will create a cross-stitch pattern as a PDF. I'll be using Cocoa/Objective C on a Mac.

源位图通常是和24bpp的形象,但数以百万计的颜色可供选择,只有少数如存在十字绣线。螺纹来在各种类型的。 DMC是最广泛使用的,并且几乎它们的整个范围可从各种网站RGB值。 这里有一个,例如。

The source bitmap will typically be a 24bpp image, but of the millions of colours available, only a few exist as cross-stitch threads. Threads come in various types. DMC is the most widely available, and almost their entire range is available as RGB values from various web sites. Here's one, for instance.

DMC#  Name               R   G   B
----- ------------------ --- --- ---
blanc White              255 255 255
208   Lavender - vy dk   148  91 128
209   Lavender - dk      206 148 186
210   Lavender - md      236 207 225
211   Lavender - lt      243 218 228
      ...etc...

我的第一个问题,在我看来,是从图像中选择可从DMC集中最接近的颜色的像素RGB的起点。什么是数学上寻找最近​​的DMC颜色,并确保它是紧密配合作为颜色的最佳方法呢?

My first problem, as I see it, is from a starting point of the RGB from a pixel in the image choosing the nearest colour available from the DMC set. What's the best way of finding the nearest DMC colour mathematically, and ensuring that it's a close fit as a colour too?

虽然我将使用可可,随意c您发布使用伪code(或连渣!)在$ C $。

Although I'll be using Cocoa, feel free to use pseudo-code (or even Java!) in any code you post.

推荐答案

使用的 LAB 色彩空间,并找到最近的欧氏距离。在RGB颜色空间这样做将产生反直觉的结果。 (或使用 HSL 的色彩空间。)

Use the LAB color space and find the color with the nearest euclidean distance. Doing this in the RGB color space will yield counter-intuitive results. (Or use the HSL color space.)

因此​​,只要遍历每个像素,并找到您选择的色彩空间内的最近距离的颜色。另外,距离必须计算的对于一些色彩空间(例如那些采用的色相的)。

So just iterate over each pixel and find the color with the closest distance within the color space you choose. Note that the distance must be computed circularly for some color spaces (e.g. those employing hue).

(大多数颜色quanization围绕竟选择一个调色板,但已经在你的情况的照顾,所以你不能使用比较流行的量化技术。)

(Most color quanization revolves around actually choosing a palette, but that has already been taken care of in your case, so you can't use the more popular quantization techniques.)

此外,检查<一href=\"http://stackoverflow.com/questions/492211/is-there-an-easy-way-to-compare-how-close-two-colors-are-to-each-other\">this问题。

要找到可可的HSB色相,它看起来像你可以使用声明相对=nofollow> getHue方法。

To find the HSB hue in Cocoa, it looks like you can use the getHue method declared in NSColor.h.

然而,如果你只是使用这种技术将图像转换为一个十字绣设计,这将是非常困难的实际缝好。这将是全单像素彩色场,其中诸如此类的失败十字绣的目的。

However, if you just convert an image to a cross-stitch design using this technique, it will be very hard to actually stitch it. It will be full of single-pixel color fields, which sort of defeats the purpose of cross-stitching.

这篇关于如何减少位图以一组已知的RGB颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆