C++ 中基本图像处理的库
我正在寻找一个很棒的 C++ 库来进行基本的图像处理。我需要做的是将图像转换为灰度并有权读取图像的像素。
我看过 OpenCV、GIL、CImg 和 Magick++,但要么它们不太好,要么我不知道如何使用库将图像转换为灰度。
I am looking for a great C++ library for doing basic image manipulation. What I need done is to be able to convert an image to grayscale and have access to read the pixels of the image.
I have looked at OpenCV, GIL, CImg and Magick++, but either they were not too great, or I couldn't figure out how to convert an image to grayscale with the library.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果您要自己将颜色转换为灰度,您通常不希望为三个通道赋予相同的权重。通常的转换是这样的:
gray = 0.3 * R + 0.6 * G + 0.1 * B;
显然,这些因素并不是一成不变的,但它们应该相当接近。
您可以通过更改因子来模拟不同颜色的滤镜 - 到目前为止,黑白摄影中最常见的滤镜是红色,这意味着增加红色并减少其他两个以保持总因子 1.0(但保持 G :B 比例约为 6:1 左右)。
If you're going to convert color to greyscale on your own, you don't normally want to give equal weight to the three channels. The usual conversion is something like:
grey = 0.3 * R + 0.6 * G + 0.1 * B;
Obviously those factors aren't written in stone, but they should be reasonably close.
You can simulate different colors of filters by changing the factors -- by far the most common filter in B&W photography is red, which would mean increasing the red and decreasing the other two to maintain a total factor of 1.0 (but keep the G:B ratio around 6:1 or so).
CImg 可能是最容易使用的,无需安装,它只是一个头文件
CImg is probably easiest to use, no install it's just a header file
您还可以查看 CxImage (C++ 图像处理和转换库) 。
You could also have a look at CxImage (C++ image processing and conversion library) .
要使用 Cimg 执行此操作的大致步骤如下:
To rough steps to do it using Cimg would be something like:
你可以看看 Paintlib
You could take a look at Paintlib
ITK 是一个很棒的图像处理库。您可以使用
itk::RGBToLuminanceImageFilter
将 RGB 转换为灰度。ITK is a great library for image processing. You can convert RGB to grayscale using
itk::RGBToLuminanceImageFilter
.