Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
load 32bit bmp

Subject: load 32bit bmp

From: mut

Date: 24 Oct, 2008 11:17:01

Message: 1 of 6

hi all:

i have some bmp files with 32 bit depth. i load then with imread:
ui8Img = imread(strImgFName, 'bmp');

size(ui8Img)
ans =
        786 1180 3

now i want to find the location for a specific color:
ui8FindColor = uint8([ 0 255 255]);

the problem starts here....
the problem is the need to load all 32bits from the bmp file so i can discriminate, for instance, from uint8([ 0 255 255 0]) to uint8([ 0 255 255 111])

if i load the image on to xnview, i can see with the color picker tool that 25:32 bits are different .

the file info is
stcImgInfo = imfinfo(strImgFName);
stcImgInfo.FormatVersion
ans =
       Version 3 (Microsoft Windows 3.x)

stcImgInfo.BitDepth
ans = 32

stcImgInfo.ColorType
ans = 'truecolor'

stcImgInfo.FormatSignature
ans = ''BM' (i don't know what BM stands for)

i have already read the doc imread and it says that imread supports 32bit files but it adds 1 byte padding. i don't quite understand what this means. does imread neglects 25:32 bits????

can anyone help me on how to load the 32bits per pixel from a bmp file???

help and comments are appreciated

thx in advance

mut

Subject: load 32bit bmp

From: ImageAnalyst

Date: 24 Oct, 2008 13:34:30

Message: 2 of 6

On Oct 24, 7:17=A0am, "mut" <mutant...@gmail.com> wrote:
> hi all:
>
> i have some bmp files with 32 bit depth. i load then with imread:
> ui8Img =3D imread(strImgFName, 'bmp');
>
> size(ui8Img)
> ans =3D
> =A0 =A0 =A0 =A0 786 =A0 =A0 =A0 =A01180 =A0 =A0 =A0 =A0 =A0 3
>
> now i want to find the location for a specific color:
> ui8FindColor =3D uint8([ 0 255 255]);
>
> the problem starts here.... =A0
> the problem is the need to load all 32bits from the bmp file so i can dis=
criminate, for instance, from uint8([ 0 255 255 0]) to uint8([ 0 255 255 11=
1])
>
> if i load the image on to xnview, i can see with the color picker tool th=
at 25:32 bits are different .
>
> the file info is
> stcImgInfo =3D imfinfo(strImgFName);
> stcImgInfo.FormatVersion
> ans =3D
> =A0 =A0 =A0 =A0Version 3 (Microsoft Windows 3.x)
>
> stcImgInfo.BitDepth
> ans =3D 32
>
> stcImgInfo.ColorType
> ans =A0=3D =A0'truecolor'
>
> stcImgInfo.FormatSignature
> ans =3D ''BM' =A0 (i don't know what BM stands for)
>
> i have already read the doc imread and it says that imread supports 32bit=
 files but it adds 1 byte padding. i don't quite understand what this means=
. does imread neglects 25:32 bits????
>
> can anyone help me on how to load the 32bits per pixel from a bmp file???=
 =A0
>
> help and comments are appreciated
>
> thx in advance
>
> mut
--------------------------------------------
mut:
If you have a file that is storing data in the last byte, then it's
not a standard BMP file. Here's what the standard says:

"The bitmap has a maximum of 2^32 colors. If the Compression field of
the bitmap is set to BI_RGB, the Palette field does not contain any
entries. Each dword in the bitmap array represents the relative
intensities of blue, green, and red, respectively, for a pixel. The
high byte in each dword is not used."
Reference: http://www.wotsit.org/list.asp?al=3DB

To find locations of a particular color (in the first 3 bytes because
the last byte is always supposed to be zero), then you can extract out
each color plane, compare it to the value for that particular plane
that you are wanting to find (this will create a logical image for
each color plane), then AND together the 3 resultant comparison
logical images. Just 1 line of code, or up to 7 if you want to be
easier to read and more explicit and clear.
Regards,
ImageAnalyst

Subject: load 32bit bmp

From: mut

Date: 24 Oct, 2008 14:06:02

Message: 3 of 6

hi all:

first i would like to thanks your comment to my thread.

i've read the link you sent me about the .bmp standard. it became a bookmark due to its interesting information about file formats.

so what do you advise me to do??? as xnview reads the last byte, should i convert these images to a format like tiff that has an alpha channel, hoping that these bytes go into this channel so i can discriminate the pixels???? or can anyone think of something else???

should i code a load function for these images???

i'll try this at once and get back to you....

comments are appreciated.:)

thanks in advance

Subject: load 32bit bmp

From: mut

Date: 24 Oct, 2008 14:27:02

Message: 4 of 6

hi all:

the suggestion i've made works... batch convert the bmp files to tiff revision 6 and then load them with imread... the 4th byte comes in the 4th plane.....

although i got a workaround for this issue, it's not an elegant one.... besides the solution i've preaviously mentioned of coding a loading function does anyone has any suggetions???

comments are appreciated..

see you, thanks

Subject: load 32bit bmp

From: hoffmann@fho-emden.de

Date: 26 Oct, 2008 13:41:15

Message: 5 of 6



mut schrieb:
> hi all:
>
> i have some bmp files with 32 bit depth. i load then with imread:
> ui8Img = imread(strImgFName, 'bmp');
>
> size(ui8Img)
> ans =
> 786 1180 3
>
> now i want to find the location for a specific color:
> ui8FindColor = uint8([ 0 255 255]);
>
> the problem starts here....
> the problem is the need to load all 32bits from the bmp file so i can discriminate, for instance, from uint8([ 0 255 255 0]) to uint8([ 0 255 255 111])
>
> if i load the image on to xnview, i can see with the color picker tool that 25:32 bits are different .
>
> the file info is
> stcImgInfo = imfinfo(strImgFName);
> stcImgInfo.FormatVersion
> ans =
> Version 3 (Microsoft Windows 3.x)
>
> stcImgInfo.BitDepth
> ans = 32
>
> stcImgInfo.ColorType
> ans = 'truecolor'
>
> stcImgInfo.FormatSignature
> ans = ''BM' (i don't know what BM stands for)
>
> i have already read the doc imread and it says that imread supports 32bit files but it adds 1 byte padding. i don't quite understand what this means. does imread neglects 25:32 bits????
>
> can anyone help me on how to load the 32bits per pixel from a bmp file???
>
> help and comments are appreciated
>
> thx in advance
>
> mut

Subject: load 32bit bmp

From: hoffmann@fho-emden.de

Date: 26 Oct, 2008 13:46:49

Message: 6 of 6



mut schrieb:
> hi all:
>
> i have some bmp files with 32 bit depth. i load then with imread:
> ui8Img = imread(strImgFName, 'bmp');
>
> size(ui8Img)
> ans =
> 786 1180 3
>
> now i want to find the location for a specific color:
> ui8FindColor = uint8([ 0 255 255]);
>
> the problem starts here....
> the problem is the need to load all 32bits from the bmp file so i can discriminate, for instance, from uint8([ 0 255 255 0]) to uint8([ 0 255 255 111])
>
> if i load the image on to xnview, i can see with the color picker tool that 25:32 bits are different .
>
> the file info is
> stcImgInfo = imfinfo(strImgFName);
> stcImgInfo.FormatVersion
> ans =
> Version 3 (Microsoft Windows 3.x)
>
> stcImgInfo.BitDepth
> ans = 32
>
> stcImgInfo.ColorType
> ans = 'truecolor'
>
> stcImgInfo.FormatSignature
> ans = ''BM' (i don't know what BM stands for)
>
> i have already read the doc imread and it says that imread supports 32bit files but it adds 1 byte padding. i don't quite understand what this means. does imread neglects 25:32 bits????
>
> can anyone help me on how to load the 32bits per pixel from a bmp file???
>
> help and comments are appreciated
>
> thx in advance
>
> mut

BMP-32 stores four bytes in this order: ARGB
The most significant byte A is not an alpha channel but
an arbitrary channel - up to the user. It's not required that
A is 0. I had used A for numbering selections in images.
The decoding of a 32 bit color word C works as follows:

Given C=ARGB
Define a mask M=000Fh
D=M AND C
Copy the value into a byte B
B=D
Shift right by 8 bits
D=M AND (C SHR 8)
G=D
D=M AND (C SHR 16)
R=D
D=M AND (C SHR 24)
A=D

The implementation depends on the programming language.
Sorry, don't know how to do this in MatLab.

Best regards --Gernot Hoffmann

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us