Ben*_*nno 9 c++ graphics image-processing
假设您想要从硬盘驱动器读取通用文件格式的图像文件,更改一个像素的颜色,并在C++中将结果图像显示在屏幕上.
您建议哪些(开源)库以最少的代码完成上述操作?
或者,哪些库可以以最优雅的方式执行上述操作?
一点背景:我最近一直在阅读大量的计算机图形文献,并且我想实现许多相对简单的基于像素的算法.然而,虽然算法本身通常很容易实现,但是以每个像素为基础操作图像并显示结果所需的帧工作量使我不能这样做.
该CIMG库易于使用.
CImg<unsigned char> img("lena.png"); // Read in the image lena.png
const unsigned char valR = img(10,10,0,0); // Read the red component at coordinates (10,10)
const unsigned char valG = img(10,10,0,1); // Read the green component at coordinates (10,10)
const unsigned char valB = img(10,10,2); // Read the blue component at coordinates (10,10) (Z-coordinate omitted here).
const unsigned char avg = (valR + valG + valB)/3; // Compute average pixel value.
img(10,10,0) = img(10,10,1) = img(10,10,2) = avg; // Replace the pixel (10,10) by the average grey value.
CImgDisplay main_disp(img, "Modified Lena"); // Display the modified image on the screen
img.save("lena_mod.png"); // Save the modified image to lena_mod.png
Run Code Online (Sandbox Code Playgroud)
它还可以用作相当强大的图像处理库.请参阅此处的示例.