Hi, to me seems that your problem in the macro is that you somehow call "Analyze Particles..." having a ROI selected yet, so the coordinates XM and YM are relative to that selection.
Try by yourself to be sure about it: without using your macro, simply select a ROI in a picture, call "Analyze
Particles..." and check the coordinates with the pointer.
After this, duplicate the original part of the picture and you will see that the (XM,YM) are correct respect that subregion.
So when in your macro you call "Analyze particles...", be sure to deselect any eventual ROI.
Best regards,
Rocco
Senior Microscopist
Crick Advanced Light Microscopy facility (CALM)
The Francis Crick Institute
1 Midland Road, NW1 1AT, London (UK)
https://roccodant.github.io/