please try the macro with the sample image, the OP has posted!
Paste the macro code to an empty macro window (Plugins >> New >> Macro) and run it with the sample image open in ImageJ.
Make sure you’ve copied the whole macro code. It ends with “exit();”
And please never ever use JPG-compressed image for scientific work because JPG introduces artifacts that can’t be removed!
Please report if you still encounter problems with the macro when applied to the OP’s sample image.
Applying the macro to other images may indeed not work and you should post typical images of the kind you like to process, so that we can have a look at them and perhaps adapt the processing.