C++ 中基本图像处理的库

发布于 2024-10-26 14:15:53 字数 128 浏览 3 评论 0原文

我正在寻找一个很棒的 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 技术交流群。

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

发布评论

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

评论(6

大海や 2024-11-02 14:15:53

如果您要自己将颜色转换为灰度,您通常不希望为三个通道赋予相同的权重。通常的转换是这样的:

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).

挥剑断情 2024-11-02 14:15:53

CImg 可能是最容易使用的,无需安装,它只是一个头文件

CImg is probably easiest to use, no install it's just a header file

瑕疵 2024-11-02 14:15:53

您还可以查看 CxImage (C++ 图像处理和转换库) 。

You could also have a look at CxImage (C++ image processing and conversion library) .

弃爱 2024-11-02 14:15:53

要使用 Cimg 执行此操作的大致步骤如下:

#include "CImg.h"
using namespace cimg_library;
...
{
...
CImg<unsigned char> image("source.jpg") //[load jpg][2] needs ImageMagick
cimg_for(img,ptr,float) { *ptr=0; }      //[Loop][3] over every pixel, eg this method equivalent to 'img.fill(0);'
save_jpeg (const char *const filename, const unsigned int quality=100) //[save as a jpg][4] 
... 
}

To rough steps to do it using Cimg would be something like:

#include "CImg.h"
using namespace cimg_library;
...
{
...
CImg<unsigned char> image("source.jpg") //[load jpg][2] needs ImageMagick
cimg_for(img,ptr,float) { *ptr=0; }      //[Loop][3] over every pixel, eg this method equivalent to 'img.fill(0);'
save_jpeg (const char *const filename, const unsigned int quality=100) //[save as a jpg][4] 
... 
}
触ぅ动初心 2024-11-02 14:15:53

你可以看看 Paintlib

You could take a look at Paintlib

鹿童谣 2024-11-02 14:15:53

ITK 是一个很棒的图像处理库。您可以使用 itk::RGBToLuminanceImageFilter 将 RGB 转换为灰度。

ITK is a great library for image processing. You can convert RGB to grayscale using itk::RGBToLuminanceImageFilter.

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