Public Lab Research note


Python and openCV to analyze microscope slide images of airborne particles

by amirberAgain |

Read more: publiclab.org/n/15519


Following the Jan 9th air quality open call I wanted to see what can be done with a microscope slide image of airborne particles. Inspired by the work started by Mathew and Stevie a couple of years ago I set out to try and get a similar process running on Python using openCV and skimage. Based on an old tutorial to detect coins I repurposed it for a single slide example. Once more example images are obtained this process could be made more robust, could also be a great candidate for DL!


Below is a code walkthrough:

1. load image, crop out the area with the scale on it.image description

2. Use Sobel edge detection to find particles.image description

3. Use a simple threshold to binarize the edges image.image description

4. Label binarized features.image description

5. Show area distribution of the particlesimage description

6. Sort and select only features which are larger than sizeTh (4 pX).

  • NOTE: I made a lazy assumption that each pixel is 1 um, this parameter can be adapted in the code to show real scale, this is a pixel scale - NOT um!

Largest:image description

Smallest:image description

6. TBC (use fractal dimension to detect if a particle is round or jagged). find a way to avoid false detection of two close particles, and from false detection of a section of large particles being reidentified by the label function.image description



air-quality pm microscope passive-particle-monitors microscopy particle-imaging


22 Comments

Hi, some days ago I talked about this topic with a friend of mine... the usecase is ongoing pollen analysis. Do you know whether there are pollen micro images which can be used to classify a particle as a pollen... and even better, also to classify from which tree/plant it comes?

Is this a question? Click here to post it to the Questions page.


This sounds very interesting, but I don't have any raw data. Maybe join the Tue. open call? I think this can be a great study case for ML/DL. Googling a bit got me to this 1939 post form pop-sci: https://books.google.co.il/books?id=7SwDAAAAMBAJ&pg=PA188&as_brr=1&cd=2&redir_esc=y#v=onepage&q&f=false

Is this a question? Click here to post it to the Questions page.


Hi, I'm trying to think how we can support and connect this work to the microscope team more -- could we post a call for images to try to run through this workflow? Both reference images and test images from DIY microscopes?

Maybe as a follow-on to this question: https://publiclab.org/questions/gretchengehrke/09-21-2017/is-it-possible-to-discern-jagged-from-rounded-particles-using-a-diy-microscope

Is this a question? Click here to post it to the Questions page.


In the comment section of the post linked below there is a link to a large cohort of images, thou I'm not sure if they represent airborne dust particles. Having looked at the posts from the last couple of years by many Public lab collaborators I feel that this issue has been dealt with rather well, so I'm not sure if the small code snippet I wrote is that relevant. That being said - I will be happy to upload it somewhere, is there a section of the git where it should go?

https://publiclab.org/notes/SimonPyle/05-13-2016/automating-imagej-for-particle-image-analysis

Is this a question? Click here to post it to the Questions page.


Oh yes please -- maybe make a new repository for now? Or use http://gist.github.com if it's just a few files.

Could you link to it from here? I think having a second implementation -- and a more standalone one -- could be quite valuable.

Is this a question? Click here to post it to the Questions page.


For now, my code and iamge excerpt can be found here, just untill I figure out how to have two git users on my machine, https://drive.google.com/drive/folders/1X0IK45IXxDBqPuxKQUqOQp-5BeLDu9zw?usp=sharing

Is this a question? Click here to post it to the Questions page.


@amirberAgain - a friend just posted this question, and I'm curious if you think any of the steps you wrote out are applicable to that kind of analysis as well -- https://publiclab.org/questions/jlev/02-01-2018/how-can-i-identify-bits-of-plastic-from-the-beach-in-an-image

@dakoller it'd be great to hear more about your interest in pollen too -- would you like to post it as a related question using the link under your comment?

In general, I'm trying to think through how these steps could be laid out one by one, for potentially solving in a modular way, like using ImageSequencer, in parallel to what @amirberAgain has done in Python -- with an eye to reusability across different similar challenges -- pollen, microplastics, dust. What do you think?

Is this a question? Click here to post it to the Questions page.


@amirberAgain as @warren suggested i am trying to implement this system in js for Image Sequencer, we already have modules for canny edge-detection (which already includes thresholding), can you please provide a little bit of insight on what metadata we want to associate with the image and how should we go about this, thanks a ton


@tech4gt note that the canny edge detection is an initial important part of a process. Extracting the actual location and sizes are found using the label function od Scikit learn's morphology module. http://scikit-image.org/docs/dev/auto_examples/segmentation/plot_label.html

I don't know how to apply SKL in JS.


@amirberAgain What metadata are we trying to get from the image, like are or perimeter? Also will the scale be already attached to the image, that part is not clear to me?

Is this a question? Click here to post it to the Questions page.


@amirberAgain i found this library, can this be of help https://github.com/PorkShoulderHolder/morph


Sorry, but I don't think this will provide with an "out of the box" solution. I noticed that the reference I gave you was not the right one, have a look at this one: http://scikit-image.org/docs/dev/api/skimage.morphology.html#skimage.morphology.label


@amirberAgain can you please also tell me the data we want to extract from the image, like area or number of particles, also will the input image already have a scale on it?

Is this a question? Click here to post it to the Questions page.


@tech4gt I think @stevie or one of the Microscopy group participants will be able to better explain what they are looking for. I believe a list of particles their size (in pixel) and possibly a measure of round VS jagged would be great. But they should be the address.


Oh, thanks a ton :D


@stevie can you please guide me a little here, what are the exact data we are looking for from the image and is the scale already attached on the input image? Thanks :)

Is this a question? Click here to post it to the Questions page.


Hi! Yes! Particle size is of interest, also shape, as mentioned (round vs. jagged) is interesting as well.

Adding in @dswenson and @partsandcrafts as well.


@stevie is the scale already attached on the input image?

Is this a question? Click here to post it to the Questions page.


For the microscope images, I don't think all the slides have a scale on them. It's not part of the setup to get it up and running, but you could use a calibration slide.


@stevie so i can start with assuming a scale and then later we can modify the code to incorporate the slide generation maybe?

Is this a question? Click here to post it to the Questions page.


I think that sounds good!


BTW FYI: I started looking in to contur operations on selected particles as a way to evaluate how round or jagged each particle is, more here: http://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_contours/py_contour_features/py_contour_features.html


You must be logged in to comment.