# Measuring what fraction of an image is covered by filaments

I'm trying to measure what fraction of an image is covered by filaments. I have tried several combinations of image processing functions without any luck. Any help?

img = Import["https://i.stack.imgur.com/Pvh7c.jpg"];


• this can be a start: MorphologicalBinarize[GaussianFilter[img, 0.2], 0.42] // ColorNegate //MaxFilter[#, 1] & – Ali Hashmi Jul 2 '17 at 0:01
• Thanks Ali, MaxFilter is great, but I need something sharper – JBogoya Jul 4 '17 at 22:05
• MorphologicalBinarize[BrightnessEqualize[img],0.43] // Opening[#, 2] & // DeleteSmallComponents[#, 100] & – Ali Hashmi Jul 4 '17 at 22:46

Almost

HighlightImage[img,bin = MorphologicalBinarize[
TopHatTransform[GaussianFilter[img, 10], 10], {.01, .02}]]


N[Total[ImageData[bin], 2]/Times @@ ImageDimensions[bin]]


0.278293

• Impressive, thanks a lot – JBogoya Jul 4 '17 at 23:15
• Good answer. You could use Mean@N@Flatten@ImageData@bin, then you wouldn't have to divide by the number of pixels – Niki Estner Jul 5 '17 at 7:44
• @nikie Thanks,that is a good tech.. – yode Jul 5 '17 at 8:36

by no means it is a complete answer. But one can surely play around with it a bit

img2 = MorphologicalBinarize[GaussianFilter[BrightnessEqualize[img], 2], 0.44] //
Opening[#, 2] & // DeleteSmallComponents[#, 200] &

(* for cropped image i took *)
Length@PixelValuePositions[img2, 1]/(Times@@ImageDimensions[img])
(* ~ 0.20 *)


• I found a little better result using PeronaMaikFilter, LocalAdaptiveBinarize, and DeleteSmallComponents functions – JBogoya Jul 4 '17 at 23:16
• @JBogoya Great. Good that worked out for you – Ali Hashmi Jul 5 '17 at 8:39
• @JBogoya You can post your own solution as an answer, it is encouraged here. – Alexey Popkov Jul 5 '17 at 9:13
• DeleteSmallComponents[ DeleteSmallComponents[LocalAdaptiveBinarize[PeronaMalikFilter[fig, 20], 250], 400] // ColorNegate, 150] // ColorNegate – JBogoya Jul 6 '17 at 1:13