The Smell of Molten Projects in the Morning

Ed Nisley's Blog: Shop notes, electronics, firmware, machinery, 3D printing, laser cuttery, and curiosities. Contents: 100% human thinking, 0% AI slop.

Category: Photography & Images

Taking & making images.

  • Spectrometer: Quick and Dirty Image Processing

    Having gotten a spectrometer image from the crude camera lashup, the next task is to (figure out how to) extract some meaningful data. The general idea is to use ImageMagick and Gnuplot as much as possible, so as to avoid writing any actual software.

    The original image is the high-res version of this:

    First light - warm-white CFL - no adjustments
    First light – warm-white CFL – no adjustments

    Use ImageMagick to crop out a slice across the middle and convert it to lossless PNG:

    convert -crop 2500x100+0+1000! dsc00273.jpg dsc00273-strip.png
    
    dsc00273-strip.png
    dsc00273-strip.png

    I can’t figure out how to reset the image size using -extract, but -crop gets the job done.

    The default ImageMagic PNG compression is 75, so I should include a -quality 100 option, too.

    Because we have colors separated spatially, all we need is a grayscale intensity plot. The easy and, alas, wrong way to convert the color image to grayscale goes like this:

    convert -colorspace GRAY dsc00273-strip.png dsc00273-strip-gray.png
    
    dsc00273-strip-gray.png
    dsc00273-strip-gray.png

    That grayscale value is a weighted sum of the RGB components that preserves human-vision luminosity:

    Gray = 0.29900*R+0.58700*G+0.11400*B

    I think it’s better to simply add the RGB components without the weights, because we care more about the actual spectral intensity. That might allow overly high intensity in some peculiar situations, but I’ll figure that out later. First, get the red / green / blue channels into separate files:

    convert -separate dsc00273-strip.png dsc00273-strip-chan%d.png
    
    dsc00273-strip-chan0.png
    dsc00273-strip-chan0.png
    dsc00273-strip-chan1.png
    dsc00273-strip-chan1.png
    dsc00273-strip-chan2.png
    dsc00273-strip-chan2.png

    That looks better: the intensities resemble the original colors.

    Then add those three files together, pixel by pixel, to produce a single grayscale file:

    convert -compose plus dsc00273-strip-chan0.png dsc00273-strip-chan1.png -composite dsc00273-strip-chan2.png -composite dsc00273-strip-spect.png
    
    dsc00273-strip-spect.png
    dsc00273-strip-spect.png

    Extract a one-pixel row from the middle and write it as a raw binary file. You could extract the row from the original image, but I think some blurring might be appropriate, so later is better. There’s no point in trying to display a one-pixel-tall image, so I won’t bother.

    convert -crop 2500x1+0+50 dsc00273-strip-spect.png gray:dsc00273-line.bin
    

    Fire up Gnuplot and have it plot the grayscale intensities:

    gnuplot
    plot 'dsc00273-line.bin' binary format="%uint8" record=2500x1 using 1 with lines lt 3
    

    And there’s the spectrogram…

    Gnuplot - dsc00270 - CFL
    Gnuplot – dsc00270 – CFL

    A quick-and-dirty bash script to persuade ImageMagick to make something similar to that happen, including all the commented-out cruft that I’ve been copying forever so I don’t forget the magick incantations when I need them again:

    #!/bin/sh
    base=${1%%.*}
    echo Base name is ${base}
    convert -crop 2500x100+0+1000! $1 ${base}-strip.png
    convert -separate ${base}-strip.png ${base}-strip-chan%d.png
    convert -compose plus ${base}-strip-chan0.png ${base}-strip-chan1.png -composite ${base}-strip-chan2.png -composite ${base}-strip-spect.png
    convert -crop 2500x1+0+50 ${base}-strip-spect.png gray:${base}-line.bin
    export GDFONTPATH="/usr/share/fonts/TTF/"
    gnuplot << EOF
    set term png font "arialbd.ttf" 18 size 950,600
    set output "${base}-spect.png"
    set title "${base} Spectrum"
    set key noautotitles
    unset mouse
    set bmargin 4
    #set grid xtics ytics
    #set xrange [0:1400]
    set xlabel "Red <- Colors -> Violet"
    #set format x "%3.0f"
    #set logscale y
    set ylabel "Light intensity"
    #set format y "%3.0f"
    #set yrange [0:60]
    #set ytic 5
    #set datafile separator "\t"
    #set label 1 "mumble" at 1600,0.300 font "arialbd,18"
    plot	\
    	"${base}-line.bin" \
    	binary format="%uint8" record=2500x1 \
    	using 1 with lines lt 3
    EOF
    display ${base}-spect.png
    

    Observations & ideas:

    It turns out that the flat topped peak in the middle was in the original green channel data: that color was overexposed.

    If I had a camera that could do RAW images, this whole thing would work even better. Using 16-bit intensity channels would be exceedingly good; the original JPG file has only 8-bit channel resolution: 1/256 = -24 dB, which isn’t anywhere near good enough. That’s assuming the camera + JPG compression has 24 dB dynamic range, which I doubt.

    That blue / violet peak over on the right looks great: the optical focus is fine & dandy. I focused the spectrometer at roughly infinity, set the camera to infinity, then tweaked the spectrometer to make the answer come out right.

    FWIW, I think that deep blue-violet line is the mercury G-line emission at 435 nm, which would explain why it’s so narrow. The others are rather broad phosphor emissions from the CFL tube’s surface.

    LEDs can provide spectral wavelength calibration markers, although their peaks are rather broad in comparison to mercury emission lines. A 400-450 nm “UV” LED puts out a broad blue-violet blur on the left (reddish) side of the emission line. Maybe it’s really the mercury emission H-line at 404 nm?

    An IR LED puts a line on the far left side, about twice the distance to the left of the red line as the green line is to its right. I don’t know the exact wavelength, but it’s around 900 nm. The camera (my old DSC-F717) can do IR + visual images, but it insists on auto-setting the exposure and focus, which wipes out the other lines. The line is barely visible with the camera’s internal (and highly effective) hot mirror in place. Maybe with a more stable setup that would work.

    Diode lasers in IR, red, green, and blue? Hmmm…

    ImageMagick (probably) can’t detect those LED markers and scale the output file width, as it deals with intensity over a regular XY grid. A Python script could swallow the output binary file and spit out a scaled binary file with the bump peaks set to known locations. Actually, I’d be willing to bet there’s a perverse way to get IM to do X-axis scaling, but I’m even more certain the command-line syntax would be a wonder to behold.

    Inject the LED images with a beamsplitter or teeny mirror across the bottom of the spectrometer slit and get intensity calibration, too. Vary the LED intensity with a known current for decent calibration over several orders of magnitude. That could compensate for the crappy dynamic range: as long as the LEDs aren’t saturated, you can correct them to a known peak value. IM can probably do that automagically, given known regions on the input curve.

    Blur the strip image to get rid of color noise and irregularities in the slit. Perhaps a vertical sum in each channel along (part of?) the entire strip, then divide by the strip height, which would completely avoid blurring along the horizontal axis. If, of course, the entrance slit is exactly vertical with respect to the camera sensor.

    IM knows how to deskew / rotate images. Apply that before summing, so as to correct small misalignments?

    Different cameras have different entrance pupils. A quick check shows the DSC-H5 has a much smaller entrance pupil at full zoom: the spectrum covers more than the full screen, so the spectroscope won’t work well with that camera. Normally, you’d like to fill the entrance pupil with the image, but …

    Getting all the optical machinery supported and aligned and oriented will require an optical bench of some sort. Perhaps my surface plate with magnetic sticky bases?

    I think this is going to work…

  • Spectrometer: Quick and Dirty Camera Mount

    This is a proof-of-concept lashup for a camera-mounted spectrometer; I wanted to find out if the image processing would work, but needed some images without devoting a lot of time to the hardware.

    The general idea is that a direct-view spectrometer produces a focused-at-infinity image for your eye. Substitute a camera for your eye and you get an image with the spectral components laid out in a spatial array, suitable for measurement and calculation.

    The trick is holding the spectrometer on the lens axis while blocking ambient light. I figured that I could mount the spectrometer in a disk that fit into the camera’s 58 mm filter threads, then hold it in place for the few pix I’d need to get started.

    The end result was Good Enough for the purpose, although it’s definitely a kludge…

    Spectrometer mounted on camera
    Spectrometer mounted on camera

    The (admittedly cheap) prism-based direct-view spectrometer has a slide-to-focus mechanism that substitutes heavy grease for mechanical precision. A guide screw in a slot prevents the focusing tube from rotating in the body tube, so I decided to replace that with a locking screw to clamp the tubes together. It’s a very fine thread, undoubtedly metric, screw, but a bit of rummaging in my teeny-screw drawer turned up a match (those are mm divisions on the scale):

    Spectrometer screw vs standard thread
    Spectrometer screw vs standard thread

    I think the spectroscope makers filed down the head of an ordinary brass screw to fit the slot, rather than using an actual fillister screw. That’s a Torx T-6 head on the flat-head screw, which probably came from a scrapped hard drive. I eventually found a round-head crosspoint screw (requiring a P-1 bit) that worked better, with a brass washer underneath for neatness.

    That got me to this stage:

    Spectrometer with locking screw
    Spectrometer with locking screw

    Making the adapter disk involved, as usual, a bit of manual CNC to enlarge the center hole of a CD from 15 to 15.75 mm, then cut out a 57 mm cookie. A stack of CDs makes a perfectly good sacrificial work surface for this operation, with some fender washers clamping the pile to the tooling plate. Those homebrew clamps are smaller than the Official Sherline clamps and work better for large objects on the small table.

    Milling outside diameter
    Milling outside diameter

    I briefly considered milling a thread into the OD, but came to my senses… I still have that pile of 10-32 taps, but now is not the time!

    While in the Machine Tool Wing of the Basement Laboratory, I bored a short plastic bushing to a tight slip fit on the focusing tube to clamp the disk to the eyepiece, with the intent of keeping the eyepiece from whacking the camera lens. That’s the small white cylinder in the first picture.

    As it turned out, I had to mount the whole affair on a sunshade that screwed into the camera filter mount, because the eyepiece protruded far enough to just barely kiss the lens.

    A liberal covering of black electrical tape killed off all the stray light. Hand-holding all the pieces together and aiming it at the CFL tube over the Electronics Workbench produced this First Light image:

    First light - warm-white CFL - no adjustments
    First light – warm-white CFL – no adjustments

    Believe it or not, that’s pretty much in focus. Much of the width in the red & green lines seems to come from the phosphors, as there’s a bar-sharp narrow blue line to the far right, beyond the obvious blue line.

    Settings: manual focus at infinity, manual exposure 1/60 @ f/2.4, auto ISO = 100. Maybe 30 cm from the 27 W CFL tube: way more light than I’ll ever get through a liquid sample in a cuvette.

    Now to fiddle with ImageMagick and Gnuplot…

  • What Do Squirrels Do When It Rains?

    Rain-soaked squirrel
    Rain-soaked squirrel

    Although I’m not a big fan of tree rats squirrels, I’ll admit this one was having a tough time of it during a recent rainstorm. He (she?) sat motionless on that stub of a branch for well over half an hour, no doubt thinking gloomy thoughts.

    Taken through two layers of mid-1950s window glass, so it’s not the sharpest image in my collection, but I’m not going out in the rain just to take a picture of a squirrel!

  • Our Old Studebaker: Back in the Day

    In addition to those after-restoration images, here are some pix from an old family album that show our 1957 Studebaker President in its prime.

    I think these were taken around 1970, but I really don’t know. As with many family pix, I also have no idea why these were so important…

    The photos were in bad shape, as you can see in the lower-right image, with the magenta dye having faded very little over the decades compared to cyan and yellow; they’ve been brutally color-corrected and contrast-stretched. They were also printed on horrible satin-finish paper and that fishnet overlay is painfully obvious.

    If you need an original image for some perverse purpose, let me know…

  • Turtles on a Log

    If there’s anything to reincarnation, next time around I’m going to put in a request to be a Staff Turtle at the Vassar Farm Environmental Station.

    Vassar Farm Turtles
    Vassar Farm Turtles

    Taken with my Casio EX-Z850 pocket camera, underexposed 2/3 stop to avoid blowing out the highlights even more. This is a dot-for-dot crop from the middle of a much larger 8 MP image, crisped up just slightly. Terrible results, but it’s better than the big camera I didn’t drag along on a guided geology tour (which ended with a generous handful of fine clay from the stream a bit further along).

    And, yeah, I know the whole reincarnation thing says you get what you deserve, not what you want. On the other flipper, nobody really knows how it all works, so I’m not losing hope.

  • AA Cell Holder: Fragile Contacts

    Broken cell holder contact
    Broken cell holder contact

    It seems I applied a bit too much pressure to one of the contacts on a metal AA cell holder: the outer rim of the rivet holding the solder tab in place departed for the distant reaches of the Basement Laboratory.

    No big deal, I thought: pop another rivet in place and get back in operation…

    You really want the rivet to go in with the flat head inside the cell holder where the original flat head was. Unfortunately, the rivet yanker’s head won’t fit into the holder; I’m pretty sure the manufacturer has a Special Machine to make that happen.

    So I put the reinforcing washer and lumpy end inside. That meant switching the insulating washers to keep the overall distance from the negative cell contact about the same.

    Cell holder rivet - inside
    Cell holder rivet – inside

    The outside looks much better…

    Cell holder rivet - outside
    Cell holder rivet – outside

    For what it’s worth, these pix came from the Sony DSC-H5 with the flash turned down 1 EV. Much better results than the Casio EX-Z850, even with its flash set to Soft (whatever that is). The H5 has much better macro capability… and with the new Eneloop cells, it lasts long enough to make it usable in the shop.

  • Sanyo Eneloop: First Charges

    So I bought an octet of Sanyo Eneloop NiMH cells from the usual Amazon source and ran a few charge / discharge tests, with the hope of powering my Sony DSC-H5 for more than a few dozen minutes at a time. It’s Marching Band season!

    The cells bear a laser-etched 09-10-IF date code that I assume means October 2009, because they arrived in early September 2010. Rumor has it that Eneloop cells come off the manufacturing line factory-charged to 75% of their nominal 2.0 Ah; all eight arrived with the same charge: 1.43 Ah. Given the vagaries of measuring battery capacity, that’s 95% of what they started with, nearly a year ago.

    The eight 500 mA constant current discharge curves are essentially identical:

    Eneloop - As received
    Eneloop – As received

    The first charge after that test was individual cells in a 400 mA charger, the second as a complete 8-cell pack with a 900 mA charger. Those two discharge curves for the pack, again at 500 mA, also overlay nicely:

    Eneloop - 8-cell pack
    Eneloop – 8-cell pack

    The pack voltage remains above 9.6 V for about 1.5 Ah, far better than the tired assortment of cells in my collection (albeit those were measured at 1 A, not 500 mA).

    These should get me through an entire day of Marching Band travel, setup, practice, and competition!