Image Segmentation on an Image with low contrast and nonuniform lighting

The image I'm working with looks like water droplets on a sheet of metal. What I'm trying to do is obtain statistics, such as blob area and centroidal distance of the shapes. I have figured out all of the code to accomplish this, but my code is lacking in the image processing department.
Shadowing has become a factor and due to the non-uniform lighting, it is difficult to do contrast adjustment effectively enough to separate the blobs from the background.
The process I have employed so far to segment the image is to:
(1) adjust the contrast of the image using imadjust
(2) apply a median filter to the image using medfilt2
(3) apply a top-hat filter using a structuring element imtophat(IM, se)
(4) adjust the contrast again using imadjust
(5) threshold the image into a binary using a decision statement
(6) morphologically open the image using bwareaopen and fill in holes using imfill
As of now, my code is able to pick out nearly all of the blobs in the image, but the centroids are obviously skewed, mostly due to shadowing I would guess. The blob area also may be a little skewed, which I think can be attributed to all of the complications that I've listed so far.
I would like to know if there are any suggestions for improving this process or maybe changing it completely. Thank you!

 Accepted Answer

The imadjust() calls are not really necessary. I'm not sure what your image looks like since you didn't upload it, or tell us where it was. I assume steps 7 was a call to regionprops(). Other than that, it's probably okay. See my image segmentation tutorial if you want to see how I do it for one kind of image (with uniform background): http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
Skewed distributions is normal for particle size analysis. They almost always show a log-normal or Lorentzian shape no matter what measurement you're looking at. There's even theory that says why (ref: http://search.barnesandnoble.com/Particle-Size-Measurement/Terence-Allen/e/9780412729508, which is the bible of particle size analysis) Don't expect that you'll get textbook perfect Gaussian-looking distributions - it almost never happens. They're almost always skewed.
The locations of your centroids may be shifted due to shadowing issues. That's why it's always best to try to correct image capture problems first rather than try to compensate for them during post processing.

5 Comments

I don't own the image, so I can't upload it to the site; that is what also keeps me from being able to fix the lighting issue during any time except post-processing. Step 7 is a call to regionprops() and then the remaining code is just manipulating the data that I get from regionprops and putting it in a form usable for my application.
Maybe I wasn't using the right verbage with saying skewed. Just that I know the shapes of the blobs should be half-spheres (circular in a 2-D point of view) and the centroid should be in the middle of those circles and that's not really happening. I think that it all has to do with shadowing and that the median filter blurs the image and shifts all of the centroids away from the shadowing.
And I use imadjust() so I can see threshold values a little more clearly. Is there something I should do instead of that to make the process better?
I've also looked into certain processing techniques such as edge detection (both Canny and Sobel methods), but again there just isn't enough contrast for those to be useful. Is there anything that you would do to help edge detection be more effective?
imadjust isn't necessary to do thresholding. Thresholding produces a binary image and that doesn't depend on how easy it is to see the image. If you're doing masking (multiplying the binary thresholded image by the original image) and want to see it more clearly, then you can use imadjust. But personally I'd never use imadjust on my actual data. You can use it on a copy of the data that you're sending to imshow() if you want but it's risky to use it on your data because how it adjusts depends on what's in there and if you have parameters set up for subsequent steps, then these may no longer work well. Or they may work fine, you just have to be careful and know what you're doing.
To get the actual center, you may have to get both the shadow and the bright part and combine them. Or else model your background with a 2D polynomial and subtract or divide by that model. So basically you need to get everything that's not background. Though I'm not sure how much of the shadow you actually want to include. It's difficult to make recommendations on image processing without seeing an image.
Would it make sense to add two images together? Given the shadows are the darkest part of the image, it may be feasible to threshold them in one image (a), threshold the blobs in another image (b) , and add those two together in image (c).
I'm very new to MATLAB and the IPT, so I apologize for my simple or stupid questions.
Also, I'm looking at the histogram of my original image and comparing it to the histogram of your blobsDemo.m file. Your image had a binodal distribution, which lent itself to an easy threshold value. My image has a normal distribution with its center at ~110 and extreme points at ~60 and ~160, which does not lend itself to easy thresholding. Would you suggest a histogram equalizer or something else to help the image processing along?
You wouldn't add them, you'd AND them with the & operator since they are binary (logical) images. With a background gradient, you won't have a nice bimodal histogram, so you need to use local methods like tophat filter, or else correct for the background, maybe by using a 2D polynomial and then dividing your image by the modeled background. I use John D'Errico's polyfitn to do background modeling: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A679
Don't do histogram equalization. It is a complete waste of time and won't help at all in this kind of situation (even though I have a really nice one in the File Exchange).

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!