Automatic length measurement of metal parts

Hi Herbie, we use telecentric lenses on high accuracy measurement devices (like our hexagon optiv)

In this case indeed we do not need it, as we can illuminate from one side, so the reflected light from the deeper part is offset from the reflection of the higher part of the object

Also the total image of the blister is 160x240 mm (5x15 parts)( quite a big telecentric lens when we want to capture the blister (actually only half of the complete blister which is 10x15 parts) with one 6000x4000 image

the idea with the illumination from the side, was to create a ‘line reflection’ on the left side of the part, as this makes it easier to measure

Now we can improve this: if we make a smaller line reflection on both the left and the right side of the part, each part we can do 2 length measurements, and if the lip would be just positioned in the line reflection on one side, the system can decide to take the measurement on the other side and judge the part right or wrong

Regarding ‘deformed’ views because of non-telecentric lens use, the idea is also to put reference pieces in some places in the blister, that allow calibration of the measurement between the center of the image and the sides of the image

Next week back in the office, will make some pictures with smaller line reflection, left and right, black background, blister aligned

Thanks for all the input! J



as I’ve written: No need for changes of your image recording setup.
(Especially and as explained before, I see no need for telecentric optics. BTW, a field lens is the more economic approach in case of large image circles.)

Regarding ‘deformed’ views because of non-telecentric lens use, the idea is also to put reference pieces in some places in the blister, that allow calibration of the measurement between the center of the image and the sides of the image

No need for reference pieces!

The results I get from your posted blister image (although it’s only an 3x6-excerpt from the whole 5*15-parts) are more than satisfying.

What would be helpful is an image of the whole blister.
Furthermore a whole blister with one or some defective parts would be of interest.



thanks, ok, will send you an image from the complete 5x15 parts, just better aligned

(will make a new picture with some wrong parts in it also)


please be so kind and thoroughly read the posts of this thread!

Angular alignment isn’t a big affair and can be obtained with a few lines of ImageJ macro code.

My approach actually performs automatic angular alignment. Consequently, there is no need to perfectly align the blister. A range of allowed angular misalignment should be known though. Presently I assume a range of ±5 degrees.




Now we can improve this: if we make a smaller line reflection on both the left and the right side of the part

Presently and as decided earlier, I fall back to the median length of the parts if a “Lip”-situation is detected.
If you can accomplish two distinct reflection-lines, one could re-measure using the other reflection-line if a “Lip”-situation is detected.
(Presently, I re-measure only if a “Reflex”-situation is detected.)

The new sample images should be in the original raw camera format, preferably TIF or PNG but not JPG because JPG introduces artifacts! You may also post images as Zip-archives.
(Converting a JPG-compressed image to TIFF- or PNG-format doesn’t make sense.).

for next week, I could give out raw, but this is nikon NEF format, so needs a separate conversion step
high quality jpeg (what I sent before was medium quality) probably does the job more than enough for what we want to achieve

No hurry Paul!

I could give out raw, but this is nikon NEF format

Please try to directly convert the images in NEF-format to the TIF-format.
The free Nikon Software “Capture NX-D” does the conversion NEF -> TIF:

  1. Select (click) the image in the preview section
  2. Click “Convert” on the tool-bar
  3. In the now opening dialog choose “Format: TIFF (16bit)”
  4. Choose a destination folder and click “Start”

When you open the converted image in ImageJ, the image will open as a stack consisting of three (RGB) 16bit slices.
In the ImageJ-menu go to “Image >> Stacks >> Z Project…” and set “Projection type: Average Intensity”.
Save the resulting gray-value image and post it here in a ZIP-archive.

On a Mac the Preview-Application can open images in NEF-format and from there you can export them as 16bit TIF-files without compression.
The same holds for Photoshop.
(ImageJ/Fiji-Bioformats doesn’t open images in NEF-format correctly!)

Please no “high quality jpeg”-compressed images!

If all fails, please post the images in NEF-format in a ZIP-archive.



thanks Herbie, from the airport now
I do use captureNX-D, but I also believe we must not make things more complicated than needed :slight_smile: especially regarding the workflow

the 16 bit tiff file is 141 Mb, on a normal processing day, once every week, we process over 200 half blisters, so this would give around 280Gb of data to process in ImageJ
do we need this to get the required accuracy for this project? (when we probably get +/- the same result with 9Mb pictures in medium Jpeg)

I’ll make a tiff file and a high quality JPEG, and we can compare the results of both, and I’ll also make diferent one with 2 small line illuminations, just for comparison

work to do! :slight_smile: and really thanks for the usefull input

1 Like

I’m just imagining easy workflow:
all pictures in JPEG in one directory, just copied from the camera, no conversion needed
batch processing all pictures, processed with green/red lines with data printed on each object, pictures that are all green saved in directory ‘OK’, if one red object, picture safed in directory ‘FAILED’, then just need to open the pictures in directory ‘failed’ and find the bad object…
(just a rough workflow, must be refined of course, with ocr from number on blister into name of new picture file etc)

1 Like


let’s start with best quality and please keep in mind that the idea is to work with gray-value images which means reduced file size.

I guess the data can be further reduced by trying 8bit gray-value images and reduced spatial resolution. However, the latter depends on the desire accuracy of the measurements.

Finally I would prefer images that are not over-exposed. The clipping effect that presently serves the final measurements should be produced by ImageJ not during image capture (camera).



Paul ,

did you look at the provided result image?



yes I saw it, really nice result, but I think when you see the complete 5x15 image, the processing must be made more ‘robust’
i mean: there are often quite inclined parts, (smaller problem), the scale in the center of the field can be up to .5% different from the scale at the side of the field (according to the lens data, must be checked) (hence the idea to use reference parts in the centre and the outer side of the field, to correct for different scaling factors over the complete area of the picture)
also processing so much pictures at the end must be without manual check of each ‘good’ picture
from what I learned from you till now, I am fully convinced this can be reached!


you know that 0.5% means 2.5 pixels length difference …

Again, what about precision?
Which minimum length difference characterizes a defective object?

also processing so much pictures at the end must be without manual check of each ‘good’ picture

Not sure I understand you here.
If there is no defect, you need not receive a message.



object length is around 20mm, tolerance +/- 0.15mm so 0.75% or around 4 pixels
so the 2.5 pixels extra can be important
I know for this we should need more detail/pixels per object length, but this goes beyond the goal of this last final quick check


I have no idea how you think you can cope with the variation of lengths of good objects by providing reference objects. Where do you think these reference objects should be placed?

In the end things get much more involved …

Good luck


Herbie, by calibrating the complete field of the image, the ok/fail will be more correct

Example: center of the field 20mm = 500 pixels, far corner 20mm= 503 pixels (just example)

Imagine the perfect part is 20mm +/- 0.15, so pass criteria for object in center of image is 496<->504 pixels, on the extreme edge of the image 499<->507 pixels



calibration will be the way to go and I misinterpreted the reference objects as being present with every blister.

Frankly speaking, I don’t like calibration because it has to be redone whenever the recording geometry changes, e.g. if someone kicks against the apparatus, slightly chnages the camera focus etc.

That’s also the reason why i prefer to individually align and segment every blister (and perhaps even every object). This is what I would call a robust approach … In respect of the scale variance of the imaging process I don’t have a convincing alternative solution yet.



1 Like

Herbie, ran a range of tests yesterday, no conclusion yet…

comparison raw/jpegH/jpegM/jpegL
straight from camera 30/12/8/4 Mb so data conversion from raw 30Mb to TIFF 16bit 140 Mb does not increase data robustness in the same order
compression in JPEG takes first place on areas with low luminance variance between adjacent pixels, nearly zero difference between raw and jpegH/M in area with high luminance difference between adjacent pixels
for same exposure, measuring parts length with jpegM, or converting raw->tiff 16bit always gives same result

overexposing or not makes a difference: higher overexposing usually makes the measurement 2 pixels longer (pixel on edge of overexposed pixel also becomes overexposed)

underexposing makes measuring less robust: often the edge is not detected, but a place more inwards into the object (makes the measurement Always a few pixels less)

illumination: one or 2 distinct lines, orientation of lights: no conclusion yet, but clearly some advantages by improving light

black or white background, both work, no conclusion yet what is best…

will send foto’s of complete blister when tests are more conclusive



things aren’t as easy as you describe them above …

I say this by assuming you used the macro code posted by me at the beginning of this thread:

8bit versus 16 bit:
The macro sets the images always to 8 bit. Consequently there can’t be any difference.
Don’t forget that the macro performs only the last step of the whole processing chain, i.e. 16 bit may turn out being advantageous for the pre-processing.

TIFF versus JPEG:
More or less the same as for gray value depth above plus impact on the pre-processing that is not yet inculded with my macro.
(For the time being forget about file sizes. Presently, it’s all about learning the various interdependencies.)

Please capture the images without overexposure.
My macro introduces an implicite threshold and it can be adjusted.
If you capture overexposed images, you loose this degree of freedom for optimization.
A big problem is the illumination gradient in your images, either produced by the illumination itself or by vignetting of the imaging optics.
Because a threshold presently seems indispensible, such gradient must be avoided or compensated. Presently, I do this in one of several pre-processing steps.
(Presently, the threshold is responsible for the different length measurements you are reporting.)

One or two illumination sources:
It appears worth trying two sources because the two dominant cases of false results could then be avoided without a priori assumptions.

A way to avoid calibration is to have precise markers of defined length on the blister package.

My overall impression from your last post is, that you didn’t fully understand my macro and that you tend to think too far ahead …



here a correctly exposed picture, set to 8 bit grey value

Good day Paul,

there are many nasty reflections from the blister mould that have about the same gray value as the object line reflections. No time to come up with a robust solution, although there are ways …

Have success