Fill incomplete holes (beginner help) / Histological analysis

Hello everyone,

I am quite new to the use of ImageJ and have been struggeling with a problem for quite a time now.
The first picture you see below is a histological sample of the kidney - the final aim of my project is to
find a way to take a closer look at the geometry of the brown cirlces in the tissue, the capillaries.
Therefore I try to fill the holes of these capillaries, so that the programm can later detect their circularity, perimeter, etc.
The point I’m struggeling with is the fact, that ImageJ doesn’t recognize some of the circles because of being incomplete. So on the second picture you can see the result after

  1. Process - Binary - Convert to Mask
  2. Fill Holes

On the third picture you can see another try of 1) + 2) after having edited the picture in Photoshop to desaturate the picture before, make it brighter and add more shadow to it.

As you can see, there are still cirlces that aren’t filled and other ones that are “overlapping”. I could complete the missing circles manually but despite the fact that I do have hundreds of samples this would take incredibly much time.

I would be very, very grateful for any kind of help/advice/ideas/etc.!
All the best,

Good day Charlotte,

this is a classic problem and the best solution is different preparation and image acquisition.

I know that usually this recommendation comes too late (why is this so?).

You may try various binary operations to fill gaps and to separate objects but in any case they will alter the objects and the corresponding measurements. The decision is yours, what approximations are tolerable.

You may also try “Grayscale Morphology”.

Good luck


Here’s a quick macro that might help get a little further, although it won’t get everything:

idOrig = getImageID();
run("Duplicate...", " ");
// Get the blue channel only
run("RGB Stack");
idDuplicate = getImageID();
run("Delete Slice");
run("Delete Slice");
// Apply subtraction to help even out the background
run("Subtract Background...", "rolling=10 light");
// Smooth a bit
run("Gaussian Blur...", "sigma=1");
// Apply watershed transform (the 10 is effectively the threshold! May well need to change!)
run("Find Maxima...", "noise=10 output=[Segmented Particles]");
// Use Analyze Particles to remove large regions, or those at the image boundary
setAutoThreshold("Default dark");
run("Analyze Particles...", "size=0-2000 show=Nothing display exclude clear add");
// Show results on top of the original image
roiManager("Show All without labels");

The basic idea is to use the watershed transform within Process → Find Maxima… to do most of the job, starting from all the ‘lighter’ bits and expanding these out, with guidance from the darker parts to prevent merging. This will certainly detect too many regions, but then large ones and those touching the boundary can be removed with Analyze → Analyze Particles….

It does risk detecting regions that aren’t capillaries, and missing some regions that are, and definitely needs more refinement… but hopefully it shows one approach that can help get around the difficulty in getting complete boundaries. A bit more time spent adjusting the parameters or perhaps including extra preprocessing steps should help (although I don’t know if it will help enough to be an acceptable solution).

Two quick questions:

  • Is your first image the original, or was any processing applied beforehand (e.g. color deconvolution)?
  • do you have images from a microscope (and this is the full size) or whole slide scanner (where the original is much bigger)?


First of all, thank you so much @anon96376101 and @petebankhead for your response!

I already tried the macro and some structures come out quite well - unfortunaetly it is quite important to me to get the small vessels as well. Actually I even think that the one big confluence in the middle of the picture isn’t too much of a problem because ther focus really lays on the circularity and perimeter of the capillaries and that the circles are complete.

@anon96376101 Unfortunately are quite right in your assumtion - (most of) the samples are already sectioned and some of them even stained, so probabyl I won’t be able to change something there. I now tried various binary options and I could get some more structures filled, but you were also right that the quality is suffering - I will try to figure out, whether this is acceptablke for the evaluation.

@petebankhead Thank you so much for the macro! Indeed, my first picture isn’t the original (linked that one below) but it is already being processed via color deconvolution. The pictures I will obtain will be from a microscope, so maybe there could be another way to change something there to get a better result…

Thanks @Charlie - I think this might be a job for Trainable Weka Segmentation, perhaps looking for the main tissue, brown staining and internal part of the capillaries as three separate classes.

The information that is removed by color deconvolution is really informative in distinguishing the false positives, and the hazy blue/gray around tissue could come in useful. Working on the single color-deconvolved channel probably makes things harder than they need to be (even if they are still not too easy…).

1 Like


could you please provide an original raw RGB-image in either TIF- or PNG-format.
(If the forum mechanism automatically converts during upload to JPG-format, then please post a typical excerpt of an original raw RGB-image.)

The image you’ve posted in your latest post is an indexed 8-bit color image.



@petebankhead Thanks so much for this hint! I’ll go and have a try!

@anon96376101 When I tried to upload my original picture in TIF-Format, but the upload somehow doesn’t work - I don’t know whether the file is too big or what the actual problem is.
I got it now as a PNG-file, does this work better?

Is this really the raw image from the microscope camera without any preprocessing?

It is clearly over-exposed.



@anon96376101 I will talk to my colleague,who took the pictures of the samples, whether this really is the original (probably not) and keep you updated!

I’m not a microscopist, but I work mostly with brightfield histology data nowadays and the image looks pretty normal in comparison to the examples I’ve seen from various labs over the years.

It does look like it has been drawn over with a paint tool in quite a few places though… that could be more problematic. I guess there is a ‘more original’ version somewhere :slight_smile:

@petebankhead - you’re right :grinning: this was one of our first experiments to manually seperate different structures so the program detects more precisely. I will try to get the original as soon as possible!

[…] the image looks pretty normal […]

It does look like it has been drawn over with a paint tool in quite a few places though […]

I’m no histologist but do you think this is “pretty normal”?

Totally confused about scientific terms these days


No, just wanted to challenge ‘clearly over-exposed’ :slight_smile:

I’d be happy to know if there’s evidence for that or if it’s possible to acquire better images of this kind though, in terms of facilitating either quantification or image analysis. I haven’t seen resources discussing this in the way that there are for fluorescence microscopy images.


@petebankhead @Charlie
Hey people! Did you manage to figure this one out? I am having a similar problem with my analysis. :slight_smile: