Is there any c function that allow me to convert a raw image to a PNG file?
Preferably, I don't need to pull in a big library for that.
Thank you.
I do not believe so. On the other hand, libpng isn't a huge library.
Have you tried the libpng library?
http://www.libpng.org/pub/png/libpng.html
I'm not sure what you mean by "raw image", but I've found LodePNG easy to work with. http://members.gamedev.net/lode/projects/LodePNG/ There's an example showing you how to encode some raw data to a png
See a related question: Convert bitmap to PNG in-memory in C++ (win32)
The short answer is that GDI+ can convert a bitmap image to PNG (with some limitations), so if you're on Windows it's an option that's even more minimal than libPNG.
Related
Is there any open source C++ library using which I can convert an image present in .bmp format to .png . I went through libpng didn't find any way to do it there, while boost/gil looks complex don't know that can be used to do this job.
Maybe this can help you solve the problem: LodePNG
I did not see BMP in boost/GIL.. maybe take a look at Magick++ ImageMagick API
http://www.imagemagick.org/Magick++/tutorial/Magick++_tutorial.pdf
Also GDK-Pixbuf can certainly do this
I use CImg for all my image manipulation. Well written, with good documentation.
Although I have found a lot about converting PNG to GIF for various languages and platforms, interestingly there are very few things to convert GIF to PNG with C++. I am rendering GIF images by using mimeTeX and want to draw them to my PDF by using libharu. The problem is that neither mimeTeX can render PNG, nor libharu can draw GIF. I know really limited things about both formats (just some elementary things I read from official PNG website and Wikipedia) and thus cannot convert GIF to PNG. I am very sorry that I cannot show you what I have tried because I could not find a start point. Please also note that all images will be created at runtime. I can use any kind of library that will work on Windows 7; and since my code is already excessively complex, I really do not want to make it even more complex. If a simple trick exist for this specific job, it will be highly appreciated. Thanks for that.
ImageMagick is the way to go; there's even a C++ library: http://www.imagemagick.org/script/magick++.php
I'm trying to use the imwrite() OpenCV function. I want to save the frames with the .TIFF extension. The problem that I have is that the saved images are compressed so I can't use them. Any idea how I can escape this compression?
thanks in advance
Do not mind what sietschie says. The TIFF flag is hardcoded in the opencv binaries with a LZW compression. You can just turn this off (comment it out) or change it.
In:
3rdparty/libtiff/tiff.h
Remove this line:
#define COMPRESSION_LZW 5 /* Lempel-Ziv & Welch */
Then compile. Presto.
Tiff options other than that are automatically set (8 bit, 16bit, color, rgb, rgba,etc) depending on your image
According to the documentation OpenCV only exposes a limited set of options for writing image files.
Non of which belongs to TIFF-Files.
So unless you want to use your own function or modify the OpenCV source, this is not possible.
I would suggest using another uncompressed format for saving the frames like PXM or BMP, unless you have some specific reasons to use TIFF-Files.
cv::imwrite("imagen.TIFF", bayer, {cv::IMWRITE_TIFF_COMPRESSION, 1,
cv::IMWRITE_TIFF_XDPI, 72,cv::IMWRITE_TIFF_YDPI,72});
The simplest way is recompiling OpenCV or direct using libtiff, but I consider as not very good idea changing 3rdparty/libtiff/tiff.h: after this modification you can't save compressed TIFFs at all with OpenCV, and under non-windows systems you usually have separate libtiff (not as a part of OpenCV).
I suggest simpler approach (still OpenCV recompilation, but you save possibility of writing compressed tiff and don't change libtiff directly):
saving uncompressed TIFFs with OpenCV
Is this possible? It doesn't matter what format the image is, but I have to be able to open it, read pixel data into some sort of array, create a new image using a modified set of pixel data.
Thanks!
Boost.GIL has a good video tutorial which shows you how to read/write and process raw image data in a very generic, yet efficient, way.
You need code to encode and decode the formats you want to support. You can do this yourself (not really ideal/practical,) you can embed encoding/decoding libraries (like libpng, for example,) or you can embed image libraries like DevIL.
Boost seems to include some sort of image access library known as Boost.GIL. I really don't know much about it, though.
I suggest the TARGA image format for your needs. You just read/write a few values in a header, then the rest is an uncompressed array of RGBA pixel data. You won't even need Boost!
I suggest CImg. This library is extremely easy to use. You only have to include a header file in your code and set some parameters when compiling and that's it! I've used CImg with MingW and GCC.
I want a c++ Code to read every pixel from an image file. and i want to save the pixels like:
r[]
g[]
b[]
does somebody know how to do this?
The answer depends on the format of the image file. Is it a format which contains raw RGB data (such as uncompressed TGA)? Is it a YUV image? Is it a compressed image such as JPEG or PNG?
There are already plenty of C++ libraries out there which can read a wide variety of image file formats, and then provide the pixel-level access you require. Take a look at Adobe's GIL, or CImg for example.
There are many freely available libraries for reading different image file formats. Since you're using C++ you might want to look at Adobe's Generic Image Library (GIL) or even OpenCV.
This will sort you out, very easy to use and 'low level' image library:
http://easybmp.sourceforge.net/
Two libraries that I've used that jump to mind are:
ImageMagick
libGD
These libraries can handle a wide variety of image formats, depending on what you need.