Complete Samples

im_info

This is a command line application that displays information obtained from a file using the IM I/O functions, basically imFile functions. It depends only on the IM main library.

Here is an output sample:

IM Info
  File Name:
    exif_test.tif
  File Size: 9.00 Mb
  Format: TIFF - Tagged Image File Format
  Compression: NONE
  Image Count: 1
  Image #0
    Width: 2048
    Height: 1536
    Color Space: RGB
      Has Alpha: No
      Is Packed: Yes
      Is Top Down: Yes
    Data Type: byte
    Data Size: 9.00 Mb
    Attributes:
      YResolution: 72.00
      XResolution: 72.00
      DateTime: 2004:01:14 11:30:11
      Make: SONY
      ResolutionUnit: DPI
      Model: CD MAVICA
      Photometric: 2

You can view the source code here: im_info.cpp

im_copy

This is a command line application that copies all the information from one file to another using the IM I/O functions. It depends only on the IM main library. It is usefull for testing the drivers.

You can view the source code here: im_copy.cpp

proc_fourier

This is another command line application that process an image in the Fourier Frequency Domain. In this domain the image is a map of the spatial frequencies of the original image. It depends on the IM main library and on the IM_FFTW library. The FFTW is a very fast Fourier transform, but is contaminated by the GPL license, so everything must be also GPL. To use it in a commercial application you must contact the MIT and pay for a commercial license.

Se also Reference / Image Processing / Domain Transform Operations.

You can view the source code here: proc_fourier.cpp

im_view

This application uses IUP and CD to create a window with a canvas and draw the image into that canvas. It is a very simple application, no zoom nor scrollbar management. The image is obtained from a file using the IM I/O functions, but using the imImage structure to make the implementation easier.

For more IUP http://www.tecgraf.puc-rio.br/iup and more CD http://www.tecgraf.puc-rio.br/cd

You can view the source code here im_view.c, or download it with some makefiles im_view.zip.

glut_capture

This application uses GLUT and OpenGL to create a window with a canvas and draw the image into that canvas. But the image is obtained from a capture device. The image can be processed before display and a sequence of captured images can be saved in an AVI file during capture.

You can view the source code here: glut_capture.c

iupglcap

This application uses IUP and OpenGL to create a window with two canvases and draw a video capture image into one canvas. A processed image can be displayed in the second canvas. It can also process frames from a video file. It is very usefull for Computer Vision courses..

You can download the source code and projects for Visual C++, Borland C++ Builder X and Dev-Cpp, here: iupglcap.zip  You will need to download IUP, CD and IM libraries for the compiler you use

IMLAB

If you want to see a more complex application with all the IM features explored the IMLAB is a complete example. It displays each image in an individual image with zoom and pan capabilities. All the IM processing operations are available together with some extra operations.

For more IMLAB go to http://www.tecgraf.puc-rio.br/~scuri/imlab.

Lua Samples

To retreive information from an image file:

require"imlua"
local ifile, error = im.FileOpen(file_name)
local format, compression, image_count = ifile:GetInfo()
local format_desc = im.FormatInfo(format)
for i = 1, image_count do
   local width, height, color_mode, data_type, error = ifile:ReadImageInfo(i)
end
ifile:Close()    

To edit pixels in an image and save the changes:

require"imlua"

local image = im.FileImageLoad(filename)

local r = image[0]
local g = image[1]
local b = image[2]

for row = 0, image:Height() - 1, 10 do
	for column = 0, image:Width() - 1, 10 do
		r[row][column] = 0
		g[row][column] = 0
		b[row][column] = 0
	end
end

image:Save("edit.bmp", "BMP")

To render noise:

require"imlua"
require"imlua_process"
local image = im.ImageCreate(500, 500, im.RGB, im.BYTE)
im.ProcessRenderRandomNoise(image) 
image:Save("noise.tif", "TIFF") 

To render using the CD library:

require"imlua"
require"cdlua"
require"cdluaim"

local image = im.ImageCreate(500, 500, im.RGB, im.BYTE)
local canvas = image:cdCreateCanvas()  -- Creates a CD_IMAGERGB canvas

canvas:Activate()  
canvas:Background(cd.EncodeColor(255, 255, 255))
canvas:Clear()
fgcolor = cd.EncodeColor(255, 0, 0) -- red
fgcolor = cd.EncodeAlpha(fgcolor, 50) -- semi transparent
canvas:Foreground(fgcolor)
canvas:Font("Times", cd.BOLD, 24)
canvas:Text(100, 100, "Test")
canvas:Line(0,0,100,100)
canvas:Kill()

image:Save("new.bmp", "BMP")  

Check the file samples_imlua5.tar.gz or samples_imlua5.zip for several samples in Lua. For some of them you will need also the CD and the IUP libraries.