Day 30: Basic image analysis with MATLAB’s regionprops

If you’re lucky enough to have imaging data that you can analyze without turning to contemporary machine learning approaches or you just need a first pass, MATLAB’s regionprops is a handy tool with a lot of functionality.

Today I’ll show how you can combine some of the

First let’s make a semi-realistic looking microscopy image:

The next step is to threshold the image and eliminate any stray particles:

The last step of the analysis involves regionprops, which outputs a structure array. This is pretty useless unless you have a clever way of getting the data out. We’ll use struct2table.

At this step, it’s pretty much up to you what you want to do with your table. Group it, rank it, sort it! In the banner image above, I create a scatter plot that represents each ROI as a circle with a diameter equal to the ROI’s area, and each circle is colored based on the mean intensity of the ROI from which it came. Here is a gist showing completely how that was done:

Create a density map using pdist2

Since we have the centroid distances, we might as well use them to calculate a density map from our image. To do this, we use the pdist2 function which calculates the pairwise distance between every element in two sets of (x,y) values. We input our centroids twice to return a matrix with Euclidean distances between them:

The diagonal entries measure the distance between an ROI and itself, so we needn’t include them in our analysis. We’ll set them to NaN so we can instead compute the minimum value (which is the distance from each ROI to its closest neighbor).

You can then use a scatterplot once again to highlight ROIs with nearby neighbors.

By adding a colorbar you can see the distances for each ROI.

The possibilities for using regionprops are pretty limitless and can be crafted for many different applications. Hope these two examples give you some inspiration to get started on your own custom image analysis projects.



Neuroscientist/cell biologist/data scientist at Columbia University

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jozsef Meszaros

Neuroscientist/cell biologist/data scientist at Columbia University