The CImg Library is a small and open-source C++ toolkit for image processing

Overview

Logo

http://cimg.eu

The CImg Library is a small and open-source C++ toolkit for image processing, designed with these properties in mind:

Usefulness CImg defines classes and methods to manage images in your own C++ code. You can use CImg to load/save various file formats, access pixel values, display/transform/filter images, draw primitives (text, faces, curves, 3d objects, ...), compute statistics, manage user interactions on images, and so on...

Genericity CImg defines a single image class able to represent datasets having up to 4-dimensions (from 1d scalar signals to 3d hyperspectral volumetric images), with template pixel types (bool,char,int,float,...). It also handles image collections and sequences.

Portability CImg is self-contained, thread-safe and highly portable. It fully works on different operating systems (Unix,Windows,MacOS X,*BSD,...) and is compatible with various C++ compilers (Visual C++,g++,clang++,icc,...).

Simplicity CImg is lightweight. It is made of a single header file CImg.h that must be included in your C++ source. It defines only four different classes, encapsulated in the namespace cimg_library. It can be compiled using a minimal set of standard C++ and system libraries only. No need for exotic or complex dependencies.

Extensibility Although not mandatory, CImg can use functionalities of external tools/libraries such as Board, FFMPEG, FFTW3, GraphicsMagick, ImageMagick, Lapack, libcurl, libjpeg, libpng, libtiff, Magick++, OpenEXR, OpenCV, OpenMP or XMedCon. Moreover, a simple plug-in mechanism allows any user to directly enhance the library capabilities according to their needs.

Freedom CImg is a free, open-source library distributed under the CeCILL-C (close to the GNU LGPL) or CeCILL (compatible with the GNU GPL) licenses. It can be used in commercial applications.


CImg stands for Cool Image : It is easy to use, efficient and is intended to be a very pleasant toolbox to design image processing algorithms in C++. Due to its generic conception, it can cover a wide range of image processing applications.


Issues
  • RGB to XYZ

    RGB to XYZ

    Hi David,

    I'm going through the colourspace conversion code at the moment, and I've noticed that sRGB -> RGB -> XYZ doesn't yield the expected results. It seems that in the RGBtoXYZ code, you use a D50 white point instead of the standard D65 (as far as I can tell from http://brucelindbloom.com/index.html?Eqn_XYZ_to_RGB.html). Any reason why that is so? Thanks!

    opened by dahtah 41
  • Open big raw, analyze and nifti files fail

    Open big raw, analyze and nifti files fail

    Hi everyone,

    When trying to load a large raw file, I've got very strange behaviour, only the n first slice are loaded, the rest is empty (0 value). All is fine with smaller files.

    I tried to get the minimal code producing error, but I obtained something different: at a certain image size, the file is not load at all (16GB for me), see http://pastebin.com/VxEfe3KF

    Do you have any idea ?

    opened by uxhub 29
  • How to save large tif files ?

    How to save large tif files ?

    Hello,

    I've a segmentation fault error when saving large tif file. The saving process write (float) image up to 8.6go and crash, (unsigned char) image up to 2.2go and crash. It works fine with smaller files and I don't have any problem by using RAW format with large files. Any idea to solve my problem ? is it a libtiff issue ? (Btw I used #define cimg_use_tiff and libtiff.so.5).

    Best regards,

    opened by uxhub 21
  • OpenMP problem with Intel compiler

    OpenMP problem with Intel compiler

    I'm copying and pasting from an imager issue. There seems to be an OpenMP problem that the Intel compiler picks up and gcc/clang don't:

    ../inst/include/CImg.h(28776): error: parallel loops with collapse must be perfectly nested
    for (int c = c0; c<(int)sc; c+=spectrum())
    ^
    detected during:
    instantiation of "cimg_library::CImg cimg_library::CImg::get_resize(int, int, int, int, int, unsigned int, float, float, float, float) const [with T=unsigned char]" at line 28711
    instantiation of "cimg_library::CImg &cimg_library::CImg::resize(int, int, int, int, int, unsigned int, float, float, float, float) [with T=unsigned char]" at line 58816
    instantiation of "const cimg_library::CImgList<cimg_library::CImgList::ucharT> &cimg_library::CImgList::font(unsigned int, bool) [with T=unsigned char]" at line 44013
    instantiation of "cimg_library::CImg &cimg_library::CImg::draw_text(int, int, const char *, const tc1 *, const tc2 *, float, unsigned int, ...) [with T=unsigned char, tc1=unsigned char, tc2=unsigned char]" at line 59949
    instantiation of "int cimg_library::cimg::dialog(const char *, const char *, const char *, const char *, const char *, const char *, const char *, const char *, const cimg_library::CImg &, bool) [with t=unsigned char]" at line 60088
    
    Error: the OpenMP "single" pragma must not be enclosed by the "for" pragma
    detected during:
    instantiation of "cimg_library::CImg cimg_library::CImg::get_resize(int, int, int, int, int, unsigned int, float, float, float, float) const [with T=unsigned char]" at line 28711 of "../inst/include/CImg.h"
    instantiation of "cimg_library::CImg &cimg_library::CImg::resize(int, int, int, int, int, unsigned int, float, float, float, float) [with T=unsigned char]" at line 58816 of "../inst/include/CImg.h"
    instantiation of "const cimg_library::CImgList<cimg_library::CImgList::ucharT> &cimg_library::CImgList::font(unsigned int, bool) [with T=unsigned char]" at line 44013 of "../inst/include/CImg.h"
    instantiation of "cimg_library::CImg &cimg_library::CImg::draw_text(int, int, const char *, const tc1 *, const tc2 *, float, unsigned int, ...) [with T=unsigned char, tc1=unsigned char, tc2=unsigned char]" at line 59949 of "../inst/include/CImg.h"
    instantiation of "int cimg_library::cimg::dialog(const char *, const char *, const char *, const char *, const char *, const char *, const char *, const char *, const cimg_library::CImg &, bool) [with t=unsigned char]" at line 60088 of "../inst/include/CImg.h"
    
    opened by dahtah 17
  • Compile error using cimg version 168

    Compile error using cimg version 168

    When I tried to build a lib written a captcha on node 4.2.0 mac os 10.11.1, an error occurred: ../native/CImg.h:175:10: fatal error: 'initializer_list' file not found but when i use cimg version 156, it seems ok

    opened by lukywong 17
  • isosurface3d could be more efficient

    isosurface3d could be more efficient

    While browsing the code of isosurface3d(), I noticed that the number of call to func could be reduced with a factor 4. Indeed, calls to func are used to populate values2 4 cells at a time, while 3 of those cells already contain the proper data from previous iterations. I created a local branch which implement a single func call data update, along with the required initialization (the first line and row of values2 need to be pre-computed) that give the exact same result as the original implementation while being more efficient.

    See pull request : https://github.com/dtschump/CImg/pull/263

    opened by UlysseV 15
  • Gaussian blur not working as expected

    Gaussian blur not working as expected

    I'm trying to see if CImg can duplicate the Photoshop Gaussian blur exactly, but I end up with an invalid image when using is_gaussian = true.

    Test program:

    CImg<unsigned char> image("lena.jpg");
    
    // sigma, boundary_conditions, is_gaussian
    image.blur(1.0, true, true);
    image.save("lena_blur_gaussian.png");
    

    Resulting image:

    lena_blur_gaussian

    Any idea what went wrong? If I change is_gaussian to false, I get a properly blurred image, but this image does not match what Photoshop produces :(

    opened by casper 14
  • CImg,h needs to be modified to avoid compiler errors

    CImg,h needs to be modified to avoid compiler errors

    In file Cimg.h, line# 6164 to 6180, marked //LG below, must be deleted to avoid two compiler errors on Microsoft Windows OS : "undefined reference to _fseeki64" and "undefined reference to _ftelli64 "

    e.g. These compiler errors are generated by the stmt: CImg img ("MyFileName.bmp") ;

    line# 6164 to 6180 are as follows (with deleted lines marked //LG ): //! Version of 'fseek()' that supports >=64bits offsets everywhere (for Windows). inline int fseek(FILE *stream, cimg_long offset, int origin) { //LG #if cimg_OS==2 //LG return _fseeki64(stream,(__int64)offset,origin); //LG #else return std::fseek(stream,offset,origin); //LG #endif }

    //! Version of 'ftell()' that supports >=64bits offsets everywhere (for Windows).
    inline cimg_long ftell(FILE *stream) {
    

    //LG #if cimg_OS==2 //LG return (cimg_long)_ftelli64(stream); //LG #else return (cimg_long)std::ftell(stream); //LG #endif }

    opened by pwplus7 14
  • mathematical morphology: erosion and dilation with an empty mask

    mathematical morphology: erosion and dilation with an empty mask

    Dear David

    erosion and dilation with an empty mask give unexpected results:

    #include <CImg.h>
    #include <iostream>
    using namespace cimg_library;
    
    int main()
    {
      CImg<double> im(10,10),out(im);
      CImg<double> msk(3,3);
      im.fill(1);
      msk.fill(0);
      out = im.get_erode(msk);
      std::cout << "Min: " <<out.min() << std::endl; 
      out = im.get_dilate(msk);
      std::cout << "Min: " <<out.min() << std::endl;
      return 1;
    }
    

    Depending on which definition of erosion and dilation we go for, the output could be 0 or undefined or the original image, but probably not the current output. Also, the implementation uses a convolution convention for the mask, instead of a filtering convention. It's a bit counter-intuitive, I suppose it's too late to change things, but maybe it should be documented, or maybe an option to follow the filtering convention should be added?

    opened by dahtah 14
  • Rotate & Crop an image takes a lot of time

    Rotate & Crop an image takes a lot of time

    Hello and thanks for a great library!

    So, the issue is - I'm trying to crop a rotated rectangle from an image, therefore I use this code:

    CImg<unsigned char> image;
    image.assign(file_source_path);
    image.rotate(angle, 0, 0).crop(left, top, left + width, top + height).save(file_result_path);
    

    The result is correct, but it takes more than 20 seconds to crop 1000x1000 px region from 4000x5600 px jpeg image. I was also trying to pass different parameters to rotate function, but the nearest type of interpolation seems to be the fastest (linear & cubic took up to 40 seconds). Same for boundary conditions.

    However when I'm using OpenCV library to perform the same task with the same image, it takes just 2±1 seconds.

    Example code:

    Mat src = imread(file_source_path, CV_LOAD_IMAGE_UNCHANGED);
    Point2f center(src.cols/2.0, src.rows/2.0);
    Mat rot = getRotationMatrix2D(center, angle, 1.0);
    Rect bbox = RotatedRect(center,src.size(), angle).boundingRect();
    rot.at<double>(0,2) += bbox.width/2.0 - center.x;
    rot.at<double>(1,2) += bbox.height/2.0 - center.y;
    
    Mat dst;
    warpAffine(src, dst, rot, bbox.size());
    Rect myROI(left, top, width, height);
    Mat croppedImage = dst(myROI);
    
    imwrite(file_result_path, croppedImage, vector<int>({CV_IMWRITE_JPEG_QUALITY, 80}));
    

    But I don't want to include OpenCV into my project, you library seems to have everything that I need and still very small.

    So the question is, am I doing something wrong? Can I optimize the time for such operation and how? Thanks in advance.

    opened by shliama 14
  • GraphicsMagick not working with CImg

    GraphicsMagick not working with CImg

    I believe I can either install imagemagick OR graphicsmagick for cimg to handle jpg, png, etc.

    I installed graphicsmagick, without imagemagick, cimg gives error 'sh: 1: convert: not found'.

    Looking at the source, graphicsmagick will be used if an exception is caught when trying imagemagick. It seems no exception is thrown in this case and the code just terminates.

    I swapped the try sequence and get graphicsmagick to work but doing that the situation is just reversed: installed imagemagick will be not used if cimg finds that graphicsmagick is missing ('sh: 1: gm: not found').

    By the way, using Debian 8.

    try { load_magick(filename); } catch (CImgException&) { try { load_imagemagick_external(filename); } catch (CImgException&) { try { load_graphicsmagick_external(filename); } catch (CImgException&) { try { load_cimg(filename); } catch (CImgException&) { try { std::fclose(cimg::fopen(filename,"rb")); } catch (CImgException&) { cimg::exception_mode(omode); throw CImgIOException(_cimg_instance "load_other(): Failed to open file '%s'.", cimg_instance, filename); } cimg::exception_mode(omode); throw CImgIOException(_cimg_instance "load_other(): Failed to recognize format of file '%s'.", cimg_instance, filename); } } } }

    opened by sylvester328 12
  • png file not reading and returning error: in function `cimg_library::cimg::Mutex_static::trylock(unsigned int)':

    png file not reading and returning error: in function `cimg_library::cimg::Mutex_static::trylock(unsigned int)':

    I was trying to read and show .png image, Ubuntu 22.04. I simply added the CImg.h to my C++ project. Tried with g++ compiler, as well as CLion CMake Project. I tried in all possible way to read and show the image. But each time it is generating error in function cimg_library::cimg::Mutex_static::trylock(unsigned int):. What I am doing wrong?

    //#define cimg_use_png
    #include "CImg.h"
    using namespace cimg_library;
    
    int main()
    {
    CImg<unsigned char> image("images.png");
    //CImg<unsigned char> image2 = (image/=(image.max()>255?257:1));
    //image2.display();
    
    CImgDisplay dispWindow(image, "window name");
      while (!dispWindow.is_closed())
      {
        dispWindow.wait();
      }
    
    return 0;
    }
    
    opened by bipul-mohanto 1
  • save tiff files using ZIP compression

    save tiff files using ZIP compression

    Hi all, I am using the save_tiff method to save images in tiff format. The compression type parameter specifies if using no compression (value = 0), LZW compression (value = 1) or JPG compression (value = 2). I know tiff images support also zip compression. Is it possibile to specify the ZIP compression in the save_tiff method? Thanks. I appreciate a lot your work!

    opened by Magallo 2
  • Optimizing the output file

    Optimizing the output file

    Is it possible to use any compilation flags to reduce the size of the executable file? I use several functions of this library, but with -O3 the file still weighs about 800 kilobytes. Is it possible to make the size even smaller?

    OS: Solus Linux GCC: 11.2.0

    opened by AlexanderZhirov 1
  • Save as base64 in a variable

    Save as base64 in a variable

    It problem is that if you want to use the lib to make an image and send it to a remote server is impossible beavis it don't exist a function to save the data in a variable only to save it to a file.

    opened by TepMaster 0
  • Can CImg compile for iOS

    Can CImg compile for iOS

    Hi, When trying to compile for iOS (with Xcode) I will always have this issue: "CImg.h:5764:19: 'system' is unavailable: not available on iOS"

    Can this library be use on iOS?

    Thank you, Stay safe

    opened by asnagni 1
Owner
David Tschumperlé
I cut my teeth on Oric Atmos, Amstrad CPC, Atari 520 STE and Amiga 1200.
David Tschumperlé
C++ image processing and machine learning library with using of SIMD: SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, AVX, AVX2, AVX-512, VMX(Altivec) and VSX(Power7), NEON for ARM.

Introduction The Simd Library is a free open source image processing and machine learning library, designed for C and C++ programmers. It provides man

Ihar Yermalayeu 1.6k Jun 24, 2022
Video++, a C++14 high performance video and image processing library.

Video++ Video++ is a video and image processing library taking advantage of the C++14 standard to ease the writing of fast video and image processing

Matthieu Garrigues 681 Jun 14, 2022
ppl.cv is a high-performance image processing library of openPPL supporting x86 and cuda platforms.

ppl.cv is a high-performance image processing library of openPPL supporting x86 and cuda platforms.

null 318 Jun 10, 2022
A fast image processing library with low memory needs.

libvips : an image processing library Introduction libvips is a demand-driven, horizontally threaded image processing library. Compared to similar lib

libvips 16 Jun 19, 2022
GLSL Image Processing System

GIPS: The GLSL Image Processing System An image processing application that applies filters written in the OpenGL Shading Language (GLSL). This means

Martin Fiedler 52 Jun 15, 2022
Small header-only C library to decompress any BC compressed image

Small header-only C library to decompress any BC compressed image

null 61 Jun 29, 2022
PoC black/white image sequence to dumpy gif image sequence converter

PoC black/white image sequence to dumpy gif image sequence converter

null 63 Jun 27, 2022
The “Quite OK Image” format for fast, lossless image compression

The “Quite OK Image” format for fast, lossless image compression

Dominic Szablewski 5.6k Jun 24, 2022
Intel® Open Image Denoise library

Intel Open Image Denoise is an open source library of high-performance, high-quality denoising filters for images rendered with ray tracing

Intel® Open Image Denoise 1.3k Jul 1, 2022
This library provides a cross-platform image loading library in C11 for projects based on our foundation library

Image Library - Public Domain This library provides a cross-platform image loading library in C11 for projects based on our foundation library.

Mattias Jansson 1 Jan 29, 2022
A toolkit for making real world machine learning and data analysis applications in C++

dlib C++ library Dlib is a modern C++ toolkit containing machine learning algorithms and tools for creating complex software in C++ to solve real worl

Davis E. King 11.2k Jun 27, 2022
A computationally efficient and convenient toolkit of iterated Kalman filter.

IKFoM IKFoM (Iterated Kalman Filters on Manifolds) is a computationally efficient and convenient toolkit for deploying iterated Kalman filters on vari

HKU-Mars-Lab 170 Jun 24, 2022
Reading, writing, and processing images in a wide variety of file formats, using a format-agnostic API, aimed at VFX applications.

README for OpenImageIO Introduction The primary target audience for OIIO is VFX studios and developers of tools such as renderers, compositors, viewer

OpenImageIO 1.5k Jun 29, 2022
An open source library for face detection in images. The face detection speed can reach 1000FPS.

libfacedetection This is an open source library for CNN-based face detection in images. The CNN model has been converted to static variables in C sour

Shiqi Yu 11.1k Jun 28, 2022
Video, Image and GIF upscale/enlarge(Super-Resolution) and Video frame interpolation. Achieved with Waifu2x, SRMD, RealSR, Anime4K, RIFE, CAIN, DAIN and ACNet.

Video, Image and GIF upscale/enlarge(Super-Resolution) and Video frame interpolation. Achieved with Waifu2x, SRMD, RealSR, Anime4K, RIFE, CAIN, DAIN and ACNet.

Aaron Feng 7k Jun 29, 2022
a generic C++ library for image analysis

VIGRA Computer Vision Library Copyright 1998-2013 by Ullrich Koethe This file is part of the VIGRA computer vision library. You may use,

Ullrich Koethe 368 Jun 25, 2022
Arduino PNG image decoder library

An 'embedded-friendly' (aka Arduino) PNG image decoding library

Larry Bank 91 Jun 24, 2022
libvot - A C++11 multi-thread library for image retrieval

libvot is a fast implementation of vocabulary tree, which is an algorithm widely used in image retrieval and computer vision. It usually comprises three components to build a image retrieval system using vocabulary tree: build a k-means tree using sift descriptors from images, register images into the database, query images against the database. I

Tianwei Shen 166 Apr 8, 2022
An 'embedded-friendly' (aka Arduino) JPEG image encoding library

Starting in the late 80's I wrote my own imaging codecs for the existing standards (CCITT G3/G4 was the first). I soon added GIF, JPEG and not long after that, the PNG specification was ratified. All of this code was "clean room" - written just from the specification. I used my imaging library in many projects and products over the years and recently decided that some of my codecs could get a new lease on life as open source, embedded-friendly libraries for microcontrollers.

Larry Bank 34 Jun 21, 2022