Determine average width of irregular line

Hey there!

I have two (newbie) questions about ImageJ and analysis/math in general (if this is the right place to ask).
For analysis of some of my data I need to obtain the average width of lines of my extruded material. Now I could just measure the width at several points and take the average, but I was wondering if it is possible to select the whole area and then calculate the average width of the entire line. I have tried changing the brightness and threshold to be able to automatically select the whole line but parts of the line keep getting lost by adjusting the settings (see images).

Then when I have the surface area, I wondered if I can just divide it by the length of the line to obtain the average wirdt, or if a more complicated formula is required for this kind of calculations.

Thanks in advance!

ImageJ sample

Hi @Joost

Check out these other Forum posts that show how to get these same measures:

Read through those - test a few things out - and if you have more questions - just let us know! We are here to help. :slight_smile:


Too - Make sure that in your binarized image - you are selecting your object as opposed to background (so either inverting your binary image or when thresholding making sure “Dark Background” is checked).

1 Like

Good day Joost,

could you please provide the first image with a drawn line that indicates how you define the width at a certain position of your object.

Presently, it is unclear how you would orientate such a line with respect to your object.

Could a length axis be constructed for the object so that the width is measured orthogonal to this axis?

Please provide more details.



Please provide the original first image in TIF- or PNG-format because JPG introduces artifacts!
(Converting a JPG-compressed image to TIFF- or PNG-format doesn’t make sense.)

@etadobson Thanks for those links, I will read them through!

@anon96376101 This was more of a quick test run, exported the images as JPG because those settings were already selected, not thinking about possible artifacts so thats a good reminder! (The second one is PNG as I just used snipping tool to get a quick snap.)

Below is how I figured the axis should be constructed and my initial idea before thinking of the total surface was to take several points on the axis and measure the width orthogonally to it.
But I am going to re-run the experiment next week anyway, also using two different microscopes. Ill read through the links posted before, and post some TIF figures, hopefully clearifying everything a bit!

Thanks for the help!

Good day Joost,

thanks for your explanations that leave me with more questions.

  1. Is this line hand-drawn or do you have a mathematical rule for drawing it? If you like to see the width computations done automatically, we need a mathematical formulation of how to find this line.

  2. Please post this image without the yellow line as original raw image in PNG- or TIF-format, otherwise we can’t do any reasonable analyses.




would this

be an acceptably oriented image version?

It was obatined according to a formal criterion.



Forgive my ignorance but I’m not that used to ImageJ, or mathmatical analysis just yet. This is just hand-drawn line, but what are those formal criterions that you mentioned?
I have no PNG- TIF-format of these images as I wasn’t expecting too much of this experiment (and the amount of help you put into this, thanks for that). I’ll upload some right images next week.

The orientation as you put is would definately be acceptible. I assume this is a step that you have to do manually for all different images that you have, or is there a way to automate this too?

The orientation as you put is would definately be acceptible. I assume this is a step that you have to do manually for all different images that you have, or is there a way to automate this too?

That is what I asked for.
Please try to imagine how to automatically do a correct orientation?

Computers need a mathematical description of what is the correct or an acceptably correct orientation. This mathematical description is a formal criterion.

For my attempt I used such a formal criterion and if you are happy with the result, we are one step further with your problem.

If you were doing the orientation by hand your later width measurements would become irreproducible.


If you are doing further experiments, could you please try to enhance the contrast between the object in question and the background?
Making the background lighter and keeping the object as it presently is, would help with image analysis.




here is a first result from your sample image:




@anon96376101, wow thats exactly what I am looking for! Are you using specific plugins to do this? I am currently reading up on the MorphoLibJ plugin that was mentioned earlier, and I will also try to find out how you did this because at the moment I am clueless.
Furthermore, I will try and using phase-contrast microscopy, that might enhance the object compared to the background.

Also, I do understand now what is defined as a formal criterion, but I can not think of a mathematical way of getting the orientation automatically correct.


let’s start with the automatic correction of the object. My approach tries to remove the background first by using this macro function (EDIT: revised):

function estimateBackground( hh ) {
	makeRectangle( 0, 0, getWidth(), hh );
	mi_1 = List.getValue( "Min" );
	md_1 = List.getValue( "Median" );
	makeRectangle( 0, getHeight()-hh, getWidth(), hh );
	mi_2 = List.getValue( "Min" );
	md_2 = List.getValue( "Median" );
	run( "Select None" );
	if ( mi_1 > mi_2 ) mi = mi_1; else mi = mi_2;
	if ( md_1 > md_2 ) md = md_2; else md = md_1;
	return round( ( mi + md ) * 0.5 );

Presently I use hh = 16 pixel, i.e. I measure the minimum and mean gray level in stripes at the top and bottom of the image that are 16 pixel high.

With the returned estimate b for the background and

changeValues( b, 255, 255 );

I get the following result image from your sample image:

which isn’t a binary image by intention.

The orientation process is based on finding the absolute minimum in the horizontal projection of the result image depending on the rotation angle. This is done with an accuracy of 0.2 degrees by using the Golden-section search with interval ±45 degrees (which takes 10 interations in case of the above result image).
EDIT: addition
The ImageJ-plugin “golden_orientation.class” that does this, is available from here:

This now oriented result image is used for contour tracing, because its contours are partly broken and there are still some background signals that make direct measurements at least difficult.

The contour tracing algorithm is described in this thread:
Mark describes a method and gives a reference:

For the result in my previous post I used a disc of 10 pixel diameter.

I’m not aware of any ImageJ-plugin that does this.



Hey Herbie,

I have been trying to reproduce the result that you gave me as an example.
Up onto the rotation part is now clear to me, giving me the result below:

After this, I use MorphoLibJ>morphological filters for the contour tracing, resulting in the following view:

I can even remove the remaining background by using MorphoLibJ > Fill Holes (Binary/Gray) But I am not sure if you should do that.
I then tried to use MorphoLibJ > binary images > Geodesic Distance map, first creating a skeleton and then use a binary version of the source image as mask. Aside from that it looks completely different from the result you posted, I get the error message “Line or rectangular selection required” when trying to plot the profile.

Given that the heatmap itself is different from the contour lining that you have posted before, as it does not run the entire x-axis of the image, I wonder if I’m even using the right method to analyze the width.

I’ve seen u using the yellow outlining of lines/cell surfaces in other topics too, but I dont understand how to get them.

Thanks again for the help,

Good day Joost,

if you use fundamentally different methods (MorphoLibJ versus my Contour Tracing) you will most likely get different results.

Presently, my approach to contour tracing is commercially available only.
(If you are interested, you can contact me off-Forum by sending a personal message from the Forum. You may either buy the corresponding plugin or let me process your images.)

Other options are:

  1. You code the necessary macro or plugin yourself.
  2. You use a different approach. Your posted image “sample4.png” may serve as a starting point.

In any case, you should be aware of the fact that both contours, the upper and the lower one, must consist of the same number of points that equal the width of the image. Otherwise it will be difficult to determine the thickness of the object in question.

That said, there is a certain problem involved with concave parts of the contours:
If they are perfectly traced, you willl get different contour positions having the same x-coordinate, i.e. you will get more contour points than the width of the object and the desired thickness measurements become at least problematic.

I see two solutions:

  1. The tracing cuts through the overhanging contour.
  2. The tracing jumps from the overhanging contour.

Both lead to different thickness measures and one has to decide which solution is adequate with respect to the project’s goal.



Object thickness:

“Black pixel column count” is a reference method that is applicable to filled binary objects only.