"Magically" aligned ROIs after scaling

Hi all,

I’m trying to rescale my images along with the ROI file attached to each file. so far so good, and it was working up to a point, then mysteriously started to align the new updates ROIs in the top left hand corner of the image. Bizarre, since every trial run I did (using the same code) while building the rest of my analysis code had ROIs positioned fine!

I’m not sure what I’m missing to make sure the positions of the ROIs stay to same relative to the new scaled image. My code is simple, so I can’t be adding anything to it…:

       run("Scale...", "x=0.25 y=0.25 width=1020 height=768 interpolation=Bilinear create");
            //loading ROIs here 
// Iterate all ROIs in ROI Manager
for (j=0; j<roiManager("count"); ++j) {
	roiManager("Select", j);
	// Scale ROI
	run("Scale... ", "x=0.25 y=0.25");
	// Replace old ROI with scaled one

Can anyone help?

I seem to make a habit of answering my own questions on here… the issue seems to have resolved itself. I switched the order so that the ROI file is opened on the original image before it’s scaled down.

I noticed that when I scale the image, then try to open the ROI .zip for the original size, the ROIs become centred (perhaps that’s a default if the ROI cannot exist within the bounds of the canvas?), so when the ROIs are subsequently scaled, they are incorrectly aligned.

For my purposes, this is resolved, but it all still looks like magic to me, so if anyone can explain, I’d be happy to listen and learn!

Best wishes,