# Wound Detection and Cell Velocity¶

The In Vitro Scratch Assay is a convenient protocol to analyze wound healing. This package provides tools to analyze cell velocity from time series of wound healing experiments. The package is installed via pip

\$ pip install wound


To detect the wound on an image called ‘wound_t08.jpg’ we call wound.detect()

>>> import wound
>>> my_wound = wound.detect('wound_t08.jpg', sigma=25, thresh=.4)
>>> print(my_wound['area'])
71922.0


The result is a dictionary with values from the detection such as area and perimeter. We can plot the detected wound on the original image with Pillow

>>> from PIL import Image
>>> im = Image.open('wound_t08.jpg')
>>> c, r = my_wound['edge']
>>> coords = zip(r.astype(int), c.astype(int))
>>> _ = [im.putpixel(x, 255) for x in coords]
>>> im.save('result.png')


In order to analyze a time series experiment with multiple images we need a list of wound detection dictionaries. Let’s assume we have three images in our experiment, each taken with 1.5 hour intervals. We parse these to detect() as a two lists

>>> images = ['1.png', '2.png', '3.png']
>>> time = [1.0, 2.5, 4.0]
>>> my_series = wound.detect(images, time)


This detects wounds on all images and assign an experimental time to each of them in order. It is very important the images and time is have the same order. The returned list my_series can be used to fit a velocity model (wound.Model) with the function wound.Model.fit()

>>> model = wound.Model()
>>> model.fit(my_series)
<wound.velocity.Model object at 0x...>


When a model is fitted it can be used to predict cell velocity at desired time points with the models own wound.Model.predict() function

>>> predict_time = [1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5]
>>> velocity = model.predict(predict_time)


With the return_std=True is passed to predict the standard deviation of the velocity is returned as well.

# Different ways to detect images¶

There are three different ways to give images to wound.detect(). You can parse a file path to the image

>>> path = 'wound_t08.jpg'
>>> my_wound = wound.detect(path)


or a PIL image

>>> import PIL.Image
>>> pil_image = PIL.Image.open(path)
>>> my_wound = wound.detect(pil_image)


or even a numpy.ndarray

>>> import numpy
>>> array_image = numpy.asarray(pil_image)
>>> my_wound = wound.detect(array_image)


For all of these cases you can parse a single image or a list of images.

# Package Reference¶

Here is a listed the avaible classes and functions in the package. The Index gives an alternative alphabetchic listing of the package content.

class wound.Model(area_kwargs=None, perimeter_kwargs=None)[source]

Wound velocity model.

The model is based on Gaussian Process Regression (GPR) and numerical differentiation. The GPR uses scikit-learn GPR class sklearn.gaussian_process.GaussianProcessRegressor.

Parameters: area_kwargs (dictionary) – The keyword arguments to the area GPR model. perimeter_kwargs (dictionary) – The keyword arguments to the perimeter GPR model. area (area model) – Instances of GaussianProcessRegressor from scikit-learn. perimeter (perimeter model) – Instances of GaussianProcessRegressor from scikit-learn. time (sequence) – Sequence of the input time points. Defined when fitted.

Notes

The keyword argument kernel is specifying the covariance function of the GPR models handling the area and perimeter. The default kernel is a sum of a linear and squared dotproduct kernel. See scikit-learn for the different kernels that can be used. Note that the kernel hyperparameters are optimized during fitting.

fit(wounds)[source]

Fitting the velocity model to wound data.

Parameters: wounds (sequence of dictionaries) – A sequence of wound dictionaries representing an experimental time series of the wound healing assay, as returned by detect(). The area, perimeter and time point of each wound is used to fit the overall velocity model. self – The velocity model in a fitted state. Model
predict(time, return_std=False)[source]

Predicting a velocity curve of a wound healing experiment.

In addition to the mean of the predictive distribution, also its standard deviation (return_std=True) can be requested.

Parameters: time (sequence) – Sequence of the desired time points of the prediction. return_std (boolean) – Whether to include the standard deviation of the prediction or not. velocity, [vel_std] – Velocity and (optionally) it’s standard deviation. Returned either one array or (if return_std=True) as a tuple (velocity, vel_std). 1d arrays
wound.detect(images, time=None, sigma=25, thresh=0.4, err=0.05, radius=None, scale=1)[source]

Detect wound on a image with uncertainty.

Parameters: images (sequence of [file paths | numpy.ndarray | PIL.Image]) – Images to detect wound(s) from. A single image path, array, or PIL image can be passed outside a sequence. time (sequence) – The time points of the images (same order as images). sigma (scalar) – The standard deviation of the image smoothing. This should be roughly the same as the distance (in pixels) between cells at confluency. thresh (scalar) – Threshold factor to calculate wound boundary. Between zero and one. err (scalar) – Standard error of the threshold value to calculate uncertainty of the detection. radius (scalar, default is None) – If radius is not None and more than 2 images parsed the algorithm uses the mean center of mass of the two first wounds to define a circular zone of exclusion with radius radius in pixels. Subsequent wound candidates have to been inside this zone to be considered valid wounds. scale (scalar, default is no scaling with scale=1) – Down scale factor to use on images for detection speed. Trades of accuracy versus cpu time. A scale of .5 will detect fast on a image of 25 % the original area. All other parameters are auto scaled. Return scale is not affected. Bigger than zero up to and with one. wound(s) – Returns one dictionary (or a list of several) with the detected wound values area perimeter (without parts that touches image border) area and perimeter variances center of mass time edge (tuple of wound edge x and y coordinates) filename, (image file path if loaded from disk) image area Returns None, for wounds that can not be detected. dictionary or a list of dictionaries

Notes

All image types and bit depth supported by Pillow can be used as input. If the images contain more than one color channel the sum of all channels will be used.

wound.sort_and_cutoff(wounds, min_area=0.05)[source]

Sort by time and cutoff based on minimum area.

Utillity function to sort wounds by time and filter out wounds by minimum area.

Parameters: min_area (float) – Percentage of the image size to consider a closed wound area. After this limit is hit the following time points will be excluded from the wound list. Range zero to one (ratio of image area). wounds – A wound list sorted by time point of the wounds. The following will remove wounds from the returned list: wound area smaller than min_area * image area wounds with later time point than the first removed None wounds list of dictionaries