Saturday, May 26, 2018

Indirect Ophthalmoscopy Using a Raspberry Pi -- Part 2

As I discussed in my earlier post on this topic, my brother and I are attempting to build an inexpensive, easy to operate, fundus camera that can be used to screen for diabetic retinopathy. Also as I said earlier, we didn't have much luck with a device I built by stacking up a raspberry pi camera, a raspberry pi, and a 7" touchscreen. Therefore we took a new approach.

Optical bench showing various adjustments
I  built an optical bench that allowed many adjustments for the distances and alignments of the components. It held the camera, the LEDs to illuminate the eye, the 20 diopter condensing lens, and the patient's head. The Raspberry Pi and some other components were attached to one or another of these devices via cables. Let me talk about these things in turn.

Camera with adjustable focus lens and LED board ahead of it
Camera -- We did not actually use the official Raspberry Pi camera. The official camera has a fixed lens. That is, it is not meant to have its focus changed from its factory setting, which is more or less at infinity. We want to be able to focus more effectively on nearby objects. The lens can actually be turned using a pair of tweezers and thus the focus can be brought nearer but this is a fiddly process, and not very convenient. Instead we used a camera sold by UCTronics. It uses the same sensor as version 2 of the Pi Camera but has a lens that can be easily focused manually. I purchased an extra long camera cable from Adafruit allowing me to mount the camera on the bench and still reach the Pi.

Board containing prototype bi-color LEDs
Board containing conventional LEDs






























LEDs -- I built two versions of the board containing the LEDs. One contained two of bi-color prototype LEDs (white and infrared) that I mentioned last time, and one contained two each of conventional through-hole white and infrared LEDs. Through experimentation we found that a single LED of each type was able to provide sufficient light. The reason we decided to have two, at right angles to each other, is an attempt to overcome specular reflection from the various optical components. The highlights of these LEDs potentially hide important information in the image so we felt it was important to deal with it. More about that later. There is a ribbon cable that runs from the LED board to a breadboard that contains the circuitry that drives the LEDs based on control signals from the Pi. There are also two potentiometers that can be used to control the brightness of the LEDs.
Infrared and White LED brightness controls



















Condensing Lens -- This lens provides the primary magnification for the image of the retina. Other focal length lenses are sometimes used but this seems to be the most common for this type of screening test.

Chin and head rest as well a condensing lens
Patient Fixture -- This is simply an adjustable chin rest and head rest meant to hold the patient's head in a fixed position.














Raspberry Pi --

Hardware -- We used a Pi 3 Model B Version 2. Using GPIO pins it is connected to the circuit board that drives the LEDs mentioned above. It is also connected via USB cable to an Arduino. We wanted the ability to control a number of Pi Camera parameters on the fly. (See Software below) We did this by using four potentiometers as voltage dividers, read the voltage via the analog to digital converters on the Arduino, and then pass that information to the Pi via the USB.

Brightness, Contrast, Sharpness and ISO camera controls
Software -- The Pi is programmed using Python. The program starts out (using the Python camera interface) to set up a camera preview and then enters a tight loop reading the desired settings for brightness, contracts, sharpness, and ISO from the Arduino based on the positions of the potentiometers. It sets the given parameters in the camera software and then loops back to read the information from the Arduino again. There is a normally open button connected to a GPIO pin on the Pi that works as a shutter button. When a button is pushed an interrupt on the Pi is triggered. The Pi takes a picture, turns off the preview, and displays the picture in a browser window on the Pi. When the shutter button is pushed again the camera preview is re-enabled and the process starts over. The pictures are numbered consecutively so they are not overwritten.  Using hardcoded variables in the Python program the action of the LEDs can be controlled. For instance, the eye can be illuminated in IR during the preview but have the white LED flash as the picture is taken. Or the eye can be illuminated in white light during the preview and when the picture is taken. Or it can be illuminated in IR continuously. Or no illumination can be provided.

Here is an example of a picture we took using our device. The optic nerve is the yellow circular area in the upper left of the picture. This picture is not perfect, of course. You can see evidence of the specular reflection I mentioned earlier. We are, however, pleased with the resolution and the field of view. Also we still haven't been able to achieve sharp focus using the IR LEDs so it should be noted that this photo is taken with a chemically dilated pupil.

Next time I'll talk about what we're doing about that.

Oh, and one other thing. There is a group that has made excellent progress on this type of device. If you're interested in the topic be sure to look here.