Gianluca
Gianluca

Reputation: 5

ImageJ Macro: setOption("Changes",false); not preventing 'Save Changes' prompt

I'm working on an ImageJ macro that iterates through a list of images, applies transformations, and saves the transformed images. To avoid unnecessary 'Save Changes' prompts, I've included the line setOption("Changes", false); within the loop to reset the 'changes' flag of the original (unprocessed) image.

However, despite using this line, I am still prompted to save changes for each image in the loop. I would appreciate any thoughts about why this is happening and how I can resolve it.

Minimal working example (edited):

macro "Minimal working example demonstrating the 'Save Changes' prompt issue" {

// Create a new folder for Target images
    NewFolder = "C:\\Path\\Of\\Choice" + File.separator + "Target_Images" + File.separator;
    File.makeDirectory(NewFolder);

// Create three new images
    newImage("Reference.tif", "8-bit Black", 256, 256, 1);
    Reference_Image = getTitle();
    newImage("Target1.tif", "8-bit Black", 256, 256, 1);
    Target_Image = getTitle();
    saveAs("tiff", NewFolder+Target_Image);
    newImage("Target2.tif", "8-bit Black", 256, 256, 1);
    Target_Image2 = getTitle();
    saveAs("tiff", NewFolder+Target_Image2);
    files = getFileList(NewFolder);
  
// Select points on the Reference image
    var xpoints = newArray(50, 97, 139, 201);
    var ypoints = newArray(41, 104, 151, 187);
    selectWindow(Reference_Image)
    makeSelection("point", xpoints, ypoints);

// Select corresponding points on the Target image and add them to ROI
    selectWindow(Target_Image)
    makeSelection("point", xpoints, ypoints);
    run("ROI Manager...");
    roiManager("Add");

// Create a new folder for Registered images
    NewFolder2 = "C:\\Path\\Of\\Choice" + File.separator + "Registered_Images" + File.separator;
    File.makeDirectory(NewFolder2);

// Iterate through the list of Target images
  for (i = 0; i < files.length; i++) {
    open(NewFolder + files[i]);
    Target_Image = getTitle();
    
    // Select the previously added ROI
    roiManager("Select", 0);
    setOption("Changes",false); // resets the 'changes' flag of the current image
    
    // Use the `Transform -> Landmark Correspondence` plugin
    run("Landmark Correspondences", "source_image=Target_Image template_image=Reference_Image transformation_method=[Least Squares] alpha=1 mesh_resolution=32 transformation_class=Affine");
  
    // Save the transformed image in the "Registered_Images" folder
    title = getTitle();
    saveAs("tiff", NewFolder2+title);
  }
  
// Close all opened images and the ROI manager
  while (nImages>0) { 
    selectImage(nImages);
    close(); 
  }
  close("ROI Manager");
}

Additional information: ImageJ version: 1.54f; Operating System: Windows 10

Expected outcome: I expect that using setOption("Changes", false); should prevent the 'Save Changes' prompt for each unprocessed image in the loop.

Actual outcome: Despite including the line, I am still prompted to save changes for each unprocessed image.

Attempts to solve the issue: I have tried including the setOption("Changes", false); line outside the loop as well, but still it doesn't prevent the 'Save Changes' prompt.

Thank you for your help!

Upvotes: 0

Views: 191

Answers (0)

Related Questions