Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am currently doing particle detection on some images and I wanted to do an Image Background Subtraction similar to what is available on ImageJ so as to even out the background tone.

ImageJ uses a Rolling Ball algorithm which I believe is a type of Top-hat transform using a ball as a structuring element.

I currently have to do the background subtraction in ImageJ and then import the file to Mathematica to do the rest of the particle detection.

Could anyone help me write a rolling ball background subtraction algorithm in Mathematica, or does anyone know another way that I can flatten out/even out the background tone of my image?

This is my first question, and I'm not well versed in image processing, so I'd be happy to provide any other information that might be useful if I can. Thanks!

share|improve this question
1  
Have you looked at the TopHatTransform command? The second argument (the kernel) can be specified to be any shape you wish (like a disk). –  bill s Feb 11 at 5:23
    
Please add as much info, code and sample data to make this question answerable. –  Yves Klett Feb 11 at 12:37
add comment

closed as off-topic by Yves Klett, m_goldberg, bobthechemist, Michael E2, rm -rf Feb 13 at 16:17

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question cannot be answered without additional information. Questions on problems in code must describe the specific problem and include valid code to reproduce it. Any data used for programming examples should be embedded in the question or code to generate the (fake) data must be included." – Yves Klett, m_goldberg, bobthechemist, Michael E2, rm -rf
If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

up vote 5 down vote accepted

You could create your own filter, using DiskMatrix embedded into a zero matrix the size of the image, and then apply your filter with the resulting mask, iteratively "rolling" the disk insert. Probably not very efficient compared to using such an algorithm in an image-processing program where it's coded/compiled at low level.

Nonetheless, there are tons of fairly efficient means in MMA to make "particles" stand out in an image, I offer this rudimentary example:

    (* make a smeared background *)
    background = MedianFilter[RandomImage[1.5, {200, 200}], 10];

    (* populate it randomly with twenty one-pixel "particles" *)
    data = ImageData[background];
    (data[[# /. List -> Sequence]] = 100) & /@ RandomInteger[{1, 200}, {20, 2}];
    particles = Image[data]

    (* do a median filter on result, subtract from original *)
    ImageSubtract[particles, MedianFilter[particles, 10]]

    (* result via TopHat (as suggesed by bill s *)
    TopHatTransform[particles, DiskMatrix[1, 7]]

Original:

enter image description here

Filtered:

enter image description here

TopHat:

enter image description here

share|improve this answer
    
Rohan: Appreciate the accept much, but almost always wise to hold off a day or so: you never know what clever answers may emerge, and who knows, someone may read it that has implemented the exact algorithm you're interested in... –  rasher Feb 11 at 6:58
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.