Creating BMP (picture) files

Hi all,

I am planning the build of an Infrared temperature scanning camera. I want to use 2 servo's to pan and tilt a pyrosensor. There will be a fresnel lens in front of the sensor to focus.

This way I can generate a value for any given point of the subject together with the x,y coordinates. So far pretty simple to mnage on a picaxe.

Second is to know how to convert the measured values to an image of some format, usable on the computer. Does anyone know a usable image format and how the data in it is organised?
 

AllyCat

Senior Member
Hi Erik,

Well, certainly avoid .JPG and similar. ;)

As usual, wikipedia seems to have useful information and the header "This article may contain an excessive amount of intricate detail that may only interest a specific audience" may delight you. You probably need to use an "old" image format such as .BMP and might find that "tools" to create icons for systems such as car satnavs, etc., might be helpful.

For use with a PICaxe, you may need to create a "template" file in a drawing package (e.g. MS Paint) and then substitute values from the PICaxe data. What resolution (pixels x pixels) are you considering?

Cheers, Alan.
 
I looked into the 'raw' info on how to create a file from scratch.. Readable but still complicated.
I guess Allycat's idea to refill a already exsisting file might be a better idea indeed. Only fill the image-space of the file. Still need the technical info to recognise where the image-bits start but seems doable.

The resolution I didn't decide on, yet. It depends on the focus on the pyrosensor and fresnel lens I can archieve but, since I planned to use servo's to pan and tilt 256*256 will not be exceeded (actually... less than that because of the limitations of the servo's)

For higher resolutions I would need stepper motors and fine-focus on the sensor

The general idea is to make an image of -a part of the- the house on a cold winter day to find heat-leaking spots.

It will be a slow paced project I guess... but fun to have the picaxe creating imagefiles in the end.


And thanks... I guess I have a good starting point from here,

Erik
 
Last edited:

MFB

Senior Member
You might find the PIC32 based MaxiMite board will do the job on its own. It has servo outputs, ADC inputs and supports VGA or video graphics. Including the ability to save BMP files to an SD card. It is programmed using a structured Basic not unlike the PICAXE version.
 
The Maximite looks very intresting... I maybe even buy one. It has BASIC with linenumbers... not labels like the picaxe just like my ould TRS 80 had :)

But IF I buy one, it would not be for this project.
The SaveBMP in the manual claims to save the screen in a bmp file where the screen is monochrome (1 bit, black OR white). This will not do the trick I'm afraid because I need at least a grey-scale.
 

boriz

Senior Member
Will this device be connected to a PC or Laptop?

There are various free versions of Basic that can be used both to receive the serial data from the Picaxe and to save an image once it has been constructed on the screen. I'll see if I can find an example.
 

MFB

Senior Member
Erik, If you take a look at the mmbasic.com site you will see that things have moved on quite a bit. The current version now includes the very latest Basic features but you are correct in that only B&W graphics is supported. However, I understand that colour developments may be under way.
 
@MFB, Since I like the Picaxe too much, I will stick to it for this project. It's the fun of finding the limits of a given platform and defenately learnng from it.

I am thinking about a stand alone appliance that can be connected to a pc to download the picture (or copy it frm a memorycard)

Since I will have to write the filegenerator myself, it will support colours from day 1. No need to wait for anyone but myself :)
 

boriz

Senior Member
Then you're looking at something like a datalogger. Picaxe + EEPROM (Or static RAM). The raw data can be stored by the Picaxe and later uploaded to the PC where your PC software can draw an image on the screen and then save it as a BMP.

If you use 8 bit colour (256 distinct heat levels), and a resolution of 128^2 (optimistic in my view), then you're looking at 128*128 = 16k per image. Half that for 4 bit colour. Half again for 64^2 resolution.

This should do the job: http://www.techsupplies.co.uk/epages/Store.sf/en_GB/?ObjectPath=/Shops/Store.TechSupplies/Products/MIC050

@128/8bit, 2 images.
@128/4bit, 4 images.
@64/4bit, 8 images.

Etc..
 

mrburnette

Senior Member
Just an FYI..

There will be a fresnel lens in front of the sensor to focus.
The sensors often sold as IR motion sensors are dual (complimentary) sensors with an internal OpAmp and the Fresnel lens is constructed to optically illuminate both sensors when no motion is in the sensor field. Therefore, the output voltage from the IC is near zero volts until an object of the appropriate size or IR radiance moves across the field -of-view.

I have, however used the MLX90614 as an accurate and sensitive IR detector.
mlx90614.html
Infrared-logging-Thermometer/

Good luck, IR is very sneaky to play with since it is essentially invisible to the human eye. Remember too that IR focuses differently and some lens glass/plastic is better than other at transmission of IR. An old camera with the IR filter removed is a great test accessory.

- Ray
 

boriz

Senior Member

moxhamj

New Member
I hacked the .bmp format recently using that wikipedia article as a base. You can simplify a lot of things.
* The .bmp format stores lines one at a time left to right but it starts at the bottom of the picture.
* Bytes in a row are 'padded' to the next 4 bytes (ie rounded to an 'uint32)
* The header is 0x36 bytes
* Width is bytes 0x12 and 0x13 (LSB first) and you can ignore the next two as it is never going to be >65536 wide)
* Height is bytes 0x16 and 0x17
* Bytes are stored BGR (cf .raw files which are RGB)

I found a hex editor program very helpful.

Now here is the cunning workaround. Take a program like paintshop/photoshop and make a .bmp file of the size you want yours to be. You can put a picture in there if you like - it does not matter. Save that file. I used the standard .bmp format of 3 bytes per pixel (ie full color, not grayscale). If you now use that as a template, the header file is going to be exactly the same. So you leave the first 0x36 bytes are they are - the size, width, height etc. Start writing your data, last row first, then at the end of the row, pad out 1 2 or 3 bytes so it is divisible by 4. Then the next row.

I found it very helpful to create a tiny little .bmp file - deliberately with the row size not a multiple of 4 (ie 5x5 pixels) and save a red pixel in one corner, a blue in one corner, a green in one corner and a yellow in one corner, then examine that with a hex editor. It is simple enough to predict what each byte should be.
 
@mrBurnette: Yes, a motion-detector sensor has 2 (or 4) sensor areas.I think such a sensor can be used since both elements are configured in serial. The pir d203s chip I found in a cheap motion-detector is configured like this.

As for the lens: I found a single-focus fresnel in a promotional card for reading glasses :) It's not like the multi-focus you find in PIR motion detectors. I guess it is a diopt +2 or +3 but it's easy enough to find the focus for visible light. Since the sensor is quite big and the servo's have limited number of positions anyhow so, a bit out of focus woulndt mind for a start.

@Dr_Acula: Someone mentioned earlier to reverse-engineer an exsisting .bmp. Your explanation gives a lot of answers already.
Lots of work to be done from here... I'll be back with some results later on...
Tnx
 

AllyCat

Senior Member
Remember too that IR focuses differently and some lens glass/plastic is better than other at transmission of IR. An old camera with the IR filter removed is a great test accessory.
Hi Erik,

Yes, a very relevant comment from Ray. Bear in mind that you are not dealing with "near" InfraRed (as used by TV remote controls, etc.) but much longer wavelengths. Window glass, for example, is almost completely opaque to these wavelengths, try setting up a PIR detector behind a glass window (it will be totally "blind"). So I'm not sure that a normal (digital) camera would be much use as a detector in this particular case.

Also, I would have though your lens would need to be 10 or 20 diopters or more, or are you planning to make a large "camera"?

Cheers, Alan.
 

mrburnette

Senior Member
@Erik,
Yes, a motion-detector sensor has 2 (or 4) sensor areas.I think such a sensor can be used since both elements are configured in serial.
But, then are ( the 2 elements) wired opposing ... so with a constant illumination, the voltages from the two elements cancel ... Rl is the load resistance that develops the differential voltage for the FET gate.

From Wikipedia:
The sensor is often manufactured as part of an integrated circuit and may consist of one (1), two (2) or four (4) 'pixels' of equal areas of the pyroelectric material. Pairs of the sensor pixels may be wired as opposite inputs to a differential amplifier. In such a configuration, the PIR measurements cancel each other so that the average temperature of the field of view is removed from the electrical signal; an increase of IR energy across the entire sensor is self-cancelling and will not trigger the device. This allows the device to resist false indications of change in the event of being exposed to flashes of light or field-wide illumination.
Passive_infrared_sensor

- Ray
 
Last edited:

mrburnette

Senior Member
...
So I'm not sure that a normal (digital) camera would be much use as a detector in this particular case. <...>

Cheers, Alan.
I am discussing NIR and you may be amazed at how sensitive a modified digital camera "may be." I use may because a lots of engineering goes into cameras to keep white balance proper.

As with anything , the fine print reads 'your results may vary.'. My old Sony minicam has a night mode and single-shot mode and does a good job in the NIR... but, it is not X-ray vision! Works great aligning my IR laser.

- Ray
 
Last edited:

boriz

Senior Member
Remember, Erik is scanning his sensor. So the two reverse-series sensors will both pass over a slice of the scene, one after the other.

Imagine a simple hot cup with a cold background. The output will read zero as it scans the cold area, then when it hits the cup is will read +ve as the first sensor detects the cup and the second sensor doesn't, then zero when both sensors are facing the cup, then -ve when the first sensor is detecting the cold background and the second sensor is still sensing the cup. Then back to zero when they are both detecting the background.

So if you integrate the reading and graph it, you will see a bump on the line where the cup is. And the vertical deflection would roughly equate to relative temperature.

This is just the simplest of examples, but you get the idea.

I had this idea years ago but never followed through. Just how quickly these things react to temperature change is crucial for determining maximum scanning speed.

I could be wrong of course. I never actually tried it. :)
 

mrburnette

Senior Member
Remember, Erik is scanning his sensor. So the two reverse-series sensors will both pass over a slice of the scene, one after the other.

<...>
Ummmm... he will not be scanning the scene with a Fresnel lens unless he implements a focal plane split/shutter or some kind of optical interrupter (chopper.) Or, you can see the graphic for how to conduct a "test" on the D203, a fairly generic version of IR motion detector. Essentially, an occluder could be used to mask 1/2 of the sensor window and shade one of the two differential elements. Afterthought, I guess a pinhole 'lens' would also work...

I am not saying it cannot be done, but I did a significant amount of messing around with these inexpensive detectors and finally had to select a sensor with an internal reference and digitizer; that is, non-differential.

The pyroelectric detector can only sense a changing temperature. The thermal changes alter the electrical polarization that appears as a voltage difference. These AC devices create halos around high AT targets. These systems typically have a chopper (to produce a changing scene) between the lens system and detector. The chopper is synchronized with the frame rate of the camera so that the displayed image appears uniform.
Reference, page 98 http://telekomunikacije.etf.rs/predmeti/ms1ts/Common_sense_approach_to_thermal_imaging.pdf

Overview or IR lens and focusing for motion detection: http://www.glolab.com/focusdevices/focus.html


- Ray

Graphic embedded extracted from link below:
Link to D203B(generic type): http://www.micropik.com/PDF/D203B-e.pdf
D203.jpg
 
Last edited:

boriz

Senior Member
"...he will not be scanning the scene with a Fresnel lens unless he implements a focal plane split/shutter or some kind of optical interrupter (chopper.)"

Why not? Why wouldn't it work just the way I proposed?

So long as the scan is in motion, the temperature will be changing, and one will follow the other exactly so long as the sensors are lined up side by side in the plane of the scanning motion.

I did use the words integrate and relative.
 

mrburnette

Senior Member
...
Why not? Why wouldn't it work just the way I proposed?
...
I did use the words integrate and relative.
Why? It is my belief that the proposed lens cannot produce sufficient image contrast for the sensor type proposed. The link given in my previous post on IR motion detector lens suggests a very special lens design... not a Fresnel lens for "reading" use... a magnifier with soft-focus.

However, perhaps it will work... but I'd think that a silicon IR sensor with an instrumentation amp would be a far better design than an IR bolometer with a differential sensor. Consider what the sensor would see with a series of black & white stripes... if the servo stops and the lens places the black image over the sensor, the voltage is 0. If the servo stops and the lens places the white image over the sensor, the voltage is 0. Only if the lens can create a contrast of black-white over the two sensors will there be a voltage output, and the voltage is differential. Is the black representative of a perfect black body? Is the white truly white and 100% IR reflective? There is no calibration other than calibrating each of the two sensors separately using the test procedure in the manufacturer's spec sheet. It we were moving the sensor smoothly and slow enough to allow definition between the black stripe and the white stripe, we would see a voltage pulse on the IC output. Going back to our B/W stripes of arbitrary width, we would only see pulses, not stripes in a servo system that advanced - sampled - stored - advanced .... across the focused field in an X,Y scenario; like a TV raster scan but in discrete steps. This does not provide a thermography of the IR source (at least I cannot see how it could.)

Replace the differential sensor with a digital IR thermometer and we can now achieve thermography and plot the IR temperatures of the source by stopping the X, Y servos at any point in the lens focal plane.

But, I may be wrong in thinking the end results will be poor ... which is to say that maybe the limitations can be (easily) overcome.

I'll look forward to the results of the experiment.

-Ray
 
Last edited:

MFB

Senior Member
When I suggested using the PIC32 based Maximite to create and save BMP files it was pointed out that only B&W graphics was supported. It now seems that there is beta software available for the single-chip Maximite boards that offers the following new features:

- Colour VGA with eight colours (black, red, green, blue, cyan, yellow, purple and white).
- Synthesised stereo music and sound effects.
- Battery backed real time clock (optional).
- Arduino compatible connector with an additional 20 I/O lines that are independent of the original 20 I/Os.
- 2 channel PWM analog output.
- Special commands for animated games.
 
Top