I expose films in a jig with pin pricks as reference markers. I use these references to register the scanned images of the film to other data.

I've been using mouse click coordinates to date, but I need to automate it and can't find a robust way to detect the pin pricks using binary image processing. I've tried various approaches using opencv with python (see below).

I don't use dust removal when scanning, that might be the issue, but it must be possible to distinguish the round pinpricks from dust no?

Does anyone have advice on suitable methods for detecting features like these pin pricks?

Thank you.

enter image description here

Here's an example image which I want to process. There are 10 pin pricks and 1 dark area of exposure. I just want the coordinates of the pinpricks.

enter image description here

An example attempt of binary thresholding followed by erosion and dilation. It doesn't robustly remove noise instead of the features regardless of parameters.

enter image description here

An attempt at finding contours which still misses pinpricks and picks up noise.

enter image description here

An attempt at using a Hough Transform with a similar result

**** EDIT ****

My attempts at template matching using an example pinprick

enter image description here

This picks out all the pins with a threshold of 0.5. This works well as the template pinprick was taken from this image.

enter image description here

This is run on a different image to the template and struggles. At the same threshold.

enter image description here

The above match when run with a lower threshold. It picks out dust instead of pins.

  • 1
    $\begingroup$ Welcome to DSP.SE! Matched filtering might be an appropriate approach, as the pin pricks appear to be fairly consistent in size. Essentially take a pattern of what a pin prick looks like and convolve it with the image before thresholding the result. $\endgroup$
    – Ash
    Jul 12, 2023 at 17:48
  • 2
    $\begingroup$ Crop out one of the pin pricks from one of the images and use it as a template. Post a picture of what correlating the template with a couple of example images looks like. $\endgroup$ Jul 12, 2023 at 21:19
  • 1
    $\begingroup$ JPEG compression artifacts hit the original that you posted here pretty heavily. Are you working on the heavily compressed data or on less distorted imagery? $\endgroup$ Jul 13, 2023 at 9:31
  • $\begingroup$ @Ash Thanks for the welcome! I used Open CV's matchTemplate is that the same in principle to matched filtering? I've provided examples of my efforts. Essentially, it works if the template is taken from the image, but doesn't generalise. $\endgroup$
    – Tom W
    Jul 15, 2023 at 19:55
  • $\begingroup$ @AnonSubmitter85 Thanks for the reply. I've tried this and shown examples. It doesn't seem to generalise as the pin pricks vary too much between images. $\endgroup$
    – Tom W
    Jul 15, 2023 at 19:56

1 Answer 1


I don't know what I'm doing, but tried anyway, learned a lot and it's up to you if useful. Anyway using Gmic curvature filter, difference of Gaussians and ImageMagick to apply skeleton thinning and line junctions reduction I was able to select the pin pricks and although the coordinates aren't truly accurate, are close.


gmic b.png fx_curvature 2,0,100,1,0,0,50,50 \
fx_dog 1.4,1.5,49,0,1,0,50.38,52.02 \
fx_skeleton 1,0,0,50,50 -o output.png

convert output.png -colorspace RGB -morphology HMT LineJunctions \
-morphology Dilate Square \
-define connected-components:mean-color=true \
-define connected-components:exclude-header=true \
-define connected-components:verbose=true \
-connected-components 4 output.png | awk 'NR>1' \ 
| grep -Po '\d+:\s'\|'\s\d+.\d+,\d+.\d+' \
| paste -d " " - -

Output after parsing:

5:   228.0,381.5 
7:   393.5,683.5 
10:   1068.5,773.5 
2:   933.0,189.0 
3:   788.4,265.4 
8:   1212.6,696.4 
9:   249.6,762.4 
1:   832.0,179.5 
4:   126.5,370.0 
6:   84.0,463.5 

pinpricks selected curvature filter difference of gaussians pinpricks points

  • $\begingroup$ Thanks for this and sorry for the late reply. Your method works better than anything I came up with, but unfortunately I still can't get it to generalise well enough to the variation in images I have and expect to have. I think I was too ambitious, so I'm finding another solution. Thanks! $\endgroup$
    – Tom W
    Aug 3, 2023 at 11:30

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.