5
$\begingroup$

I have a microscopic image (img1).

img1

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

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):

enter image description here

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?

$\endgroup$
2
  • $\begingroup$ 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? ... $\endgroup$
    – xiaohuamao
    Commented Mar 11, 2021 at 5:07
  • $\begingroup$ @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 $\endgroup$
    – P Pyne
    Commented Mar 11, 2021 at 6:28

3 Answers 3

8
$\begingroup$

Try ComponentMeasurements

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

cells = ComponentMeasurements[pic // Binarize, {"Centroid", 
"EquivalentDiskRadius" },  #AdjacentBorderCount == 0 &&100 < #Area &];
HighlightImage[pic, Circle @@@ cells[[All, 2]]]    

enter image description here

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

enter image description here

shows the plot with the selected circles only.

$\endgroup$
2
  • $\begingroup$ @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 $\endgroup$
    – P Pyne
    Commented Mar 8, 2021 at 12:50
  • $\begingroup$ @PPyne "bild"=pic (I modified my answer) ! Sorry, I cannot test my code with MMA v9 . $\endgroup$ Commented Mar 8, 2021 at 13:03
4
$\begingroup$

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 *)
$\endgroup$
2
  • $\begingroup$ @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? $\endgroup$
    – P Pyne
    Commented Mar 11, 2021 at 7:10
  • $\begingroup$ I have version 12.1. "#Area" is showing green, that seems o.k. $\endgroup$ Commented Mar 11, 2021 at 8:42
4
$\begingroup$

Here's my trial, which is v9 compatible:

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

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

enter image description here

mask = Dilation[comp, 5];
HighlightImage[img, mask, Method -> "Boundary"]

enter image description here

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

enter image description here

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

$\endgroup$
1
  • $\begingroup$ thank you, it works fine $\endgroup$
    – P Pyne
    Commented Mar 11, 2021 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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