/* Copy or append metadata from one open image to another v220630: 1st version PJL v230822: selectImage corrected to selectWindow. */ macro "Copy metadata from one open image to another" { if(nImages<2) exit("Only " + nImages + " images open; this macro needs at least 2"); macroL = "Copy_metadata_from_one_image_to_another_v230822.ijm"; Dialog.create(macroL + " options"); Dialog.addMessage("File must be saved uncompressed by ImageJ to retain metadata"); Dialog.addMessage("Currently the Append/Insert/Replace option has not impact ¯\_(ツ)_/¯ "); Dialog.addImageChoice("Source image"); Dialog.addImageChoice("Destination image"); Dialog.addRadioButtonGroup("Modification:",newArray("Replace","Insert","Append"),3,1,"Append"); Dialog.addRadioButtonGroup("Data type",newArray("Info","Label"),2,1,"Info"); Dialog.addCheckbox("Copy non-unity image scale if destination scale is unity",true); Dialog.show(); sourceImage = Dialog.getImageChoice(); destImage = Dialog.getImageChoice(); modType = Dialog.getRadioButton(); dataType = Dialog.getRadioButton(); copyScale = Dialog.getCheckbox(); if(sourceImage==destImage) exit("Same images selected"); selectWindow(sourceImage); List.setList(getMetadata(dataType)); List.toArrays(skeys, svalues); getVoxelSize(sPxW, sPxH, sPxD, sU); if (sPxW==1 && sPxH==1) copyScale = false; selectWindow(destImage); List.clear(); List.setList(getMetadata(dataType)); List.toArrays(dkeys, dvalues); List.clear(); getVoxelSize(dPxW, dPxH, dPxD, dU); if (dPxW!=1 && dPxH!=1) copyScale = false; if (copyScale) setVoxelSize(sPxW, sPxH, sPxD, sU); if (sPxW==1 && sPxH==1) copyScale = false; if (modType=="Append"){ skeys = Array.concat(dkeys,skeys); svalues = Array.concat(dvalues,svalues); } else if (modType=="Insert"){ skeys = Array.concat(skeys,dkeys); svalues = Array.concat(svalues,dvalues); } List.fromArrays(skeys, svalues); setMetadata(dataType,List.getList()); }