Problems regarding spot analysis on salmon - Shadows between fish scales being counted as spots




I’m analysing spot density on Atlantic salmon, but I have problems getting ImageJ to count the smallest spots. In stead of actually count the small spots, the Macro I utilise can’t distinguish small spots from shadows between fish scales. The problem seems to be the Macro itself: After converting the images to grey tone images, it seems like the contrast between the black spots and grey shadows is too low, making the “analyse particles”-part of the Macro wrong. How can I make ImageJ to distinguish between black and white “more effectively”?

This is the Macro:

macro “SetScale [1]”{
run(“Set Scale…”, “known=228.1 unit=mm”); }

macro “MakeRectangle [2]”{

makeRectangle(1900, 1600, 1600, 400);


macro “Crop [3]” {



macro “SaveAsTIF [4]” {



macro “MeasureSpots [5]” {
//convert to greytone image
run(“Remove Outliers…”, “radius=50 threshold=50 which=Bright”); //remove bright reflexes

run(“Auto Local Threshold”, “method=Sauvola radius=100 parameter_1=0.7 parameter_2=128 white”);
//local thresholding

//connect particles that are very close
run(“Options…”, “iterations=1 count=1 do=Erode”);
//remove very small particles (noise) and shrinks larger particles run(“Options…”, “iterations=3 count=1 do=Dilate”);
//Make particles grow
//Spots that are connected will be separated
run(“Set Measurements…”, “area centroid perimeter shape feret’s area_fraction display redirect=None decimal=2”);
//Sets measurements types
run(“Analyze Particles…”, “size=2-Infinity show=Overlay display exclude include add”);
//Runs particle anlysis
//Reverts thresholdes image to saved original

macro “RotateCW [6]”{
run("Rotate… ", “angle=2 grid=1 interpolation=Bilinear”); }

macro “RotateCCW [7]”{
run("Rotate… ", “angle=-2 grid=1 interpolation=Bilinear”); }

macro “Save ROI«s [8]” {


macro “Reset ROI«s [9]” {



Kind regards,


Good day David,

without typical raw images in the original TIF- or PNG-format we can’t help.

No JPG-format for the images though, 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.)




Ups! Sorry, here’s an example:

ROI is from the gill cover and to the dorsal fin, and the lateral line is in the middle. The width of the ROI is just an inch above and below the lateral line.

Original TIFF image: download

Kind regards,


Thanks David,

this is really a tough task!

I would first try to optimize image acquisition, especially the lighting.
Try with highly diffuse illumination to avoid the specular reflections.
You may also try colored light to enhance the contrast.

At the moment I don’t have an idea for a reasonable processing scheme.




Aah, okey. Should I just try to change the lighting in Photoshop/Lightroom? I’m fairly new with ImageJ.

Kind regards,


change the lighting in Photoshop/Lightroom?

No, when taking the photographs!
Post hoc it doesn’t make sense.

BTW, don’t use any processing in Photoshop/Lightroom if you want to do quantitative image analysis, except you know exactly how these appplications are set-up. All you need for image processing and anaylsis can be done with ImageJ, provided the images were suitably acquired!




Aah, okey. Then I’m fairly screwed.

Thanks anyway!

Kind regards,