I want to iterate over each pixel color in a jpg
format image,
which library should I refer to to do this so that the code can be as short as possible?
JPEG uses a lossy form of compression based on the discrete cosine transform (DCT). This mathematical operation converts each frame/field of the video source from the spatial (2D) domain into the frequency domain (a.k.a. transform domain).
C or C++ C or C++ language have been used for image processing because it contains native libraries such as EmguCV, OpenGL and OpenCV have built-in intelligent feature, mainly used for image processing.
It's the most widely accepted image format. You can open JPG files with your web browser, like Chrome or Firefox (drag local JPG files onto the browser window), and built-in Microsoft programs like the photo viewer and Paint application. If you're on a Mac, Apple Preview and Apple Photos can open the JPG file.
I can think of either ImageMagick or CImg. Here is a CImg tutorial for you. They abstract away a lot of the decompression details and just give you a grid to work with.
If you go with CImg, you only need to use the data call. You can probably do something like:
CImg<unsigned char> src("image.jpg");
int width = src.width();
int height = src.height();
unsigned char* ptr = src.data(10,10); // get pointer to pixel @ 10,10
unsigned char pixel = *ptr;
Qt has a QImage class:
QImage i("input.jpg");
int x, y;
for (y = 0; < i.height(); ++y) {
for (x = 0; x < i.width(); ++x) {
doSomethingWith(i.pixel(x, y));
}
}
I would use Allegro Game Library http://liballeg.org/Allegro it's simple / open source / free / multiplatform, and you can iterate pixel by pixel if you want
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