How to completely remove the background of microscopic image



Good day!

I’ve tried removing the background of my sample images using the Process > Subtract Background method. I’ve also tried subtracting the blank image from the image with my samples but they both won’t work.

I would have to apply Fractal analysis on my images so I wanted to create an automatic way to delete the background so when I adjust the threshold of the binary images of my sample, I wouldn’t overestimate or underestimate the sample image.

Here is a sample image. Please help. Thanks!


Maybe there is some confusion of what “background removal” is.
Background removal often relates to the uneven illumination of brightfield microscopy images, or the bias/offset of darkfield images.
I do not believe your image is either of those. It looks more like reflected light.

Can you explain how you captured it?


Ohhh. I’m a new user of ImageJ and I believe I’m somehow confused. I though background removal meant removing all parts of the image that isn’t the sample.

My samples are brightfield microscopic images of collected dust stuck on glass fiber filters.
However, the microscope we own has a broken light source, so I used a lamp to shine light on the glass fiber filter which also resulted to uneven light on my samples.

I’ve tried the Process > Subtract Background on this sample:

I subtracted 15 pixels from this sample which resulted to this:

Eventually, I adjusted the threshold and it had a really good result. In fact, I got the result I want, and ImageJ adjusted the threshold automatically which means I did not over/underestimate the amount of dust (which will be analyzed by Fractal Analysis later on) on glass fiber filter respectively:

^ It worked on my other samples, however, on this particular type, the method above doesn’t seem to work. It looked like this:

I’ve tried raising the pixels to 100, 150, … 500. None seemed to achieve the results I wanted like the above sample.


Btw, for this type of sample

I wanted to achieve a binary image something like this:

I really want an easier, automated, and constant method of removing the unnecessary parts of the microscopic image without disregarding the dust particles when converting it to binary image.

Thank you for all the help.


I do not think that you can do that with the methods you tried which are for different types of illumination. You have reflected light and a textured surface.
Try some local thresholding, for example the Phansalkar method seems to produce some reasonable results.


Try this…it just sneaks up on the first bump in the histogram.

//Thresholding via histogram by Ron DeSpain 180320
if(nImages==0) {open();}
if(nImages==0){showMessage(“This Macro requires an open image”); exit();}
ot = getTitle();
run(“Duplicate…”, " ");
getHistogram(values, counts, 256);
print(values[0], counts[0]);
print(values[80], counts[80]);

for(i=1; i<255; i++){
print("graylevel: “+values[i]+” Counts: “+counts[i]+” countMax: "+cmax);

if(counts[i] > cmax)

print(“graylevel: “+values[i]+” Counts: “+counts[i]+” countMax: “+cmax);

//the cmax/3 ratio below is the threshold governer
if(counts[i] < cmax/3 && counts[i] != 0) {
run(“Duplicate…”, " ");
setThreshold(0, i);
setOption(“BlackBackground”, true);
run(“Convert to Mask”);
run(“Divide…”, “value=255”);
mask = getTitle();
imageCalculator(“Multiply create”, ot,mask);


//Macro End

Here’s it’s output…try it on some other of your images and tune it by changing the cmax/3 ratio.