Gimage: Yet another image library, for study

So, I started to look at what it would take to incorporate color management into my rawproc program. It’s a convoluted story I won’t bore you with here, but I ended up coding my own image library. Yes, yes, I know there are many good libraries, but I developed two reasons for taking this path: 1) having all of the LibRaw options available, and 2) assembling a basic set of image operations in one place for others to study. The second reason has roots in my previous career as a teacher, I guess; my personal learning of image processing has been a convoluted journey, and I thought there’d be benefit to consolidating it all in one place for others to capitalize.

(geesh, could do without the picture here…)

I need to give a nod to the FreeImage library; it provided an excellent platform upon which to start my study. Where I ran into roadblocks was with access to the LibRaw options; the 32-bit flags parameter really limited this. I ended up defining options as a c++ map of name=value pairs, which provides both a lot of capability to pass booleans and values, as well as a straightforward path from command line parameters to the library.

In a nod to G’MIC, I simplified my internal image representation to floating-point RGB, 0.0-255.0. This impacts some computational efficiency, but it really simplifies the processing functions for better understanding, as well as promotes better-image quality after repeated manipulations.

The essential reason I’m posting here is to point others who want to study basic image processing to gimage.cpp, where I’ve provided narrative comments for the various functions, as well as cites to the supporting literature. No Richardson-Lucy, no wavelets, no layers, just the basic operations in what I hope is a clear and concise presentation in C++. This part of the endeavor is really a response to the poster of a few months ago who was looking for sources to study basic image processing, A detailed description of the image processing algorithms used by RT.

Also in here is a command line program I’ve used to test as I go, gimg.cpp. I’ve been using its rawproc progenitor, img.cpp, to do batch processing; when I implemented wildcard file processing it became really useful. gimg will do the same sort of thing:

$gimg "*.NEF:gamma=srgb,autobright" contrast:10 resize:640,0 sharpen:1 "*.jpg"

reads all the Nikon NEF raws in the directory, applies LibRaw gamma and autobright, gimage contrast, resize, and sharpen, and saves them as correspondingly named JPEGs. No shell antics, but you do have to put the parameters with “*” in them in quotes to keep the shell processors from expanding them for you.

Compiling gimage may be daunting right now; you first need to download the participating LibRaw, llibtiff, and libjpeg libraries if you don’t already have them in your gcc library paths and compile them. You’ll need to mess with the Makefile to point to the right places. The Makefile recognizes a build/ directory in which you can put a localmake.txt file to define your particular things without disturbing the github-cloned Makefile in the parent directory. And so on. Later, I’ll make it easier to build, but that’s not my first priority.

Anyway, what I’m after here is not code reuse so much as education; if others find such a compendium useful in that regard, that’d make the effort worthwhile.

4 Likes

A bit of change has happened in the library. Thanks go to @floessie, with whom I had a really constructive bit of dialogue in the github issue page about better use of C++. Now, gImage uses a vector of pix structs for its image storage, and the only pointers left are for dealing with the image format libraries and the resize algorithm copied from Graphics Gems. It’s not complete, but gImage is now a more comprehensive but simple illustration of a C++ image library, and I now have a better perspective on C++ for the effort.

Now, I’m returning focus to my rawproc program, as this excursion in library writing was originally meant to enable color management there. So, you’ll see additional methods show up for color profile conversions, as I figure out how to best incorporate LittleCMS. Also, I’ll be adding more parameters to the list of things you can tell LibRaw to do in raw processing, which might make the command line program more useful in real workflow.

I can’t remember that.

I apologize. I have confused you and someone who goes by “Floessie” on github, and I thought I’d correctly tied real names together with screen names, from emails.

I don’t think I’m fitting into the social media world too well. I mean, for example I’m too dense to come up with a different moniker than my real name for these things… :slight_smile:

1 Like

If I had to guess, that’d be @floessie but who really knows on the internet?

No need to apologize. But editing your post to give the credits to @floessie probably would be nice :wink:

Edit is done. Now, it’s back to the garage, where I have a home project to do that doesn’t require knowing folks’ names… :smiley:

1 Like

I take it as an honor being mistaken for @heckflosse. :smile:

Thanks, Mica, for correcting the name mapping. Glenn, don’t worry.

Best
Flössie