Assume you want to read an image file in a common file format from the hard drive, change the color of one pixel, and display the resulting image to the screen, in C++.
Which (open-source) libraries would you recommend to accomplish the above with the least amount of code?
Alternatively, which libraries would do the above in the most elegant way possible?
A bit of background: I have been reading a lot of computer graphics literature recently, and there are lots of relatively easy, pixel-based algorithms which I'd like to implement. However, while the algorithm itself would usually be straightforward to implement, the necessary amount of frame-work to manipulate an image on a per-pixel basis and display the result stopped me from doing it.
Doodle drawing might be one of the easiest possible ways to draw a picture. The fact that it is such a free-form method of drawing also takes away any fear of failure: doodling is the place where you can do no artistic wrong. Everyone can doodle, whether it's rows of hearts and stars, or more involved scenes or shapes.
The CImg library is easy to use.
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
It can also be used as a rather powerful image processing library. See the examples here.
You should look into the OpenCV library, especially if you're doing theoretical research into computer graphics.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With