Correcting The Pink Photo From My Modified Phone: A Follow-Up

A week or so ago I posted an Ask Hackaday, in which I asked the community for help with a common camera hacking problem I was having with my mobile phone to C mount conversion. In short, when you take a camera with a tiny lens and change that lens for another, the resulting photographs have a colour cast. It’s usually the right colour in the centre, and moves to a pink colour in a ring around the photo. The commenters came up with the right answer, and identified the problem as the phone software applying a correction to compensate for the relatively awful tiny lens. It’s a problem not limited to me, it’s appeared in many such projects including this one. So having been educated as to the nature of the problem, my next  step was to look at how to fix it.

It’s A Flat Field Correction Problem, Folks!

This image has pink edges fading to white in the centre.
The Galaxy Note 3 calibration image.

Of course I am not the first to encounter this in some form, thus as expected there’s a well-tested technique in photography to correct it. It’s called flat field correction, and it works by correcting each pixel in the image to match the gain to that of the pixels in the centre of the image. It’s a straightforward enough mathematical procedure, and to measure those relative pixel gains it requires that the camera take a calibration image of a uniformly lit white surface. The idea is that each pixel in this image will deliver the difference between it and the pixels in the centre, and thus the required correction for that pixel.

Taking a calibration image is easy, and involves pointing the camera at something white and reasonably lit, and unfocusing it to remove any surface texture effects. The picture must be at the same resolution as the photo to be processed. I took a picture of the same white table in my hackerspace from the stuffed animals picture at somewhere under a metre’s distance, with the lens set to infinity focus. The resulting image shows the circular pink pattern alone, and very clearly indicates the nature of the problem.

Correction Method 1: GIMP

The same image of stuffed animals twice, top: fixed version, bottom: original with pink cast.
Top: fixed, Bottom: original.

Perhaps the easiest way to perform flat field correction is in your normal photo editing package. I use GIMP, but I am guessing that other packages will follow a similar path.

  1. Open your photo to be corrected. The result will be brighter so you’ll need to reduce its exposure (Colours menu > Exposure).
  2. Change the encoding precision to 32-bit floating point (Image menu > Encoding). Since this is a mathematical process, this reduces any rounding errors that might affect picture quality.
  3. Open the calibration image as a new layer above the photo (File menu > Open as layers). Some guides then suggest applying a Gaussian blur to this layer to further reduce noise. I tried either, and found it made little difference.
  4. Change the layer’s mode from “Normal”, to “Divide”. This can be found in the Layers panel, in a pulldown above the list of layers.

Following these steps delivers an image with the flat field correction applied. Of course, it may still need other processing such as white balance, but the pink ring is gone.

But What About The Command Line?

A straightforward GIMP workflow is an easy way to correct a single photo, but converting a day’s worth of pictures is likely to become a major pain. For a directory full of pictures it makes sense to use Image Magick if I can, and for a video I need to be able to use ffmpeg. So after a bit of messing about, here is the same process, for both command line packages. I have also placed the shell commands in a GitHub repository, in case your browser manages to mangle cut-and-pasting the commands below.

Image Magick

The first task is to create a calibration map from the calibration image I took earlier. This is a PNG image whose pixels represent the level difference from the centre of the image normalised to 50% grey, as opposed to the original image which shows their relative values at whatever illumination it was taken under. The -blur option applies a blur to remove any textures in the image, while the -fx option contains the mathematical formula required to apply the calculation. I am not ashamed to admit that I had a lot of help in getting these steps right, for which I am thankful.

magick calibration-photo.jpg \
  -blur 0x60 \
  -fx 'channel(
    0.5*u.r/max(u.g,0.02) *
        u.p{w/2,h/2}.g/max(u.p{w/2,h/2}.r,0.02),
    0.5,
    0.5*u.b/max(u.g,0.02) *
        u.p{w/2,h/2}.g/max(u.p{w/2,h/2}.b,0.02)
  )' \
  -depth 16 PNG48:calibration-map.png

Having created the calibration map image, it can now be applied to the photo. The multiplication by 0.5 is a compensation for the calibration map being centred around 50% grey, and the divide function is the same as that in the GIMP version above.

magick photo.jpg \
-evaluate multiply 0.5 \
calibration-map.png \
-compose DivideSrc -composite \
-quality 95 photo-corrected.jpg

ffmpeg

Now for video! Performing the same task in ffmpeg follows the same process as  with Image Magick, but the calibration map must be the same resolution as the video. The most straightforward way to do this is to make a short video of the illuminated white surface rather than a still photo, and average all of its frames into a single image. The result is a similar one to the still calibration image, but it’s important to do it this way as the video camera app may apply different processing to the still camera one.

ffmpeg -i calibration-video.mp4 \
-vf "tmix=frames=60,format=rgb48be" \
-frames:v 1 -update 1 calibration-image-video.png 

This image can then be processed in exactly the same way as the Image Magick version. Again, it’s applying a blur, and the same formula to make the calibration map.

ffmpeg -i calibration-image-video.png \
-vf "format=gbrp16le,gblur=sigma=60,\
geq=r='32768*r(X,Y)*g(W/2,H/2)/(max(g(X,Y),1)*max(r(W/2,H/2),1))':\
g='32768':\
b='32768*b(X,Y)*g(W/2,H/2)/(max(g(X,Y),1)*max(b(W/2,H/2),1))'" \
-frames:v 1 -update 1 -pix_fmt rgb48be calibration-map-video.png

Using the map, the conversion can then be performed on the video itself. This is a slow process though, on my run-of-the-mill Thinkpad it was processing only 1.8 frames per second.

ffmpeg -i your-video.mp4 -loop 1 -i calibration-map-video.png \
-filter_complex \
"[0:v]format=gbrp16le[video];\
[1:v]format=gbrp16le[map];\
[video][map]blend=all_expr='A*32768/max(B,1)':shortest=1,\
format=yuv420p[out]" \
-map '[out]' -map '0:a?' \
-c:v libx264 -preset medium -crf 18 \
-c:a copy your-video-corrected.mp4

So we’ve identified the problem as flat-field correction, and here are three ways to do it. The camera is now a lot closer to being useful, even if the processing steps can be a little cumbersome and the photos may require a little more post-processing. It’s obvious that in the phone hardware is the best place to do this, but without access to the internals of a 13-year-old Samsung this is the next best thing.

Building A Wireless Network Adapter For The Super Nintendo

The Super Nintendo Entertainment System, or SNES for short, didn’t have much in terms of networking or online functionality. While it originally did have an expansion port on the bottom that the SatellaView satellite modem uses, this was very much a niche application outside of Japan. Correspondingly [Danny Boland] opted to use the front serial ports – also known as the controller ports – for a wireless network adapter instead.

This Super Network Adapter, or SNET, project combines an RP2350 with an ESP32-C3 to provide both connectivity with the SNES’ controller port for a ~30 kB/s data link and a WiFi connection to the local network or as a hotspot. By default SNES games do nothing with this peripheral, so ROMs have to be patched and loaded from an appropriate flash cartridge.

With that done it unlocks features such as being able to synchronize game saves between the cartridge’s SRAM and – as shown here – a WebDAV server to keep your game saves consistent between the cartridge and a RetroArch instance. There’s also a demonstration of having an LLM generate NPC dialogue for Legend of Zelda: Link to the Past to have them do things like react to you smashing their pots, though your mileage may vary on how useful this feature is.

Overall it seems like it could be a pretty useful add-on for custom SNES ROMs, if you’re into that sort of thing.

How Modern Smartphones Talk To Satellites

The common cellular phone has always been a terrestrial communications device, speaking to towers dotted about the landscape. Meanwhile, satellite phones have long existed as specialized equipment, for staying in touch far beyond the coverage areas of the cellular network. They’re expensive to use, with dedicated antennas and radio chipsets for talking to dedicated constellations of satellites flying overhead.

These days, though, the lines are blurred. You can have a regular old smartphone that has two-way satellite communications capabilities baked right in from the factory. This new technology has only been around for a few years, but it’s already changing the game when it comes to staying connected when trekking out far from civilization. But how does it all work?

Continue reading “How Modern Smartphones Talk To Satellites” →

No MicroDrive? No Problem!

The Sinclair ZX Spectrum and QL computers contained many of Sir Clive’s signature quirks, but perhaps chief among them was their take on mass storage. The Microdrive was something similar to a miniaturised version of an 8-track cartridge, with a continuous loop of tape inside that gave about 80k of storage. At the best of times, their reliability was a little suspect, but with all examples now being over four decades old, a working one is something to be cherished in 2026. If you have a QL or a Spectrum with Interface 1, though, all is not lost. [Alexander Vollschwitz] has your back with Oqtadrive, an emulator for Sinclair microdrives. What it delivers is an emulated eight daisy-chained Microdrives, and even the Sinclair networking system over the Internet, something that many users never even saw locally back in the day.

At its heart is an Arduino Nano that connects to the Microdrive port and, if necessary, the network port, which in turn connects to a daemon running on a host computer. This can be anything from a PC or Mac to a Pi Zero. The Arduino emulates the hardware and the protocol for the Sinclair machine, while the daemon manages the storage and networking.

Continue reading “No MicroDrive? No Problem!” →

Repairing A Cheap Rotary Evaporator For The Home Lab

After running through the chemical reactions required to get whatever substance you were targeting, it’ll often still be mixed in with a lot of solvent. Getting rid of this solvent can be done in a variety of ways, but the quickest and most gentle approach is to use the rotary evaporator, or rotovap. Unfortunately, despite being rather simple devices, buying them new is quite the financial decision, so [ProjectsInFlight] opted to try and fix up a cheap broken one that he bought online.

A rotovap, as the name suggests, rotates the flask that the liquid is contained in. A heating bath provides gentle heating to the flask, while a vacuum lowers the boiling point of the solvent. The evaporated solvent is then condensed and collected for reuse or disposal. With even a ‘cheap’ budget rotovap starting at around $1,600, finding a rather trashed one for $100 might be a steal, even with the broken glass condenser section.

A replacement condenser was sourced for pretty much the price of the rotovap, with the hope that this would create one whole unit. After some testing it turned out that this rotovap probably fell down a tall flight of stairs, with a busted bearing block for the vertical lift. This is where having a milling machine and some scrap aluminium came in useful.

Ultimately the whole machine came together just fine, and a demonstration of why you want one of these puppies in your lab. For just over $200 this rotovap is excellent at massively speeding up evaporating over a basic hotplate, although you do need to supply your own vacuum pump, plus a cold trap or similar moisture trap if you use a rotary vane vacuum pump. Here using staged (eccentric) membrane pumps might be a budget solution.

Drying things in a vacuum is overall a very useful concept, one that can be used for more than just making chemistry tasks go faster, but also speed up drying of desiccant and FDM filament.

Continue reading “Repairing A Cheap Rotary Evaporator For The Home Lab” →

Cabinet lights

When Drawers Get Their Own Status Lights

Ever just want a bit more light in a drawer? It’s a common enough problem with a lot of potential solutions. This beautifully done project from [Marcus Lab] handles it in a very elegant way. The Drawer Illumination Subsystem senses each of the drawers and lights the corresponding section when one is opened.

The lights come from a single WS2814 RGBW COB strip, with 21 pixels dedicated across the drawer columns. The strip is powered from 24 V, with a step-down DC-DC converter feeding the ESP32-C6 that runs everything. The ESP32-C6 is connected to magnetic reed switches to sense the state of each drawer. It is also connected to Home Assistant over Zigbee, reporting the state of each drawer—because who doesn’t want to graph their drawer usage? There is a custom PCB that handles all the power conversion and makes plugging everything in a breeze.

There was also a fair amount of mechanical work done on this project: routing a groove under the countertop to recess the LEDs and to keep the wires out of sight. Each reed switch is mounted to the frame while the magnets sit on the drawers themselves. This is a wonderfully documented project; be sure to check out some of [Marcus Lab]’s other work over on the site. Also be sure to check out some of the other home automation projects we’ve covered.

I Heard There Was A Secret Port…

TCP specifies 2^16 ports, 65536, much more than are typically used. In fact, the port zero is almost never used, or, as [Acid Vegas] found out, about 0.25% of hosts globally (give or take) to be precise. The reason is not technical, in fact TCP supports it quite well, but rather social. If one were to request the Linux kernel provide you with port 0, it would actually provide you with a randomly allocated even port between 32768 and 61000. But, there are, of course, ways around this. Raw sockets or, the route [Acid] takes, IPTables/NFTables port mapping. By this, plain text IRC is bound to irc.supernets.org on port 0, and TLS on port 1.

But, should you go try to connect to this IRC server, you will find most userland programs simply refuse to accept a port of 0. BSD NC and Telnet will simply tell you the port is too small. Chromium and Firefox derived browsers will warn you its unsafe. And Python SSL will give you an IO error. However, Python AsyncIO and socat work just fine. Once again, this is not technical limitation of the port, but rather a reflection of the fact that there really isn’t a reason to use it.

Should you go looking on the internet for hosts using port zero, you will find they mostly appear accidental. Mostly likely a network device defaulted to a strange configuration that no one noticed. Regardless the reasons, some strange services are using the port. SSH, mostly DropBear, suggesting IoT or networking devices like routers. Likewise, Telnet appeared on a number of embedded devices. HTTP router admin pages also appear on the port. But, if you remember, browsers don’t let you use port 0, so you need to set up a local port forwarding rule if you want to connect.

While a handful of other services including RustDesk are on port 0, the most interesting is Station Message Detail Recording. SMDR is a simple TCP protocol which logs the outputs of phone calls in plain text.

If you like Linux networking, make sure to check out this VPN hack next!

Thanks [adistuder] for the tip!