Saturday, February 8, 2014

Rigid Image Registration (a quick & dirty intensity-based approach)




Fig. 1. Showing the original image, the manual transformed, and the automatically corrected image via registration algorithm.

Image registration is useful when you want to compare different images from the same object but taken from different angles. In order to make the images comparable, one has to correct the transformation of the target images, so that the target images align with the reference image. This is a quite useful technique with a broad range of applications. One of them is in Medical Imaging where images of the same anatomical structures are taken with different modalities and at different time points.

In this example I am loading good old Lena into the application to demonstrate the function of the code. The important part of this implementation it the finding of initial values (guess) for the fmin (optimization-) function. Without that step, the function is very likely not able to find the correct transformation parameters. Thus, to provide an initial guess, I let the x,y (image shift) and the r (image rotation) vary from -10 to 10 and calculate the intensity-based image errors. Subsequently, the minima for these variations are determined and used as initial guess. (Maybe not the best method but quite simple and robust). Then, I pretty much let the fmin function do the magic to search for the parameters that yield the smallest value returned form the intensity-based image error function.    

The Python code:



       
'''
@author: Christian Rossmann, PhD
@license:  Public Domain
@blog: http://scientificcomputingco.blogspot.com/
'''

import numpy as np
import Image
from scipy import ndimage
from scipy import optimize
from scipy import misc

from pylab import *

def MeasureErr(img1,img2):
    diff = (img1-img2)
    return sum(diff**2)

def RigidRegistration(img,ximg):
    
    # Perform initial guess rotation & translation 
    v_range =  np.array(xrange(-10,10))
    
    err = np.array([MeasureErr(img,ndimage.shift(ximg,(v,0))) for v in v_range])
    x = v_range[where(err==err.min())[0]]
    
    err = np.array([MeasureErr(img,ndimage.shift(ximg,(0,v))) for v in v_range])
    y = v_range[where(err==err.min())[0]]

    err = np.array([MeasureErr(img,ndimage.rotate(ximg,v,reshape=0)) for v in v_range])
    r = v_range[where(err==err.min())[0]]

    # List contains displacement in x and y and rotation
    
    param = [x,y,r]
    
    def ErrFunc(param,img=img,ximg=ximg):
        
        # Perform rotational and translational transformation
        
        _img = ximg.copy()
        _img = ndimage.rotate(_img,param[2],reshape=0)
        _img = ndimage.shift(_img,param[:2])
        
        return MeasureErr(img,_img)

    
    param = optimize.fmin(ErrFunc,param)
    
    #Final transformation
    _img = ximg.copy()
    _img = ndimage.rotate(_img,param[2],reshape=0)
    _img = ndimage.shift(_img,param[:2])
    
    return (_img,param)

img = misc.lena().astype('float32')

# Normalize image (0-1)
img -= img.min() 
img /= img.max()

# Generate transformed image
ximg = img.copy()
ximg = ndimage.shift(ximg,(5,-1))
ximg = ndimage.rotate(ximg,-4,reshape=0)

(rimg,param) =  RigidRegistration(img,ximg)

 
figure(1)
clf()
subplot(1,3,1)
title('Original')
imshow(img)
subplot(1,3,2)
title('Transformed')
imshow(ximg)
subplot(1,3,3)
title('Registered')
imshow(rimg)
show()

Monday, October 14, 2013

Python Spyder, clear workspace/shell command



Python Spyder is a great Tool similar to Matlab but still lacking commands for clearing variables form workspace. I've added following code to the Spyder startup file (C:/Python27/Lib/site-packages/spyderlib/scientific_startup.py) to generate clear commands for workspace and the shell:


So whenever I type clear() or clear_all(), the command shell or the variables from the workspace will be cleared, respectively.



Tuesday, October 8, 2013

Cancer treatment with Doxorubicin (a mathematical model)

Cytotoxic antineoplastic drugs are administered to treat many different types of cancer including breast, lung, bladder and liver cancer. Doxorubicin (DOX) is a chemotherapy agent (also called Adriamycin) which is given by injection or drip (infusion) through a fine tube inserted into the vein (e.g. cannula), through a fine plastic tube inserted into a vein near your collarbone (central line) or into a vein in the crook of your arm (PICC line). Mathematical modeling can be used to determine DOX drug concentration in in systemic plasma, aggregate body tissue, tumor plasma, tumor interstitial space, and tumor cells. Such mathematical models allow optimization of drug delivery systems to achieve a better therapeutic index.

In the section below I present a mathematical model according to (http://www.musc.edu/ablation/pubs/Gasselhuber,%20PLos%20One%202012.pdf) to predict systemic and tumor drug concentrations for DOX in mice.

Overview about the mathematical model including compartments for body plasma, body tissue, tumor plasma, extra and intracellular compartment for tumor tissue. The transport mechanism between the compartments are indicated via arrows.


The ordinary differential equation model was built and solved via Python.















Wednesday, September 18, 2013

Low-cost, small animal thermal ablation system


 The goal of this project was to develop a cheap, simple and robust ablation system for creating small thermal lesions in animals. As soon as biological tissues are exposed to temperatures > 40 degree Celsius for several minutes (~>30) tissue necrosis occurs and introduces cell death. This technique is used in cancer therapy to kill cells and to destroy tumors. 
Schematic of small animal ablation example in a mouse brain to study brain cancer treatments.
The understanding of ablation techniques and the development of heating algorithms/strategies rely on animal research studies. To provide a low cost system for ablation studies in small animals (mice,rats) I developed a simple system including a graphic user interface.

Schematic connection sketch for the micro-controller and electronic board.
The system uses an Arduino-Uno Micro-Controller (MC) board and an ordinary, resistive thermistor. The graphic user interface (GUI) communicates with the MC about 4 times per second. In a first request voltage is read from the thermistor to determine the actual temperature. Then in a second step the GUI/program calculates the necessary voltage to reach the required set-temperature (defined by user) and  sends the info to the MC. On the MC the voltage reaching the thermistor will be set accordingly. An integrated PI (proportional/integral) controller regulates the voltage to keep the temperature at the thermistor constant.
Graphic user interface for the Thermistor control
Total costs of the utilities < $50 (Micro controller board $25, Thermistor $8, Wires, etc $17)

Links:
Thermistor:
http://www.mouser.com/ProductDetail/Honeywell/112-102EAJ-B01/?qs=F1jq4PciTHu%252b30xNPtI64w%3D%3D&gclid=CJzDjPjl1bkCFdSd4Aod5VYA8A

Wednesday, July 31, 2013

Radiofrequency tumor ablation with COMSOL (tutorial)

Radiofrequency ablation modeled with COMSOL



Tissue ablation is the destruction of diseased (pathologic) tissue with the aim to cure a disease. One way to achieve this is via thermal methods (i.e. thermal ablation), by either heating or cooling to temperatures lethal to cells (typically below -40 °C (-40 °F), or above 50 °C (122 °F)). A number of different physical principles can be employed for heating and cooling tissue, such as radiofrequency (RF) electric current, microwaves, laser, ultrasound, and cryogenic cooling. In our lab we perform research on ablation using heating by RF currents, or cryogenic freezing.

In this tutorial I am using COMSOL to simulate radiofrequency tumor ablation for 15 minutes. Following will be covered in the tutorial:
  • Radiofrequency heating via single cool-tip electrode
  • Automatic Voltage PI-control for constant heating temperature in tissue
  • Arrhenius tissue damage model
  • Bioheat equation / perfusion decrease due to tissue damage
Download the tutorial (pdf): https://dl.dropboxusercontent.com/u/41416749/COMSOL/COMSOL%20RFA%20%2B%20ARRH%20-%20Tutorial.pdf