Thursday, February 20, 2014

Make your camera DICOM-able with a Raspberry PI

As I'm working on a medical product which includes almost all aspects of medical services, working with DICOM is one of my primary items. I came accross a requirement for integrating standard photo cameras into the system so that photos taken from those cameras can be easily imported into medical results. This initially came from an international clinic where physicians use high resolution EOS cameras to take patient's skin photos.

Our medical solution has a built-in feature that accepts images sent from DICOM compliant devices like ultrasound machines so my primary path for the intergration is to make the cameras DICOM-able. There are however several constraints for the solution:
  • There will be a large set of camera models that we need to support, ranging from low-end ones like the Canon IXUS to something like the 7D series.
  • The solution needs to be independent from the user workstation operation system as the users of our medical product can use different types of OS including Windows, OS X or GNU/Linux.
  • User operation needs to be as simple as possible as we want to avoid any redundant step in manually selecting the files and sending them.
My solution for this was to use a Raspberry PI, loaded with Pidora and custom scripts to work with the camera and send captured photos via the network to the DICOM storage server.

To support different camera models, I used the gphoto2 command line tools to watch camera activities and download photos to the Rasperry PI. The connection between the Raspberry PI and the camera is a USB cable. Downloaded photos will be then converted into DICOM files and sent to the server using the dcmtk command line tools. The following steps provide you with the details on how to get it done:

Step #0:
Prepare your Raspberry PI with Pidora. Connect it to the camera using a USB cable and to the local network using an ethernet cable.

Step #1:
Install necessary tools:

# yum -y install gphoto2 dcmtk

Step #2:
Make a main script that invoke gphoto2 and watch for captured photos

$ nano capture.sh
#!/bin/sh

while :
do
    export CAMERA=`gphoto2 --summary --quiet 2>&1 | grep "Model: " | sed "s/Model: //"`
    if [ "x$CAMERA" = "x" ]; then
        sleep 1
        continue
    fi
    gphoto2 --quiet --capture-tethered --hook-script=camhook.sh
done


Step #3:
Make the script that handles the downloaded photo and send it via DICOM

$ nano camhook.sh
#!/bin/sh

if [ "x$ACTION" = "xdownload" ]; then
    echo "Converting to DICOM..."
    img2dcm -k "PatientName=$ARGUMENT" $ARGUMENT $ARGUMENT.dcm
    echo "Sending to storage..."
    storescu -aet "$CAMERA" --propose-jpeg8 192.168.100.51 9104 "$ARGUMENT.dcm"
    echo "Done."
    rm $ARGUMENT.dcm
fi



After having all the setup done, starting the capture.sh will make your camera now DICOM-able.



1 comment:

Unknown said...

Hi, you use Dicompass Dicom Camera on Android tablets, phones or Android enabled cameras (NIKON, SAMSUG)..
https://play.google.com/store/apps/details?id=org.medoro.dicompasscamera