# Remove some of the background noise to get clear microscopic image

I have a microscopic image (img1).

I need to analyse it to be like the following image (img2):

But how do I do it in Mathematica (I am using Mathematica 9)? I am not much familiar with the processing of images.

I have tried using TotalVariationFilter. After using this the image looks like the following (img3):

Now the problem is that the particles look blur (hezzy).

The code I have used:

filtered = TotalVariationFilter[imj, 0.4]


So is there any option to bring the particle bright and clear remaining all other things unchanged?

• Can you provide more details of the aim/criterion of your desired processing? This is an interesting question but the description is vague. Any shape larger than a specific size? Large structure of a particular shape? ... – xiaohuamao Mar 11 at 5:07
• @xiaohumao thank you,actually I want to remove background noise (img1) i.e. the particles which are not clearly visulased and also very small size, just like background subtraction, on addition the outer layer the particle should be removed – P Pyne Mar 11 at 6:28

Try ComponentMeasurements

pic=[![enter image description here][1]][1]

cells = ComponentMeasurements[pic // Binarize, {"Centroid",
HighlightImage[pic, Circle @@@ cells[[All, 2]]]


Graphics[Circle @@@ cells[[All, 2]]]


shows the plot with the selected circles only.

• @Neumann Thank you for the idea, however I could not evaluate it, I think "AdjacentBorderCount" and " Area" is not evaluating as it appears as blue color in my system (Mathematica 9)and I did not understand what "bild" is? Kindly help me – P Pyne Mar 8 at 12:50
• @PPyne "bild"=pic (I modified my answer) ! Sorry, I cannot test my code with MMA v9 . – Ulrich Neumann Mar 8 at 13:03

I do not know what your aim is. For the present, I assume that you want to count points of a given size. We proceed as follows:

First we copy the picture and make it black and white picture:

im1 = ImageAdjust[im0]
im2 = Binarize [im1]


Then we pick dots that have an area in a given range. E.g. big dots:

 ComponentMeasurements[im2, "Area", (100 < #Area < 300) &]

(*{1 -> 290.25, 138 -> 114.625, 166 -> 168.25, 285 -> 265.875,
318 -> 146., 500 -> 247.875, 503 -> 173.75, 655 -> 111.5,
736 -> 114.875, 778 -> 125.25, 869 -> 186., 888 -> 122.875,
891 -> 147.5, 1027 -> 125.5, 1056 -> 171.75, 1147 -> 143.625,
1158 -> 146.375, 1198 -> 224.25}*)


Finally we count them:

ComponentMeasurements[im2, "Area", (100 < #Area < 300) &]  // Length

(* 18 *)

• @Huber in my mahematica version "ComponentMeasurements[im2, "Area", (100 < #Area < 300) &] " is not executed and "Area" showing blue, can you please help me to get rid of this? – P Pyne Mar 11 at 7:10
• I have version 12.1. "#Area" is showing green, that seems o.k. – Daniel Huber Mar 11 at 8:42

Here's my trial, which is v9 compatible:

img = (* Copy and paste the image here *);

comp = SelectComponents[Binarize[img, 0.6], "Area", # > 80 &]


mask = Dilation[comp, 5];

ImageFilter[Mean@Flatten@# &, img, 7, Masking -> ColorNegate@mask]

Parameters like 0.6, 80, etc. are all determined by trial and error.