Sylvain Mareschal, Ph.D.
Bioinformatics engineer
August 6, 2011 at 14:41
Bitmap images
Here are a few tools to import bitmap files in R, i developed a few months ago for an image processing project. The read.bmp function reads a 24 or 32 bits bitmap file and returns a bmp object, which stores the data in a 3 dimensions array (height, width and color channel). The whole bitmap specification is not yet implemented, refinements such as compression or palettes are not supported, I may implement them in the future if needed.

bmp-class.R (click to download)

Defines the bmp S4 class and its methods.

Slots
@fileName : Unique character value, the path to the file read.
@fileSize : Unique integer value, the total size of the file in octets.
@height : Unique integer value, the height of the image in pixels.
@width : Unique integer value, the width of the image in pixels.
@colorMode : "L", "BGR" or "BGRA", according to the different color channels available.
@pixels : Three dimensions (height, width and color) array. Positions are non named dimensions, color is named with single letters : "L" stands for level in gray level bitmaps, "B","G" and "R" for the blue, green and red channels in 24 bits bitmaps and "A" for the alpha (transparency) component in 32 bits bitmaps.

Methods
show(object="bmp") : prints a textual summary of the S4 object.
plot(x="bmp") : X11 plotting of the image stored in the object.

read.bmp.R (click to download)

This function reads a 24 or 32 bits bitmap files and returns its content in a bmp object.

Arguments
fileName : Unique character value, the path to the file to read.

Value
Returns an object of class bmp.

bmp2gray.R (click to download)

This functions converts as 24 or 32 bits bmp object into a gray level bitmap object.

Arguments
object : The bitmap object to convert.

Value
Returns an object of class bmp.