CLIP
C++ Library for Image Processing (CLIP) is a simple C++ library written at the Hebrew University of Jerusalem at the late 1990s and was used as a very basic tool at the Hebrew University, Haddassa College, and even had some commercial application.
CLIP is a core library - it provides tools to write image processing code with, but only a minimal set of functions are provided. Clip also is not and was never meant to be very efficient (it was originally meant to be a prelude for a compiler).
However, CLIP has features that make it very comfortable for quick testing, among them:
•CLIP is compact - CLIP programs tend to be very short.
•CLIP image types are also C++ data types, there are no implicit type descriptor anywhere.
•CLIP in-memory images are separated from the file format - this limits the functionally, but makes CLIP more comfortable to use.
•CLIP is multi-platform, though having real-pipes (Unix variants, including Mac-OS) makes it more comfortable to use.
Let’s look at a simple example. In this example we read a PNM format image from the standard input, convert it (if needed) to float grayscale type using proper coefficients, compute for each pixel x, its dB value 20 log(x+1) then convert back to byte and save the output to standard output also in PNM format.
1.#include "pnm_env.h"
2.int main()
3.{
4. fMonoImg img = pnm(stdin);
5. fMonoImg res = (img+1).map(log10f)*20;
6. pnm((bMonoImg) res).Write(stdout);
7. return 0;
8.}
Line (1) includes all the necessary CLIP definitions,
Line (4) reads a color or grayscale PNM format byte image, then convert it into the assignee (img)type which is a monochromatic float image type.
Line (5) applies the standard function log10f to each pixel, multiplies the resulting image by 20, and saves the result in (res).
Line (6) converts the results back to byte (monochromatic) image and sends it to the standard output.
CLIP’s initially only read and write PNM files. The intent was to keep CLIP minimal, and use external program such as ImageMagick Convert to convert between datatypes, for example:
convert inputImage.jpg pnm:- | img_dB | convert - outputImage.tiff
where img_dB is the program above, will read a JPG image apply the above computation and save the result as tiff image. Note that a multicore machine will run the three process in parallel using UNIX pipe buffers. Also note that the conversion to grey-scale can be done by the Convert program using “pgm:-” i.o. “ppm:-”. In this case img_dB will not need to convert inside.
Writing filters this way and chaining them using UNIX pipes can be very useful, however the conversion to and from byte image and float images is not only inefficient, but it also hurts the accuracy due to rounding error. For this reason CLIP supports private extensions to PNM that allow float images (both grey and color) to be saved. Note that these files are meant to be used locally and are not compatible across architectures with different byte ordering (Endian). To use these extensions all that is needed is to remove the cast operator “(bMonoImg)” from line (6). The compiler knows that “res” is monochromatic float type and will automatically output this type. The program will also accept float input format - no change is needed.
Finally, we do not really need the two image variables “img” and “res”, and can write the entire program as follows:
1.#include "pnm_env.h"
2.int main()
3.{
4. pnm((bMonoImg)((((fMonoImg) pnm(stdin))+1).map(log10f)*20)).Write(stdout);
5. return 0;
6.}
The programs is reduced to a single statement that can read (gray,color) x (byte, float) extended PNM input files from the standard input, convert it, if needed, into float monochromatic image, compute its pixels dB value convert back to byte image and send the result to the standard output.
This is arguably the shortest programs that can perform this task as any program must have at least one statement.
(auto-level)