Q2

You're an aspiring computational biologist, working with some alveolar (lung) cells to study some of the cellular machinery involved in disease progression. You've tagged the proteins you're interested in, run your experiment, and collected your data from the confocal microscope in your advisor's lab.

Unfortunately, someone didn't properly secure the confocal microscope, because some dust or something got shaken loose during your imaging slot and it seems to have corrupted your images!

You don't have enough time to completely re-do the experiments, so you'll need to use your computational skills to clean up the data post-acquisition.

A

The scipy.ndimage submodule has lots of "filters" you can use to process your images. In the lecture we saw how the Gaussian filter worked for smoothing; we'll use that again here, in addition to a median filter.

The functions you'll want to use are ndimage.gaussian_filter and ndimage.median_filter. You can find their respective documentation pages here and here.

The upshot is both functions have 2 required arguments: the first is the image (of course), and the second is an integer that indicates the filter size; for the Gaussian filter, this argument is sigma; for the median filter, this argument is size.

Experiment with both filters, and with a few filter sizes. Plot the results of your filters using plt.imshow(), which has already been imported for you. Make sure you post the results!


In [ ]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import scipy.ndimage as ndimage

img = ndimage.imread("noisy.png", flatten = True)

### BEGIN SOLUTION

### END SOLUTION

B

Compare and constrast the two types of filters (Gaussian and median). Are there similarities between their effects? Are there differences? How do the filter sizes affect the outputs? Can you speculate as to how these filters work under-the-hood?

C

Choose one of your filtered images from Q2A that you think would be a good candidate for counting the number of cell objects.

Write a function count_cells which accepts two arguments: a filtered image, and a pixel threshold. This function should set all pixel values below that threshold to 0. It should then use the ndimage.label function to count the number of cells, and print out how many cells it found. The documentation page for this function is here.

You don't have to plot the labeled objects (you can if you want), but your code should print the number of objects you found.


In [ ]:

D

Using the function you created in the previous question, re-run the cell counter, but this time on the original noisy image. Run it a few times, changing the pixel threshold you set (but using the original noisy image each time). How does the number of objects your function finds change with the pixel threshold?

Now run it on a filtered image, but change the filter size. Make it really small and count the number of objects. Make it really large and count the number of objects. Keep the pixel threshold constant for this. How does the number of objects your function finds change with the filter size?

Put your code in the box below, and write your responses in the box below that.


In [ ]: