[英]The easiest way to draw an image?
假設您要從硬盤驅動器讀取通用文件格式的圖像文件,更改一個像素的顏色,並在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
它還可以用作相當強大的圖像處理庫。 請參閱此處的示例。
您應該查看OpenCV庫,特別是如果您正在對計算機圖形進行理論研究。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.