![]() |
|
#41
|
|||
|
|||
Re: How to get the pixels' value of a bmp image? (Pelles C)Ι have found the errors in my program. Since the header file is 40 it means that it is not a V5 infoheader. I commented out the unecessary structs and variables from the header file. Now it works. However my new output is this one :
Size of File Header is : 14 Size of File Header is : 40 Bmp File Type is : 4d42 Bmp Size is : 263222 Bmp Reserved One is : 0 Bmp Reserved Two is : 0 Bmp Header Offset is : 1078 Bmp Header Size is : 40 Image Width is : 512 Image Height is :512 Image bpp is : 8 Image Compression is : 0 Bytes in pixel data section are : 262144 File Pointer at the beginning of storing to the 2D array is : 1078 File Pointer at the end of storing to the 2D array is : 263222 Total Number of bytes read into the array is : 262144 Why is the Header Offset 1078? What happens from byte 54 to 1078? Empty bytes with junk? |
|||
|
#42
|
|||
|
|||
Re: How to get the pixels' value of a bmp image? (Pelles C)Ιt was the pallete that I was missing! Now everything works!
|
|
#43
|
|||
|
|||
Re: How to get the pixels' value of a bmp image? (Pelles C)hi silvermaul/dave,
could you please guide me as to how those pallettes were corrected? appreciate your help very much... regards, vk |
|
#44
|
|||
|
|||
Re: How to get the pixels' value of a bmp image? (Pelles C)I used a grayscale to save the pallete into a different .raw file and then is used it as a reference with all my bmps. The pallete is the same in all bmps. I also used it to convert 24bmp to 8bit grayscale bmp and it works.
Hope this helps. |
|
#45
|
|||
|
|||
Re: How to get the pixels' value of a bmp image? (Pelles C)Quote:
Hi Silvermaul, Thank you very much for the reply. When I used a standard grey scale picture such as the one below, ![]() I get the following output Code:
please suggest a method to overcome this problem. Thanks a lot in advance. |
|
#46
|
|||
|
|||
Re: How to get the pixels' value of a bmp image? (Pelles C)Quote:
How about showing us the program that gave that output? See Footnote. I have a program that reads that bitmap just fine. Code:
Bottom line: I respectfully suggest that in order to get help, you show us exactly what code you are using. This is always important. Also, tell us what compiler and what version of compiler you are using. Sometimes it makes a difference to people who would like to help. Regards, Dave Footnote: I am going to guess what happened when you wanted to make a program to read the bitmap in your post. Now, if you didn't do what I am about to show, then I apologize for wasting everyone's time (and board bandwidth). I hate to repeat myself, but the point remains: Show us what you are working with. Maybe someone can help. Here's my guess: If you used my example program from post number 28 in this thread as a starting point note the following
The moral of the story: Eliminating annoying messages doesn't always lead to a satisfactory solution. I gave some links to places with information about bitmap file formats In post number three of this thread. They are all still live but Microsoft has moved theirs to mdsn Bitmap Storage Reference, and some day they may delete the original link. Last edited by davekw7x : 25-Jun-2009 at 11:47.
|
|
#47
|
|||
|
|||
Re: How to get the pixels' value of a bmp image? (Pelles C)Hi Dave,
Thanks for your reply. As a staratup, i am using the code that you suggested in Thread 28. I would post the code here: CPP / C++ / C Code:
Quote:
Code:
As I am a beginner in this area, I am still not able to understand the pallete differences. What I understand is the differences in the pallete and the bit count of the bitmap could be the reason. How were you able to read the index value at [171][170]. I am using Visual Studio 2008. Dave,Please help me.Appreciate your help very much. Regards Last edited by admin : 26-Jun-2009 at 01:47.
Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
|
|
#48
|
|||
|
|||
Re: How to get the pixels' value of a bmp image? (Pelles C)Quote:
Hmmm... When I compile that with Visual C++ version 8, I get the following: Code:
This is consistent with my "real" bitmap reader, and is not exactly what you posted earlier. Oh, well... Quote:
Instead of talking endlessly about all of the things that could happen in a bitmap file, I will try to explain exactly what this file contains: 1. The two headers have a total length of 54 bytes. 2. Since the number of bits per pixel is equal to 8, there is a color table. Each entry in the color table consists of four bytes. The four bytes are the green, blue and red intensity values and there is a zero-byte. Each of the color bytes has a value from zero through 255. The color table itself could have as many as 1024 entries. 3. After the color table, there is one unsigned character for each pixel. The value of the unsigned char is used as an index into the color table, where the rgb values can be found for that pixel. 4. The actual length of the color table is obtained by subtracting the length of the two headers from the fheader.offset value. In this particular picture, fheader.offset is equal to 1078 - 54 = 1024 bytes. 5. So: After reading the headers, you know the length of the color table and you read that many bytes into the table. Then and only then do you start reading pixel values. One byte per pixel. The pixels occur sequentially a row at a time. The very first pixel is at the lower left hand corner of the picture. 6. One minor additional complication: The number of data bytes on each row in the file must always be a multiple of four. Your picture has 512 pixels per row, and this is a multiple of four, so there are no extra bytes. If your picture had 511 bytes, then each data row would consist of 511 pixel bytes and one zero "padding" byte. 7. Anyhow, you can read the data bytes one at a time for each row and use the values as follows: CPP / C++ / C Code:
Output: Code:
Now, it's possible that the color table could have been created differently. Maybe it's a real color picture, not a gray-scale, in spite of its appearance. By examining the file itself, we can see that this particular color table has rgb values of 0x000000, 0x010101, 0x020202, ... 0xffffff, which is a linear "gray ramp", but sometimes the values are not exactly linear, as might happen if someone played with the "curves" (in Photoshop for example) to alter contrast and other visual characteristics. You could even do stuff like make the picture come out negative by just changing the color table and not the pixel data values themselves. What I'm trying to say is that for this particular picture's color table the pixel byte value is actual equal to the gray-scale intensity, but that's not always the case. Regards, Dave Footnote: This program is for illustration purposes. If I were doing some heavy-duty picture processing, I would probably not just make an array of integers for the color table, since accessing the individual color values is kind of compute-intensive. I'll leave refinements to people who are interested (if anyone out there is still awake). Also, of course, the number of rows and columns are generally not known ahead of time, so dynamic allocation of the data buffer would, undoubtedly, be used in a more generally useful program. I have personally dealt with bitmaps that have one bit per pixel, two bits per pixel, and four bits per pixel as well as eight and 24 bits per pixel. Everything with eight or fewer bits per pixel will have a color table. For the smaller numbers, the pixel data are stuffed into the bytes and have to be extracted by shift/mask operations. This is the C++ board, but I have shown how one might do it in C. For C++ (and, actually for C) I would probably make a "bitmap structure" or class that would allow me to treat the bitmap as an object. User programs could call functions to read and write files without user having to struggle with individual fields of the headers. Stuff like that. |
|
#49
|
|||
|
|||
Re: How to get the pixels' value of a bmp image? (Pelles C)Quote:
In my sample code I declared the color table to be an array of 1024 integers. It could have been 256 integers. Dave |
|
#50
|
|||
|
|||
Re: How to get the pixels' value of a bmp image? (Pelles C)Thank you very much Dave. You are awfully fast in responding.The method you provided me was really helpful. I have some more problems which I ll try it out myself and then come to you if I am not able to solve it.
cheers! |
Recent GIDBlog
Once again, no time for hobbies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Question about locking surfaces to directly access pixels, SDL. | george89 | C++ Forum | 0 | 18-Jun-2006 22:16 |
| Pixels | dan_ielle20 | C++ Forum | 0 | 23-Mar-2005 09:54 |
| Checking source codes of image, audio and video files | onauc | C Programming Language | 5 | 26-Feb-2005 22:47 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The