I want to find blue areas on 24 bit bmp image. How can i find the blue color channel ? What is the ways of accessing the blue color channel ?
Blue Color Channel on bmp 24 bit file format
1.5k views Asked by user1138401 AtThere are 2 answers
A 24-bits bitmap (.bmp) image has a header of 54 bytes. After that comes the pixeldata. Per pixel, 3 bytes are used: blue, green, red, in that order.
To see this, make a 1x1 pixel image in paint and make the one pixel blue. If you view the .bmp file in a hexeditor you'll see the 55th byte has the value FF (blue), while the 2 after that are 00 (no green, no red). Ofcourse you can also see this if you write a C program that reads all the bytes. If you print the values from the 55th byte till the end, you'll see the same.
The pixeldata needs to be aligned, this is called stride. Stride is calculated as follow:
stride = (width * bpp) / 8;
In a 3x3 bmp, stride will be (3 * 24) / 8 = 9. This value needs to be rounded up to a number divisible by 4 (12 in this case), so you need 3 extra bytes per row to correctly align the bits. So if all bytes are blue, after the 54 byte you will have:
FF 00 00 FF 00 00 FF 00 00 00 00 00
FF 00 00 FF 00 00 FF 00 00 00 00 00
FF 00 00 FF 00 00 FF 00 00 00 00 00
For a 4x4 bmp, stride = (4 * 24) / 8 = 12. 12 is divisible by 4, so there are no extra bytes needed. For a 5x5 bmp, stride = (5 * 24) / 8 = 15, so 1 extra byte is needed per row.
To find out more info about the bmp file format, check out this wikipedia page. Hope this helps!
...from here.