Library to generate Images with pixels - c++

I'm looking for a Library that allows me to generate an Image via pixel information, in this style(dummyfunction):
/*
coord_x = X coordinate
coord_y = Y coordinate
red = red part of RGB
green = green part of RGB
blue = blue part of RGB
*/
setPixel(int coord_x, int coord_y, int red, int green, int blue)
Is there such a Function? I've searched libpng, but it doesn't appear to allow to set pixels manually (might be wrong, though)...
Prefered formats for output would be PNG, GIF would be acceptable, JPG will probably not work (due to compression and lack of transparency as in PNG and GIF).

a strong and powerful library is Imagick:
Use MagickWand to convert, compose, and edit images from the C language. There is also the low-level MagickCore library for wizard-level developers.
http://www.imagemagick.org/script/api.php?ImageMagick=2m69higs264080492m8ttkndb5#c

I'd use Boost.GIL.

If you're on Windows, you could use GDI+.

You could look at ITK (http://www.itk.org). Its primary use is for medical image processing, but it works just as well for processing other images. It's also portable (built using CMake).

Related

read jpg into a 2d array of pixels in CPP [duplicate]

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?
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
jpeglib is quite a handy library to play with jpegs.
For access to pixel level information. libjpeg & JAI Image I/O Tools should be sufficient. JAI provide advance image processing framework more than this. All options allow you to read/write pixels to an image file.
libjpeg
In C/C++. It is available for Linux and Window. I have used it in Linux before and it works well. However, if you would like to process other image type, you may need to get other package and learn another API interface.
Java Advanced Imaging(JAI) Image I/O Tools
Remember to download the platform specific java package because there is specific optimization for different system. It covers not only JPG but other image format too with exact same API interface.
Java Advanced Imaging(JAI)
If you plan to do more advance level of processing such as using image operator and filter, you can use this. This is a package provide higher level functionality than JAI Image I/O Tools.
EDIT: to remove the 1, 2 & 3 as suggested
Try FreeImage, it seems pretty versatile and many projects use it.

reading indexed palette image in C++

My platform is Windows. I didn't expect reading indexed palette image to be this difficult in C++. In case you are not familiar with it, it's single channel image but expresses its pixel color with 256 indexed colors called palette.
I was using OpenCV but its imread just converts the file to a 3 channel image so I have no way to save it back to indexed palette image or compare it with another indexed palette image.
I tried to use Bitmap but for some reason, it does not read correct pixel values.
So right now, I am looking for a light library or code to read pixels from indexed palette file.
Using OpenCV to read or write a image from real cameras will lose and change the image information, so I prefer to use gdi+, which is more powerful in dealing with image format problems to solve your problem.
As comments on the question shows, I decided to have two methods, OpenCV for non-indexed-palette images and Bitmap (GDI+) for indexed palette images. Now everything is working perfect.

Can libjpeg be used to change contrast of images in C++?

If not, where can I find the algorithm to adjust contrast of an image. I will have to code it in C++ and have access to libjpeg and libjpeg-turbo libraries
http://en.wikipedia.org/wiki/Image_editing#Contrast_change_and_brightening
Is this a good starting point for color images?
The simplest I could have think of is the ImageMagick library, or do it yourself*.
* I know that the code in that answer is not c++, but if you know c or c++, you should be able to understand it.
You might like this one for starters: Processing in the 8-bit YUV Color Space
C there is the contrast adjustment. With an image with pixel format in YUV color space, constrast adjustment is quite easy and is an update for Y component of the pixel.
libjpeg is not quite the tool for image processing, unless you are decoding/encoding JPEGs and you need some processing on the way.

How to process jpg images with c/c++ most easily?

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?
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
jpeglib is quite a handy library to play with jpegs.
For access to pixel level information. libjpeg & JAI Image I/O Tools should be sufficient. JAI provide advance image processing framework more than this. All options allow you to read/write pixels to an image file.
libjpeg
In C/C++. It is available for Linux and Window. I have used it in Linux before and it works well. However, if you would like to process other image type, you may need to get other package and learn another API interface.
Java Advanced Imaging(JAI) Image I/O Tools
Remember to download the platform specific java package because there is specific optimization for different system. It covers not only JPG but other image format too with exact same API interface.
Java Advanced Imaging(JAI)
If you plan to do more advance level of processing such as using image operator and filter, you can use this. This is a package provide higher level functionality than JAI Image I/O Tools.
EDIT: to remove the 1, 2 & 3 as suggested
Try FreeImage, it seems pretty versatile and many projects use it.

How to get into image manipulation programming?

How can I do simple thing like manipulate image programmatically ? ( with C++ I guess .. )
jpgs/png/gif .....
check out BOOST , it has a simple Image Processing Library called GIL. It also has extensions to import common formats.
http://www.boost.org/doc/libs/1_39_0/libs/gil/doc/index.html
Using .NET you have two options:
GDI+ from System.Drawing namespace (Bitmap class)
WPF engine wich can do a lot of things
If you want low level processing you can use unsafe code and pointers.
A Bitmap or Image is just a big array of bytes.
You need to learn:
what is a stride (extra padding bytes after each row of pixels)
how to compute the next row or a specific pixel location using width, height, stride
the image formats RGB, ARGB, white&black
basic image processing functions (luminosity, midtone, contrast, color detection, edge detection, matrix convulsion)
3D vectorial representation of a RGB color
Depending on how fancy you want to get, you may want to look at OpenCV. It's a computer vision library that has functions ranging from reading and writing images to image processing to advanced things like object detection.
Magick++ is a C++ API for the excellent ImageMagick library.
An advantage of ImageMagick is that it can be used from the command-line and a bunch of popular scripting and compiled languages too, and some of those might be more accessible to you than C++.