/* A macro to copy the image scale from one open image to one or more other open images Features: If only one scaled and one unscaled images it automatically transfers the scale to the unscaled image Scale can be copied to more than one image Images with scales are listed separately and if there is only one it is automatically selected as the source (but are not selected as targets) Images with no scale are listed as primary target choices and are automatically selected Peter J. Lee Applied Superconductivity Center, NHMFL, Florida State University v200922: 1st working version v210804-5: Modified to handle large numbers of images. v210809: Fixed error on line 88 Updated functions: 5/16/2022 3:43 PM v220610: pixel width values of 1 are assumed to be unscaled. Minor cosmetic fixes. v220614 Allowed more images (based on screen height). v220715: Batchmode now working (much faster). Better dialog for larger numbers of open images. v220725 Now correctly lists source image IDs v221213: Apparently does need some delay to register each image. v230103-4b: Added a diagnostic option to show the progress of scale application by flashing the images and also removed some redundant code. v230822: Corrected selectedImage to selectedWindow */ macro "Copy Image Scale" { /* Note that the version used in the startup macro has shortcut key in name */ macroL = "Copy_Image_Scale_v230822.ijm"; requires("1.53i"); /* for flashing images */ imgC = nImages; if (imgC==0) exit("No images open."); imgTitles = getList("image.titles"); imgSTitle = getTitle(); /* for default source image */ imgPxWs = newArray(imgC); imgPxHs = newArray(imgC); imgPxDs = newArray(imgC); imgUs = newArray(imgC); screenH = screenHeight; screenW = screenWidth; maxImgs = round(screenH/40); iSourceImgs = newArray(); /* Images that have a scale so can be sources */ iNoScaleImgs = newArray(); /* Images that have no scale so they cannot be sources */ if (imgC<6){ showProg = true; setBatchMode(true); /* Only to the 1st Dialog */ } else showProg = false; showTime = 2000/imgC; iDefSImg = -1; for (i=0,imgScaleC=0,noImgScaleC=0; imaxImgs){ setBatchMode("exit and display"); Dialog.create(macroL + ": Apply current scale to all other open images"); Dialog.addMessage(imgC + " images open, the current menu is limited to " + maxImgs); imgWidthU = getWidth() * imgPxWs[imgIDCi]; Dialog.addMessage("Current image title: " + imgTitles[iDefSImg] + ", width: " + imgWidthU + " " + imgUs[iDefSImg] + "\nCurrent image pixel width: " + imgPxWs[iDefSImg] + " " + imgUs[iDefSImg] + "\nCurrent image pixel height: " + imgPxHs[iDefSImg] + " " + imgUs[iDefSImg]); Dialog.addCheckbox("Copy scale from current image to all other open images?",true); if (imgScaleC>1) Dialog.addCheckbox("Overwrite existing scales?",false); Dialog.addCheckbox("Show progress \(slows things down a bit\)",showProg); Dialog.show(); copyToAll = Dialog.getCheckbox(); showProg = Dialog.getCheckbox(); if (!copyToAll) exit("Goodbye"); if (imgScaleC>1) copyToAllOv = Dialog.getCheckbox(); for (i=0; imaxString) maxString = stringL; if (i0){ imgNSInfo = ""; Dialog.addMessage("Target image\(s\) without scale:"); if (noImgScaleC>1) Dialog.addCheckbox("Select all " + noImgScaleC + " images without scale \(overrides selections below\)", false); targetNSCheckBoxGroup = newArray(); imgNSInfoLine = ""; imgNSInfo = ""; for (i=0,maxString=0; imaxString) maxString = stringL; if (i1){ Dialog.addMessage("Target image\(s\) that already have a scale:_______________"); Dialog.addCheckbox("Select all " + imgScaleC + " images with scale \(overrides selections below\)", false); targetISCheckBoxGroup = newArray(); for (i=0; i0){ if (noImgScaleC>1) targetAllNSImgs = Dialog.getCheckbox(); else targetAllNSImgs = false; for (i=0; i1){ targetAllSImgs = Dialog.getCheckbox(); for (i=0; i