# How to Count Cells, Annihilate Sailboats, and Warp the *Mona Lisa*

In a recent series of Image Processing with *Mathematica* workshops held at universities across the United States, we presented *Mathematica*‘s new image processing functionality and applied it on the spot to attendees’ real-world problems. It was amazing to me to see how rapidly and flexibly *Mathematica* could be applied to solve complex image processing problems. For example, it might seem like writing a program to automatically count cells in an image would be a master’s research project, but amazingly you can do it with a few lines of *Mathematica* code.

Below I am using morphological operations and measurement tools to segment and analyze red blood cells in a microscopy image.

Cell segmentation and hole filling can be done with an intensity thresholding using `Binarize` and `FillingTransform`:

As you may notice, some cells are overlapping, and this will eventually cause misleading measurements. In order to separate the overlapping cells, I extract a set of markers by finding local maximas of the `DistanceTransform` and use these as markers in `WatershedComponents`:

Next, I select cells whose pixel counts fall between a reasonable cell size and use our powerful `ComponentMeasurements` function to locate and analyze the cells:

I can also use `ComponentMeasurements` to take measurements for all selected components. Here I plot the size distribution of the cells:

Image restoration is another major topic in image processing. It is sometimes used to visually enhance the image quality or make the details more visible.

Below, I use our new `Inpaint` function to retouch a crack in an old picture:

In order to locate the crack, I create and use an oriented derivative filter:

This function takes the image derivative along the specified orientation. Here you can see the result of the function on an image of a disk:

To create the crack mask, I take the oriented derivative of my Lincoln image along 120º and compute straight and strong edges in that image:

In order to completely cover the crack, I use morphological `Dilation` and then use `DeleteSmallComponents` to delete components that do not belong to the large crack:

Now, removing the crack is as simple as running `Inpaint` on the original image and the created mask:

Let’s take a look at the before and after images side by side:

`Inpaint` by default uses a texture synthesis algorithm and therefore can also be used to remove large objects from an image. Here is an example:

Here is again a side-by-side look at the before and after images:

Restoration techniques such as smoothing, denoising, and deblurring are sometimes essential as preprocessing steps in an image processing task. We have introduced many smoothing functions in *Mathematica* 8. Below I have an example where an edge-preserving smoothing can help a segmentation task. The image is a kidney ultrasound, and we want to segment the angiomyolipoma (the large, light blob at the upper left):

I am using our new `PeronaMalikFilter`, which is an inhomogeneous diffusion method used for smoothing the image while preserving the edges:

Once the image is smoothed, an intensity thresholding can detect the bright tumor, and then we apply a selection based on the size of the bright object. Below is the tumor highlighted in the original image:

I also demoed *Mathematica*‘s transformation and registration capabilities starting with `ImageTransformation`, our new and optimized image transformation that can take any function to spatially transform image pixel coordinates.

Here is an example where a sine wave is added to the *x* coordinates of the *Mona Lisa*.

Or a custom function to create a fisheye effect:

I also showed the integration of Wolfram|Alpha into *Mathematica* and its current image processing capabilities. We are expanding the extent of these capabilities on a daily basis. Here is a quick example:

In addition, using the `Compile` function, DLL linking, and new CUDA or OpenCL linking (which can all increase the performance of a program) were among the most popular topics.

Below I have an example where I would like to apply a function to all pixel values in an image using `ImageApply`. While the two versions give exactly the same result, the computation is ten times faster when using the `CompiledFunction`:

Here is what some attendees had to say about the Image Processing with *Mathematica* events:

[The] talk and Workshop focus on my thermography problem were an “eye opener,” even for a long-term user like myself. The imaging processing functions built in to

Mathematicaare so powerful and comprehensive that I will now probably require my students to use it on their Senior Project….—

As someone who has given quite a few technical presentations, I was very impressed with [the seminar]. This just confirms my belief in the quality of the product put out by Wolfram Research… I think that

Mathematicais the single most impressive product I have ever used or seen. It is a bonus that Wolfram believes in its product enough to offer free seminars.

We discussed many more image processing applications in the university workshops. If you were not able to attend, I encourage you to explore our image processing functions by starting from the main guide page for image processing and analysis. We also have several training courses and seminars available regularly.

Would you like a Wolfram developer to give a seminar near you? Request a *Mathematica* presentation, workshop, or event in your area or at your organization.

Thank you to all of the attendees and other presenters for your participation and support. We enjoyed meeting all of you and hope to see you at future Wolfram events.

Download this post as a Computable Document Format (CDF) file.

aren’t these features included in mathematika 7……nonetheless these are amazing pieces of genius coupled with creativity!!…:-)

@ Sankalp –

The functions we highlight in this post are all new to Mathematica 8.

Thank you!

Weren’t these techniques already covered in the 2011 conference?

These techniques were covered during the Wolfram Technology Conference 2011. However, many readers of this blog and

Mathematicausers were not able to attend the conference. This blog post allows more users to experience these features ofMathematica.Thanks. Really powerful functionality.

Would be really cool if could just upload a picture to Wolfram Alpha mobile and have it count the objects in a picture for me.