DIY wall-reflecting surround sound speakers

Audio, Projects

Surround sound is cool. Hearing sound effects and music coming from every angle is much more immersive than just having the sound come from your TV. However, it isn’t easy to fit so many speakers in to every type of room. People who are into hi-fi will tell you that you need to have your speakers a specific distance from the wall, and rotate them at a specific angle to get the best sonic experience in the seating position. And god forbid if you tell them that you have your sofa against the back wall… “The rear wall will enhance the bass at random frequencies, it will sound boomy and horrible”.

What do you do then, if your room isn’t the right size and shape for an ideal home cinema? What if you only have space to put a speaker on one side of the seats? Well, one thing you probably shouldn’t do is build the speakers yourself (but maybe you still should).

The room problem. A small side table on one side and the doorway on the other. No room for a speaker on the right hand side.

I wanted to install a 5.1 surround sound system, starting with a 3.0 system. If you didn’t know, the first number is the number of ‘surround speaker’, and the second number is the number of subwoofers. Typically in cinemas sounds bellow around 80Hz are played by subwoofers, and higher frequencies are played by the other speakers. 3.1 systems have a left and right speaker, and a centre channel as well as a subwoofer (the 0.1). 5.1 systems add two surround speakers what are approximately in line with the seats. 7.1 systems have another two speakers behind the seats and point towards the TV. In 2014 a new standard was created, Dolby Atmos, that adds hight channels to the sound on films. The best way to do this is to cut holes in the ceiling and place speakers pointing at the seats from the ceiling at specific locations. However, for people who can’t do this, there is also an option to have speakers pointed at the ceiling (typically on top of other speakers at ear level) and to bounce the sound off of them to the seats.

Klipsch tower speaker with ceiling-firing speaker built into the top of it.

This is all very interesting, and probably sounds great. However, I didn’t want to cut holes in the ceiling, or to buy a new receiver that can decode Dolby Atmos, and I still couldn’t fit in even a 5.0 system. I then had the idea of using the surface bouncing idea to reflect the sound off of a wall and back to the seats so that the speaker near the door would have room.

With this idea in mind, I took some measurements of the distances and hight of the seating position, location of sofa, etc and put this geometry into Fusion 360 – a CAD software. This allowed for easy determination of the correct height and angle for the speaker driver to be located, such that a reflection off of the wall would arrive at approximately ear level.

Diagram of sound reflection off of the wall. Red line shows the approximate reflection path.

A speaker driver was selected, meeting the criteria of being full range (not including frequencies that might be covered by a future subwoofer), relatively small, high sensitivity, 8ohm, and relatively inexpensive. Since I don’t have any test equipment (oscilloscope or calibrated microphone) I thought it would be best not to try for a two way speaker, since designing and testing the a crossover without being able to measure anything really isn’t engineering, it’s just guesswork. The sensitivity requirement was set at about 90dB/1m/1W since one of the speakers has a long and inefficient path including a wall reflection. Small drivers were required so that the speakers can remain compact. (In hindsight, a coaxial speaker might have been a good choice, as a I could probably find a sufficient crossover network that someone else has calculated.)

FaitalPro 3FE22 full-range driver

The speaker driver selected was the FaitalPro 3FE22. These are 8ohm, full-range speakers (~100-20k Hz) that have an RMS power handling of 20W and a sensitivity of 91dB/1m/1W. These would then be expected to play at up to 104dB/1m, which isn’t as loud as the front stage, but sure is enough to damage your hearing with extended play. Further, rear channels really don’t have much happening most of the time and so if slightly more power is pushed through them during the final blockbuster-explosion, then they probably won’t catch fire. Interestingly, in Dolby Pro Logic, the first one in the ’70s, the surround channels were mono and limited to 7kHz. Modern movie mixes use the rear channels more, but still most of the sound will always come from the front speakers, and lower quality rear speakers are a reasonable cost saving endeavour.

To design an enclosure you need to know how the speaker will perform. In the ’60s and ’70s Thiele and Small worked out a simple model of how speakers react in various boxes. Thiele-Small parameters are used to model speakers, although they only apply for low frequencies. Some speaker manufactures ‘fudge’ their numbers a little bit, so before I ordered the drivers I wrote a small C++ programme that checks the Thiele-Small parameters against one another (the parameters are not completely independent). The driver checked out and so I trusted the rest of their measurements.

In order to ensure that a solid 100Hz was playable through the speakers a ported box was designed in WinISD (a free speaker modelling software). WinISD takes the Thiele-Small parameters and plots the frequency response of the speaker in different enclosures. The TL;DR answer to speaker boxes is that larger boxes allow deeper bass notes to be played as the air behind the speaker is more easily compressed (just like a long piece of rubber band is more stretchy than a short piece). Ported boxes resonate, exactly like a mass-spring (or pendulum) system. Frequencies that are near to the resonate frequency of the port excite air in the port and cause it to oscillate, this boosts the volume at the port resonant frequency. If you align the ports resonant frequency to be about the same frequency where the speaker driver starts to loose efficiency (and so play quieter) then boosting the volumes extends the linear frequency range.

There are some disadvantages to ports, in that you are basically always listening to the driver as well as the delayed response from the port, these two pressure waves can interfere with one another, and can also extend the length of a note while the port is oscillating. Ports with a small area produce a chuffing sound as air rushes through them, and larger ports need to be very long to achieve the same resonant frequency, they also have a large mass of air that can cause them to be improperly damped. This being said, perfectly good speakers can be designed with ports – like anything in engineering there is a trade-off between whatever compromises you choose to make.

The compromise that I came up with was to have a large long port that slightly boosted the bass. Due to the method of construction, this very wide port was easier to make.

Comparison of a ported and sealed enclosure response in WinISD. The ported response has a higher -3dB point, but the response drops of more rapidly. The sealed box has a volume of 0.7L. The ported box has a volume of 2L and a 4″x1″ port that is 40.6cm long.

The final parameters for the ported box was a volume of 2L, a rectangular port of 4″x 1″ and 40.6cm long. With these parameters I then went back to Fusion 360 to design the boxes. I designed two completely different boxes that both have the same port length and volume. The first of which was a traditional bookshelf speaker form, with a front facing port. The driver height was set to be just above ear level. The second box was designed with the speaker driver angled at 5.7˚ above horizontal, and a plate such that it can be stabilised under a sofa. The second box was also much taller, just under the height of the arm of the sofa.

Designing a box of the correct volume is easy enough, working out the correct port length was a little more challenging, but for a folded port it is easy to use some algebra to work out how many turns to use. To make sure the speaker was stiff enough everything was made from 12mm MDF (although I understand that plywood would have been a better choice as it is stiffer for the same thickness), and the front baffle was made double thickness. The top of the angled speaker was also made twice as thick to reduce the radiated sound. The sharp angles in the port will cause turbulence and reduce the efficiency of the port – I assume it was also reduce the Q of the port resonance (which should increase the tolerance in port length).

Width of the baffle for both speakers was 4” (~102mm), I don’t have a table saw, and cutting many metres of straight 4” wood was never going to happen. Luckily my local hardware store was able to cut the wood for me. I planned the design around this so that my manual sawing would have the fewest opportunities to ruin the build. I only had to cut strips to length, and cut out the side panels.

CAD model of router jig.

I 3D printed a circle cutting jig for my router in order to cut the 3” hole for the driver; an M3 machine screw holds the jig to the wood and sets the radius. For small holes the order of operations is a little awkward as the screw head is under the body of the router. Rather disconcertingly when in use the last part of the circle is quite hard to cut as the wood is only joined by a thin section. I drilled the centre holes for the speaker cut outs with the two piece of wood taped together, however, the router bit was not long enough to cut through both piece of wood, so they were separated for the final hole. I cut the hole undersized for the driver, and, after gluing together both components, I widened the hole with a rotary tool to make room for the basket and terminals.

The second speaker was much like the first. However, there were a few unusual challenges such as the angled joining points at the top of the speaker.

Test fitting the driver revealed the ideal location for the holes to fasten it to the baffle. I used M4 T nuts and machine screws to attach the driver as MDF disintegrates if screws are driven in and out of the wood. The drivers would have been difficult to flush mount, and already had gaskets on them, so this process was easier than it could have been. The T nuts were hammered in to the back, and later on in the build I used a clamp to seat them deeper as the first test fitting pushed them out (from the screw threading into the wood).

Each of the components were glued on to one of the side panels. 3D printed spacer cubes were used to hold the components of the port the correct distance away from one another. These were strong enough to clamp over and were printed very slowly so as to ensure they were dimensionally accurate. Clamps and weights (including a blender full of water) were used to hold everything together. Only one or two parts of the speaker were glued at each step, other parts were dry fitted in place to ensure everything stayed in position. Aluminium foil was used to separate surfaces that shouldn’t be glued.

The last part to be glued on was the side panel. The binding posts on both speakers were on the side panel as they were both designed to sit right up against a rear surface. Heavy gauge wire was soldered to speaker terminals and the binding post rings. The 3” hole for the driver was just large enough for my hand to tighten the nuts after the side was glued on.

I lightly sanded various parts of the speakers for fitting. The 5.7˚ angle for the angled speaker baffle was sanded into the front panel. And other parts were sanded flat to remove saw marks before gluing. The dust from this was collected and mixed with glue to make a wood filler that was used to fill the gaps made by my imperfect joinery. This filler was used inside and out of both speakers before the side panel was finally attached.

The two speakers were then installed in the living room, connected to the receiver. I manually set the distances and levels by playing white noise thought the each of the speaker in turn and using an app on my phone to measure the level– although at some point I should try the auto adjustment. The two speakers sound a little thin at the moment, but otherwise are fine. I have them set up as ‘small’ on the receiver, it then sends all of the bass to the front three speakers that have much larger drivers (the main speakers play down to 44Hz). I don’t know if this is the best compromise. Maybe I’ll update this when I’ve lived with them for a little while.

Surround music sound really good on the system with Dolby Prologic II music. This algorithm takes normal stereo music and sends the common signal to the centre channel and the difference between the left and right to the rear channels with some filtering. You get some interesting ambient effects and it really feels like the music is surrounding you. I’m sure better rear speakers would make it sound even better, but I’m quite happy for the moment with these. (You can do a similar thing without any fancy processing with a spare speaker and any normal stereo. Just connect the spare speaker to two positive terminals of your amplifier i.e. the positive from the left speaker and the positive from the right speaker. Then run that speaker behind you. The stereo sound should be about the same, but ambient effects will play through the rear one (you can do the same with two rear speakers). This set up is called a Hafler circuit, the ambient sounds that you hear are sounds that are out of phase between the L/R speakers.)

Movies also sound really good too. The first film we watched with the speakers installed was Jurassic Park, incidentally the first film with a DTS sound track. I was particularly struck with the echoes in the entrance hall of the Jurassic park building. In a darkened room, you really feel like you are in a room the size of the one depicted, not the size of your own room. The fire work effects in Coco were also very involving as you can hear them all going off around you.

First on my list of things to finish off with them is to get some primer on. The MDF won’t last long without something to protect it. However, that will involve quite a bit more sanding and a few clear days when I can paint outside, and then the final colour can go on. After that, I’d like to measure the output of the speakers and see if I can improve the sound. I have some DSP capability on the amplifier, but I might also try to implement a baffle step correction circuit.

In short, if you don’t have room to put a speaker for a surround sound system. You really can bounce the sound off of a wall, and it sounds pretty good.

How to get the most out of budget film scanners

Photography

A few simple tips to get the best image quality from budget film scanners. Scanning film can be challenging, high quality dedicated scanners are expensive, and even entry level flatbed for film are pretty pricey. My preferred method is to scan film with a macro lens – perhaps I’ll talk about this method at some point in the future – but today I was going to mention some tips for using the basic 35mm film scanner units which are available on ebay/amazon for between £30-£50. These units all seem to be the same or at least very similar: they are powered by USB, scan to SD cards, and claim a resolution of 5Mpx. Maybe a new generation will come out with a higher resolution sensor, but there are plenty of issues with these scanners and the sensor is not the worst of them.

Typical ebay listing for these sorts of units.


A good 5Mpx scan could be sufficient for digitising photos, especially if you don’t currently shoot film and want to digitise family photos from a few decades ago, as it’s likely that the photos where shot on basic point-and-shoot cameras. If you want to squeeze every drop of image quality from your Leica M7 you probably know that a £30 scanner isn’t for you. To be honest, I don’t think these scanner are for anyone, but if you happen to have one you might be able to eke out a little more image quality with this method.

Dust is the enemy of film scanning. Your film should be as clean as you can make it before scanning. Compressed air, or a hand pumped air puffer, can help to clean up your film and so can water (ideally deionised), however you should make sure not to scan your film wet. If you process your own film you’ll know that you can wash it with tap water and even dish soap, however tap water can leave streaks in your film from the minerals in the water (but if you just dropped your wedding photos on the carpet and they are covered in fluff this is probably a reasonable proposition – and you can re-wash your film if needed).

However, with this scanner you don’t need to clean your film at all. This film scanner was sitting in my dad’s computer cupboard for several years before I tried it, and all that time is has been filling up with uncleanable dust. Not only does the design of the scanner make it very likely to collect dust, it also makes sure that all of the dust is visible in your scans. The scanner has a slot from left to right which accepts the film tray, this slot doesn’t have a dust cover, so is constantly collecting dust. Inside the film scanner is a sensor and lens (just like in a digital camera) and a light source and diffuser. When the film is inserted the light source shines through the film. However, as the diffuser for the light source (a sheet of milky plastic) is very close to the film, dust on this sheet will appear in your scan.

If you scan photos with a dSLR you want the light source to be far from your negative so that any dust on the light source is out of focus.

Schematic of these scanner units
Scan from the film scanner without any film. All of this dust is superimposed onto each frame which you scan. Also, you can see that the illumination isn’t even.
Scan without any correction applied
Scan with dust removal and some simple colour work

The images above were ones which I had processed a few years ago. I thought that I should redo the process with a few intermediate steps to prove to myself that I had remembered all of the steps.

First you need to scan each frame multiple times. I did this two ways, the first was better and the second was faster. The first way is to scan the frame, then wiggle the tray around a little and scan again (you should repeat several times until you have at least 5 scans of each frame). The second method is to scan the whole strip 5 times and just hope that you moved the film holder a little each time.

At the moment you’ll have several images where the dirt is in the same place but the picture moves, we can swap that up so that the picture is in the same place and the dirt moves.

Unregistered images from the scanner. The image moves, but most of the dust stays still.

I found all of the images from the same frame. As you can see the scan area is significantly smaller than the 35mm film frame – another issue with theses scanners. To complicate issues, there are three different kinds of artifact which we want to remove, marks which are fixed in the scanner frame, marks which move a little in the scanner frame, and marks which are on the film. The distinction of marks which move a little in the scanner frame is important as if these didn’t exist we might be able to perform background subtractions, or use the image with no film as a mask to show where the dirt is.

Registered images, for some reason the automatic registration failed.

The registered images show just how much fluff and rubbish is inside the scanner. For a more accurate alignment it is helpful to increase the resolution size (by interpolation), I doubled the number of pixels in each direction, and downsampled the image at the end of this whole process.

Next is where the magic happens. How do we keep the bits which are the same, but remove the bits which move? The median filter! Just as a quick recap, you probably know the median as a centre point estimate, you might use it like the mean if you have outliers in your data. Well, that’s exactly what we have here. Hopefully, if we stack each image on top of one another and look at each pixel we’ll have 5 pixels which are very close in value, and one which is bright white (the dirt is opaque and the negative has the intensity reversed). Now, if we sort the pixels by intensity and the select the one in the centre there is a very good chance our selected value will be close to the true intensity value on the film without the artifact from the dirt.

This process isn’t perfect of course, one issue is that if each image is very dirty then there might be many regions where all of the stacked up pixels happen to be in dirty regions. However, the more images we include the better we can remove the dirt. Also, we will average out noise and JPEG artifacts. For removing noise and JPEG artifacts taking the mean would be slightly more effective, however, for dirty regions which are close to 100% white caused by the dirt we would be left with 6 copies which all have 16.7% brightness all over the image – which might be worse than just one copy of them. Especially if you had to clone-stamp them all out.

The result of the median filter. I did call it a magic trick, but it’s less Wingardium Leviosa, and more ‘Is this your card?’.

The median filter cleaned up the image a lot, but there is still a lot of mess in the frame. Some of this is dirt on the film, or small scratches.

We can easily clone-stamp out the remaining fluff and brighten up the image.

After touching up the image with the clone-stamp and adjusting the brightness we could say that we’ve got the most out of the scanner (and the frame). Zooming in you can the significant noise in the sky, and the halos around the birds caused by the sharpening algorithm in the scanner.

This film cost £1 (it’s Agfa Vista 200) and if you can’t see the grain in £1 colour film then there is probably something pretty bad going on in the scanning.

So, what are your scanning tips? Do you have one of theses scanners? Do you think you’ll use this technique?

Might as well add some more birds in.

So… We built a robot.

Projects, Robots
Seven of Nine Lives – prototype

I used to love robot wars when it was on TV. I always wanted to make a robot for the competition, but when I was a kid I didn’t have the technical skills or budget to make a 100kg fighting robot. I still don’t, but more recently my girlfriend and I found out that there are several weight classes of robot which people compete in the UK, one of them is the 1.5kg ‘Beetleweight’. These are much more affordable and safer than the heavier weight classes. So we immediately started planning out a design for Seven of Nine Lives.

If you have any background in physics/engineering the benifits of spinning stores of energy are obvious. The energy stored is proportional to the square of the angular speed of the blade. Effectively, you charge a battery over an hour, and then dump energy from the battery into the spinning weapon over 10sec and then you dump that energy into the other robot in ~1/1000th of a second. Even with 1.5kg robots the energy storage in the weapons can be quite amazing, many times the energy of a bullet.

Anyway, our approximate plan is for a light, small, sturdy robot with a huge bar spinning on the top. Currently we have a 3D printed draft of the design. This current prototype is the first version of the robot in which all of the components work. It drives around well and the weapon spins up.

We had a lot of problems with the drive for the weapon. This stalled the development of the rest of the robot for quite a while as we thought we had damaged the motor/esc (electronic speed controller), but it might be that we were using the wrong kind of drive belt (we used a beefy v-belt). This is next on the list of things to fix, but currently we just have the weapon directly mounted onto the motor – clearly not a good idea as the bearings inside the motor are not designed for any side loads – but as the weapon is made of hollow plastic at the moment it doesn’t seem to be an issue.

We have spent many nights researching, planning, designing, soldering, and constructing this prototype. It’s been really interesting so far, but we have a lot more work to do. After we sort out the drive for the weapon we can start working out how to make the chassis out of aluminium. It would be really interesting to numerically model the performance of the weapon, amour, and chassis but that seems to be a little out of our area of expertise. If anyone has any tips for this kind of simulation we’d be very interested. So far we have just use the simulation module in fusion 360, but it seems to be designed for static loads or resonance conditions.

Seven of Nine Lives driving around and attacking a plastic bag. If any opposing robots use plastic bags as armour they will likely be defeated.

The humble Tessar

Photography, Projects

In April 1902 Paul Rudolph, of the Carl Zeiss firm, applied for a patent for a camera or projection lens:

Lens layout from US patent 721240A

‘[Constructed by]… arranging four single lenses in two groups separated by the diaphragm, the two components of one of the groups inclosing an air-space between their two surfaces, facing one another, while the two components of the other group are joined in a cemented surface, and the pair of facing surfaces having a negative power…’

The full specification of the lens is included in the patent, but the wording is extremely broad. The Tessar is considered to be any lens of four elements, with a doublet and a pair of singlets. However, Rudolf Kingslake in The fundamentals of lens design gives more insight, describing them as like Protars but with an air-spaced front group, the Protar being another design from Rudolph and produced by Zeiss from 1890.


Lens formula from US patent 721240A

If we want to swap out those refractive index values for Abbe values we can simply fit Cauchy’s equation and use that to estimate the C-line index, giving the table below.

Simply fit the three wavelength/index pairs to Cauchy’s equation to calculate the missing values. Only the first two terms were needed.
nd (589.3nm)Vd ∆P(g,f)
Lens 11.6113258.41280.020117
Lens 21.6045743.22430.012310
Lens 31.5211051.51090.013207
Lens 41.6113256.36750.021767
Refractive index Abbe number and anomalous partial dispersion for the glasses listed in the Tessar Patent

The original patent lists most of the values needed to model and construct the lens, however, you might struggle to find those particular glasses. A more modern formulation, from Kingslake, would find the same basic lens updated with modern (for 1978 in the case of my copy of lens design fundamentals) glasses, SK-3, LF-1, and KF-3, of note is the significant decrease in index of the second lens, but still flowing the same idea of a dense crown for the outer elements and medium flint for the second, and a light flint for the third.

The system focal length seems to be nominally 1000mm and back focal distance is 907mm. For the purposes of this exercise the presented designs will be scaled to exactly 1000mm focal length.

The lens produces an image circle of approximately 500mm. Requiring good performance over this size field is a challenge, but would be necessary if the camera was intended to be used without an enlarger. However, if only contact printing was intended then the definition requirement would be significantly lower. If the camera was to be used with wetplates then the chromatic aberration requirements become quite challenging, as the camera needs to be corrected for longitudinal chromatic aberration in the visible light (where it is focused) and the near-UV where most of the exposure comes from.

My initial hope/plan was to simply re-optimise this lens with modern computer optimisation and to get a slightly better performing lens at f/4 over the f/5.5 lens. This did not happen. It seems that Zeiss’s reputation was well earned. However, what I did do was significantly alter the lenses character and learn a lot on the way. For one, I didn’t really understand the importance of vignetting for aberration control, as you can clip off some of the problematic rays near the edge of the field of view, with only a small loss in edge illumination.

We can assess the performance of a photographic lens in a number of ways. From a design point of view one of the most obvious is spot size. This is the size that a single point of light would make at the focus of the lens. Different object distances can be considered, but for this I only looked at objects at infinity. Lenses tend to have better definition in the centre than at the edge, so it is important to examine the spot size at different field angles. Also, since lenses have dispersion it is important to also examine the effect of wavelength on the system. I used three main methods to judge image quality, the polychromatic spot size, chromatic focal shift, and image simulation. The image simulation also gives an idea of the performance of the whole system, including sharpness, chromatic aberration, and vignetting.

Layout of the Patent version of the Tessar, at f/5.5.
Raytrace of the Patent Tessar, at f/5.5.
Chromatic focal shift in the Patent Tessar. The maximum focal shift is 916µm
Spot diagram for the patent Tessar at 0˚, 7.5˚, 15˚, 20,˚ and 30˚ at f/5.5. The colours show the wavelength.

There are some things we do know about the lens such as properties of the glass and the radii of the curvatures. But there is also other information which we don’t know, such as the semi-diameters of the lenses, or the manufacturing tolerances of the system. If we guess at the first and ignore the second we can model the system as shown in the figures. The rear lens group is slightly smaller than the front group, vignetting some of the rays – this is set by the edge thickness of the rear lens.

To characterise this lens we might say that it is well optimised over the whole field, with the spot size increasing by more than a factor of 3 from the centre to the edge. The chromatic shift isn’t significant and at f/5.5 there isn’t any obvious lateral chromatic aberration.

I re-optimised the lens several times, tweaking the weightings of various factors. I decided that distortion wasn’t an issue, and that over-all central performance was more important the edge or the very centre. I also kept the same glass as the original. The prescription which I arrived at is

Radii/mmThickness/mm
r1213.366L140.881
r2-3276.842gap19.710
r3-648.011L211.081
r4197.148to stop39.115
r5-777.429from stop19.649
r6221.080L38.382
r7-340.573L446.140
Backfocus887.795
Re-optimised prescription for lens
Re-optimised lens layout at f/4

As can be seen from the table and the layout diagram the first lens of the re-optimised lens is almost unchanged. The second lens is slightly strengthened on both surfaces. The rear doublet is thickened and has more power. This might have been avoided in 1902 due to the cost of the ‘new achromat’ glass. Overall, the lens is not much changed, at least by examination. I expect that the 1902 patent lens would be less expensive to make due to the weaker surfaces and thinner lenses. However, in the re-optimisetion I did squeeze an extra stop of speed out of the system.

Raytrace of the re-optimised Tessar at f/4
Focal shift in the re-optimised Tessar, maximum focal shift is 766µm
Spot diagram for the re-optimised Tessar at 0˚, 7.5˚, 15˚, 20,˚ and 30˚ at f/4. The colours show the wavelength.

The re-optimised Tessar is a slightly better achromat with a smaller maximum chromatic focal shift of 766µm instead of the 916µm of the original Tessar. This is probably not significant. I don’t know exactly how the original lens was achromatised, however, my choice was to achromatise 0.54µm and 0.4861µm. These value were chosen as they are close to the peak sensitivity of the eye and of the collodion process, hopefully, a photographer could focus in the visible light and expose with minimal focus shift in the blue/near UV.

In the spot diagrams of the re-optimised lens you can see an obvious design choice, the centre spot has been allowed to increase in size slightly, and the very edge spot has increased significantly, all of the other regions show significant spot size decreases. This is due to a difference how I would personally like to compose images, with a less strong centre bias than 1902-Zeiss expected.

The average spot size for the re-optimised lens is significantly larger than for the patented example although almost all of that is in the very edge, but we can’t judge it too harshly as the re-optimised version is almost a stop faster at f/4 rather than f/5.5. If we stop it down to f/5.5 we get a slightly different result.

Raytrace for the re-optimised Tessar, at f/5.5.
Spot diagram for the re-optimised Tessar at 0˚, 7.5˚, 15˚, 20,˚ and 30˚ at f/5.5. The colours show the wavelength.

The spots have decreased significantly over the field when stopped down, as would be expected. The central spot size is now almost the same as in the patent design, and the 15˚ spot size is now smaller than the 7.5˚ spot size in the patent design – this significantly increases the region of good definition of the system.

Perhaps a more meaningful way of comparing the lenses is by simulating an image made from them.

Comparison of the image quality between the original patented Tessar and an re-optimised version of the lens.

Examining the simulated image (which doesn’t take into account depth) we can see some of the character of each lens. Like with any other artistic tool, the final judgement is based on the desired use.

Circle packing

Projects

Circles are ubiquitous in nature as they minimise surface for a given area. Circles arrange themselves in efficient ways due physical forces – lipid vesicles inside cells for example. The patterns look pretty cool too.

Randomly generated circles in a range of acceptable radii

There are several simple circle packing algorithms which can be used to generate these patterns. A central requirement in many of these algorithms is determining if a given circle is wholly outside of another circle. This can be simply calculated by requiring the centre of the new circle is at least separated from the old circle’s centre by the sum of the two radii. A simple circle packing algorithm then randomly generates centres and radii and tests to see if these are wholly outside of all of the current circles. This algorithm produces more small circles.

Initial large circle with smaller circles generated around it.

It is then simple to add other requirements and initial conditions. Large circles can be used to produce negative space around which the other circles can be distributed.

The packed circles can be filled in a variety of visually interesting ways.
Circles above a certain size are not drawn

Controlling the drawing process is also interesting, smaller concentric circles can be draw inside larger ones, or some class of circle can be skipped out.

The images produced are typically visually complicated. Simplifying them or adding order can significantly change the nature of the image.

To take this process further, more efficient packing and drawing algorithms could be implemented, as could more filling techniques (lines, zigzags, spokes) and colours. Further, generating these patterns could be generated according to the intensities of a photograph.

A pair of new related sequences of integers

Projects

A) 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 2, 1, 4, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 4, 1, 1, 1, 2, 2, 1, 1, 1, 5, 1, 1, 1, 1, 1, 3, 3, 1, 3, 1, 1, 1, 7, 3, 1, 1, 1, 2, 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 3, 1, 1, 2, 2, 1, 3, 2, 2, 1, 4, 1, 1, 2, 2, 1, 1, 2, 1, 1, 2, 1, 3, 2, 2…
and
B) 1, 1, 1, 1, 1, 1, 1, 2, 5, 3, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 1, 1, 1, 3, 1, 3, 3, 3, 4, 1, 2, 1, 2, 3, 1, 2, 1, 1, 1, 2, 1, 1, 1, 3, 1, 1, 1, 3, 3, 2, 3, 3, 1, 1, 5, 4, 3, 2, 3, 1, 7, 3, 3, 1, 1, 2, 1, 1, 1, 2, 2, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 1, 1, 1, 2, 1, 5, 3, 1, 1, 3, 2, 3, 1, 3, 3, 4, 1, 4, 1…

What are these sequences, and what links them? Well, if you take the prime numbers in order, and sort each of their digits and then count how many factors each of these numbers has you’ll find either sequence A or sequence B depending on if you sorted the digits highest first or lowest first. The 1s represent numbers which are primes. The first few prime numbers only have 1 digit, so sorting the digits gives the same number, then there is 11, which sorted is still 11, and 13 which can be sorted to 13 or 31, both of which are prime. 19 is the first prime number, which when sorted highest to lowest gives a composite number.

A property of this pair of sequences is that, at least up to 9592 digits, the sum of the first n digits of B is greater than A. This is expected as the intermediate values, the sorted prime digits, of B are 1 larger and 2 more likely to have 0s or 2s at the end of them (since 0 and 2 are both small numbers and guarantee numbers to be composite). Larger numbers are more likely to have more factor since there are more available combinations. I don’t know this result to be true for all N, it is a conjecture.

I’m hoping that the sequences get accepted to the Online Encyclopedia of Integer Sequences (OEIS) which is the goto place for sequences like this to be sorted so that people can cross reference. If they do get accepted then they’ll be sequence A326952 and A326953, respectively. However, the OEIS curates the sequences that they list carefully so as not to include arbitrary sequence which no-one else will find interesting. I don’t know if other people will find this interesting.

Excitingly, as of the 25th of August, they have both been approved https://oeis.org/A326952 and https://oeis.org/A326953

Plot of the cumulative sum of each of the sequences
Plot of sequence A against sequence B for the first 4796 terms

Macro focusing rail v2

Uncategorized
Stack of 128 frames of a wasp using a 3.7x 0.11NA objective on a Pentax K-1

Focus is often used creatively in photography to separate the subject from the background of an image. In microscopy ‘optical sectioning’ to resolve details out of the plane of the image. In macrophotography, however, we often want to capture images which are pin-sharp front to back. Doing this is quite hard.

The depth of focus is very narrow at high magnification. In fact, in the wasp portrait the depth of focus was only 58 microns, or only 0.058mm. You can see what a single image looks like bellow. Only few hairs are in focus. In total for this photo I took 128 images in 20 micron steps.

Single frame from stack

It’s pretty hard to move in 20 micron steps by hand, so for a little while I’ve been putting together a focusing system.

Version 1 was just a z-axis rail for a CNC machine. A rail with a carriage supported on it, with a screw thread and a like-threaded insert on the carriage, and a stepper motor. This was controlled by an arduino and stepper driver. The camera was set up with an interval timer, and the arduino code had periods in it for the camera to take a photo.

This setup had several disadvantages, securing the camera to the camera was difficult. an M5 to 1/4″ bolt was used, but this didn’t allow for the camera to be securely fastened. Also, the minimum step size was ~50µm which wasn’t fine enough. Lastly, the camera needed to stay in sync with the arduino, which was achieved by starting the arduino code a few seconds before the camera, not ideal.

Version 2 has a number of improvements. By cannibalising a shutter release cable I’ve been able to control the camera from the arduino, by just bringing a pin high. I also drilled out a tripod base plate to give sufficient clearance for the camera plate to slide into it, while everything is bolted together. Lastely, I swapped out the threaded rod for a M8 fine pitch rod. This rod has a pitch of 1mm, and only 1 thread cut into it, instead of the ~2.5mm pitch and 4 threads cut into the rod I was previously using. This improves the stepping precision by a factor of 10. A single step on the new system is only 5µm, which is only about 10 wavelength of light.

The thread was cut into a small block of wood which was pre-drilled with an 8mm hole. The wood offers quite a lot of resistance, but also doesn’t produce any backlash.

1:1 zoom of the eye of the wasp. 1px is 1µm in size. The facets of the compound eye are most interesting as they transition from the hexagonal packing into a square packing.

Mounting unusual lenses on digital cameras

Projects
lens recovered from Polaroid Sprintscan 35

Pleasing effects can often be found when using unusual lenses on modern digital cameras. Sometimes they give a highly aberrated image which is useful in creative situations, sometimes the history of the lens enhances the image in a meaningful way, and sometimes the unusual lens offers a quality which is not possible with typical lenses from first party manufactures.

The last instance is often the case with macrophotography. Many people use objectives to photograph small insects as they offer much higher magnification ratios and resolution than macro lenses. Occasionally, lenses used for obscure purposes in industry can find use in various areas of photography. Surplus aerial photography lenses, such as the Kodak Aero-Ektar are highly sought after for their high resolution and high speeds over large flat film planes. Occasional lenses with have excellent performance are found for macrophotography.

It is one of these which I have acquired recently from an old film scanner. Film scanners image a flat sheet of film onto a flat sensor at high resolution. Unlike lenses for general photography they are optimised for magnification ratios of around 1. Most photography lenses are optimised for a magnification of almost zero.

lens recovered from Polaroid Sprintscan 35

Mounting a lens can be easy. Adapters often exist allowing a camera lens to be mounted on other cameras. However, when we look at older lenses, or lenses which were designed for industrial use the adaptation is more difficult.

CAD model of the lens holder

In order to mount the lens securely, I designed a small device to securely hold the lens. The bore has 0.5mm of clearance for the lens barrel, and a flange at the base so that the lens can be reliably positioned the same distance from the sensor. This was 3D printed by a friend of mine. There is also a place for a grub screw to be installed so as to secure the lens in place. The base is so sized so that it may be bonded to a body cap. The injection moulding used on the body cap left the inside surface shiny, this was sanded to reduce reflections. The body cap can the be fitted to a set of bellows or extension tubes.

3D printed lens hold affixed to body cap and with a screw to hold the lens in place
Lens mounted to an old set of bellows. These bellows are backwards, so that the remaining rails are on the camera end.

I was surprised to realise that the top of the body cap was quite convex. This cased two problems. Firstly, the contact area which the lens holder made was rather small, and secondly, it would slide about as the glue dried. To compensate for the first issue I used quite a lot of adhesive. To compensate for the first I used a quick curing epoxy resin. This turned out not to be so quick curing, and I spent about 30 minutes poking the parts into alignment.

I intend to test the lens both ways around and at different magnifications. I don’t know exactly what magnification it will perform best at, presumably at it’s design magnification. However, it may surprise us. The lens is not a symmetric design, the front (dot end) has a convex element, the rear surface is plano.

I took the lens out for a short while and tried to photograph some insects. Unfortunately, I didn’t bring my flash light guide, so most of the picture turned out greatly under-exposed. The lens is not exceedingly sharp, at least, not at the magnifications which I tested it at. However, this is not a well designed resolution test (that will come later).

Full image (resized) and 100% zoom on a 36MP full frame sensor

As can be seen from the above frame, the lens is not sharp to the pixel. However, it shows nice contrast and has very little longitudinal chromatic aberration.

Not many insects would stay still for me. This guy did, but he was really small.

The insect above was very small. I’d be interested to know what species it is. Part of the issue with this photo is the due to a heavy exposure pull due to a lack of flash power. The Pentax K-1 isn’t known for its dynamic range, but this is pulled 3.5 stops, and I don’t think it is so bad. I tried a few different magnifications, but I didn’t keep track of it. The working distance is quite short, but this is also a lot higher magnification than my macro lens.

The resolution is probably what I should expect. The scanner that this lens came from was a 2,700 dpi scanner and the resolution of my sensor is 5,200 dpi, so it isn’t surprising that it out resolves the lens. However, image space resolution isn’t the only important property.

JPEG artifact removal with Convolutional Neural Network (AI)

Uncategorized

JPEG images, at high compression ratios, often have blocky artefacts which look particularly unpleasant. JPEG images look particularly bad around the sharp edges of objects.

There are already ways to reduce the artefacts, however, these methods often don’t use very sophisticated techniques, only using the information from adjacent pixels to smooth out the actual transition between the blocks. An example of this can be found in Kitbi and Dawood’s work https://ieeexplore.ieee.org/document/4743789/ which gave me the original inspiration for this.

An alternative way is to use a convolutional neural network (CNN) to intelligently estimate an optimal block given the original block and the eight surrounding blocks. And then tile over the image to estimate the optimal mapping for each block.

The network design was a 5 layer fully convolutional one, using only small filters. Several different architectures were used, which all gave largely similar results. The compromise between effectiveness and speed (i.e. 1/size) was found with a small network with only 57,987 parameters. Training the network was surprisingly fast, taking only a few hours without a GPU.

The network takes in full colour information and outputs the full colour too. The reason for this is to use all of the possible information. The colour channels are highly correlated with one another. It would be possible to train the network on monochrome images, but that would lose the relation which naturally exists.

So, does it work?

In my opinion, yes it does work. I think my method performs best when there are complicated edges, such as around glasses, or on hairs which are resolved as partial blocks. It works least well, in comparison to the method which photoshop currently uses, when there are large smooth areas.

Text was not present in the training data set. So the poor effectiveness of the network on text is not a significant point of comparison. The above images are quite small. A larger example is below, along with a zoomed in video comparing the original, JPEG, photoshop artefact removal, and my method.

I did calculate root mean squared error values one point comparing the network performance with the JPEG image to the original. In some cases the network was reliably out performing the JPEG – which is impressive, but not too surprising, as this was how it was trained. I don’t think that those sorts of values are too important in this case. The aim isn’t to restore the original image, but to instead reduce the visual annoyance of the artefacts.

If you really wanted to reduce the annoyance of the artefacts you should use JPEG2000 or else have a read of this paper https://arxiv.org/pdf/1611.01704.pdf