Which floating-point image format should I use? - c++

In the past I've saved RGB images (generated from physical simulations) as 8-bits/channel PPM or PNG or JPEG.
Now I want to preserve the dynamic range of the simulation output, which means saving a floating point image and then treating conversion to 8-bits/channel as a post-processing step (so I can tweak the conversion to 8-bit without running the lengthy simulation again).
Has a "standard" floating point image format emerged ?
Good free supporting libraries/viewers/manipulation tools, preferably available in Debian, would be a bonus.

Have you looked into Radiance RGBE (.hdr) and OpenEXR (.exr). RGBE has some source code here. NVIDIA and ATI both support EXR data in their graphics cards. There are source code and binaries from the OpenEXR download page. ILM created OpenEXR and it has wide support. OpenEXR has support for 16 and 32 bit floating point per channel, and is what most people use these days, unless they've written their own format.
The Pixel Image Editor for linux has EXR support for editing, too.
pfstools is also necessary if you're going to work with HDR on linux. Its a set of command line programs for reading, writing and manipulating HDR and has Qt and OpenGL viewers.
Theres also jpeg2exr for linux
Heres some other debian packages for OpenEXR viewers.
Based on this, it looks like theres also a Gimp plugin somewhere.

It looks like the modern incarnation of FITS would fit your stated needs, but I would also suggest you consider using a 2D histogram structure from one of the good analysis packages in wide use by the physics community: ROOT or AIDA are the modern ones that I am familiar with.
NB: It's been more than a decade since I used FITS for anything, but I recall it begin a nice and flexible way to store fairly raw data.

For future reference, also rather widespread is the TIFF format. You can use the free and open-source LibTIFF for I/O.

Related

custom opengl compressed texture

I am developing mobile games on windows. Our image resources are in the PVR-TC 4 format. When we run our game on simulator, images are decoded by CPU which is really slow, as our PC graphic card don't support GPU decode. Is it possible to make PC OpenGL support PVR-TC or ETC hardware decode?
You cannot force an implementation to implement a particular extension or image format.
Your best bet is to convert the images yourself offline. That is, instead of loading images of a format your hardware can't handle, load images of the format that it can.
After all, it's not like the images are originally in PVRTC format, right? They were originally authored in a regular format like PNG or whatever, then converted to PVRTC. So just add another conversion for S3TC or whatever format desktop hardware actually supports.

C++ runtime convert gif to png

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

Is there a faster lossy compression than JPEG?

Is there a compression algorithm that is faster than JPEG yet well supported? I know about jpeg2000 but from what I've heard it's not really that much faster.
Edit: for compressing.
Edit2: It should run on Linux 32 bit and ideally it should be in C or C++.
Jpeg encoding and decoding should be extremely fast. You'll have a hard time finding a faster algorithm. If it's slow, your problem is probably not the format but a bad implementation of the encoder. Try the encoder from libavcodec in the ffmpeg project.
Do you have MMX/SSE2 instructions available on your target architecture? If so, you might try libjpeg-turbo. Alternatively, can you compress the images with something like zlib and then offload the actual reduction to another machine? Is it imperative that actual lossy compression of the images take place on the embedded device itself?
In what context? On a PC or a portable device?
From my experience you've got JPEG, JPEG2000, PNG, and ... uh, that's about it for "well-supported" image types in a broad context (lossy or not!)
(Hooray that GIF is on its way out.)
JPEG2000 isn't faster at all. Is it encoding or decoding that's not fast enough with jpeg? You could probably be alot faster by doing only 4x4 FDCT and IDCT on jpeg.
It's hard to find any documentation on IJG libjpeg, but if you use that, try lowering the quality setting, it might make it faster, also there seems to be a fast FDCT option.
Someone mentioned libjpeg-turbo that uses SIMD instructions and is compatible with the regular libjpeg. If that's an option for you, I think you should try it.
I think wavelet-based compression algorithms are in general slower than the ones using DCT. Maybe you should take a look at the JPEG XR and WebP formats.
You could simply resize the image to a smaller one if you don't require the full image fidelity. Averaging every 2x2 block into a single pixel will reduce the size to 1/4 very quickly.

Any good C++ library for displaying large bitmaps

I'm currently using MFC/GDI and Stingray to display bitmaps in my application and am looking for a better solution. Specifically;
Faster drawing speed - My current solution is slow, based on StretchDIBits
Better rendering quality - StretchDIBits rendering quality is awful when scaling a bitmap
Support for rotated bitmaps
Support for loading / saving in all popular formats
Support for large bitmaps - I'm regularly using aerial photographs that are ~64mb as 12,000x12,000 jpegs. GeoTIFF support would also be useful
Compatible with MFC document/view, including printing (e.g. must be able render to a CDC)
Access to source code is good but not necessary
Easy to use / port existing GDI code
While free is always nice, I don't mind spending a reasonable amount on a decent library, though no run time royalty costs. Googling suggests the following;
CImg
Graphics Magick
Lead Tools imaging SDK
Anyone got experience of these or can recommend an good alternative?
GDI+ is available on any Windows machine since early XP. It has codecs for all popular image formats, JPEG is included. Very nice filters for high-quality image rescaling. Unrestricted image rotation. Draws to a CDC through the Graphics class. Source code for the C++ wrappers are available in the SDK gdiplusXxx.h header files. Speed is likely to be equivalent however, rendering is software based to ensure compatibility.
You can #include <gdiplus.h> and use the C++ wrappers directly. The SDK docs are here. The CImage class is available in MFC, it doesn't expose all capabilities however.
I think it's unlikely you'll find something that performs faster than GDI on windows since it has kernel-level support which is something open source solutions will not have.
You might want to also look into OpenGL or Direct2D/Direct3D since these too have direct access to the frame buffer. With 3D APIs, texture size would probably be an issue since most standards limit to something like 4096x4096.
I have used CxImage in the past which is one to add to your evaluation list.

Fast Cross-Platform C/C++ Image Processing Libraries

What are some cross platform and high performance image libraries for image processing (resizing and finding the color/hue histograms). No gui needed. This is for C/C++.
So far I have looked in to
OpenCV
GIL as part of Boost
DevIL
CImg
My questions
How's the performance of the ones I have listed above
What are some other libraries
Your input much appreciated.
OpenCV has quite good performance. It should be sufficient for most cases.
To improve performance, you can also use OpenCV together with Intel IPP, which is however a non-free commercial product. If OpenCV detects that IPP is installed it will use it where possible.
As a third option you can use IPP directly. IPP was designed with high performance (on Intel architectures) as a goal. It is optimized to use the intel SIMD instructions.
imagemagick is quite popular.
I don't think I've seen anything better in features and performance than HALCON from MVTec. It provides all sort computer vision and image processing algorithms out-of-the-box and plenty of real life examples. The library uses multithreading as much as algorithms could possibly allow and GPU when available. It's very cross-platform and provides a fantastic IDE that will allow you to export your prototype code (algorithm) to many languages including C, C++, C# and more.
One of the best features of this library is how they treat region objects. It is just incredibly smart and efficient both for storage and mask processing. Unfortunately OpenCV has a lot to learn from it.
The main problem with this package is the price (stupidly high) but if you are working on a project where you don't need to deploy runtime licenses (e.g. SaaS) then this is the way to go, look no further if you require serious image processing and computer vision.
Don't forget to look at CxImage - I've used it professionally in globally deployed graphics intensive mobile phone applications, where it performed perfectly and it's so full of features. Do check it out!
I help maintain libvips, a free, cross-platform C/C++ scientific image-processing library. It is fast and works well on very large images.
I did a very simple benchmark: load a 10,000 x 10,000 pixel RGB tif, crop 100 pixels off every edge, shrink 10%, sharpen, and save again. On this trivial test at least, vips is more than twice as fast as anything else I've tried.
The C++ API is documented here. For example:
#include <vips/vips8>
using namespace vips;
int
main( int argc, char **argv )
{
// startup, load plugins, init support libraries, etc.
if (VIPS_INIT(argv[0]))
vips_error_exit(NULL);
// the "sequential" access hint means we plan to only read this image
// top-to-bottom (eg. no 90 degree rotates) ... this means libvips can
// stream the image and run decode and processing in
// parallel on separate threads
VImage image = VImage::new_from_file(argv[1],
VImage::option()->set("access", "sequential"));
// shrink to 20% and find the histogram
VImage hist = image.resize(0.2).hist_find();
hist.write_to_file(argv[2]);
return 0;
}
You can run this program with any input and output image format, for example:
$ g++ -g -Wall resize.cpp `pkg-config vips-cpp --cflags --libs`
$ ./a.out ~/pics/wtc.jpg x.csv
And it'll read the JPG input and write the histogram to the CSV file.
There is a simple and free open source cross-platform image processing library Simd. As follows from its description:
It provides many useful high performance algorithms for image processing such as: pixel format conversion, image scaling and filtration, extraction of statistic information from images, motion detection.
The algorithms are optimized with using of different SIMD CPU extensions: SSE, SSE2, SSSE3, SSE4.1, SSE4.2, AVX, AVX2 and AVX-512 for x86/x64, VMX(Altivec) and VSX(Power7) for PowerPC, NEON for ARM.
You might want to look at IM. It builds on several platforms, and has support for (modular) image file formats, a variety of image representations, and a wide array of transformations and operators. A GUI tool, IMLab, for demonstrating image processing operators based on the IM library is also available.
There are also VTK and ITK, with a huge amount of manifold image processing algorithms.
There are also:
Framewave based on AMD Performance Library which provides signal and image processing features
GraphicsMagick multi-threaded derivative from ImageMagick
ExactImage is a fast C++ image processing library. Unlike many other library
frameworks it allows operation in several color spaces and bit depths
natively, resulting in low memory and computational requirements.
We used Accusoft for quite a while, but for very specific reasons we switched to LeadTools, which exists for windows only.
Accusoft has a very clear and much more well defined interface than leadtools. Both libraries are very robust and both claim to read more or less all existing file types. Both also have quite responsive support.