Sunday, January 30, 2011

Reading a bmp image directly in C++ : Part 1

For this we need to first understand the bmp file format

As illustrated by the figure below:

The bitmap image consists of 3 main parts:


1) Header ( Including the signature and the image info data)

2) Colour Profile

3) Image data


Image source: http://en.wikipedia.org/wiki/BMP_file_format

The header data is of size 54 bits. This can be observed by adding up the size requirements of the individual entries as written below. Also mentioned is the offset value for individual entries. An interesting observation is that the total size is not a multiple of 4 which might create several problems as in most compilers memory is read in chunks of 4 bytes.



offset size description
0     2      signature, must be 4D42 hex
2     4       size of BMP file in bytes (not very reliable)
6     2       reserved, must be zero
8     2       reserved, must be zero
10    4       offset to start of image data in bytes
14    4       size of BITMAPINFOHEADER structure, must be 40
18    4       image width in pixels
22   4       image height in pixels
26   2       number of planes in the image, must be 1
28   2       number of bits per pixel (1, 4, 8, or 24)
30   4       compression type (0=none, 1=Run Length Encoding (RLE)-8, 2=RLE-4)
34   4       size of image data in bytes (including padding, to make it a multiple of 4)
38   4       horizontal resolution in pixels per meter
42   4       vertical resolution in pixels per meter
46   4       number of colours in image, or zero
50   4       number of important colours, or zero



(To be continued in next post)

Friday, January 21, 2011

Increasing RAM using a USB drive

A disk cache component called ReadyBoost has been introduced by Microsoft in its two latest offerings Windows Vista and also Windows 7.

Although it is best to physical add new RAM to your system, it is possible to improve the performance by using an external hard drive by about 5-10% using flash memory, a USB flash drive, SD card, CompactFlash or any kind of portable flash mass storage system as a cache.

How to enable Ready Boost in your external disk:

1)Go to My Computer
2)Right click on your device
3)Select Properties
4)Click on the ReadyBoost tab
5)You can select various options/space allotment from there.

How to enable/disable Ready Boost in your system:

1)Go to the Control Panel menu option.
2)Click on Performance Information and Tools
3)Click on Advanced Tools in the left hand navigation bar.
4)Click on Configure my Windows ReadyBoost device
5) Select the options you want.

You can even check the performance imporvement by :


1) Go to Control Panel menu option. Change to classic view options

2) Click on the Administrative Tools icon.

3) Click on Reliability and Performance Monitor icon.

Under the monitoring tools category, click on performance monitor

Thursday, January 20, 2011

Matlab-4 Display multiple images, plots in a single window in MATLAB

How to display multiple images or graphs in a single window (frame) in MATLAB


This is done by using the subplot command in MATLAB

Suppose we have to display 4 images (aa,bb,cc,dd) in a single figure and arrange them in 2x2 fashion.

We will use the following commands:

figure;

subplot(2,2,1);imshow(aa);
subplot(2,2,2);imshow(bb);
subplot(2,2,3);imshow(cc);
subplot(2,2,4);imshow(dd);


similary to display two image in 2x1 fashion, we will use:

subplot(2,1,1);imshow(aa);
subplot(2,1,2);imshow(bb);