Saving multiple active windows that have been manipulated onscreen...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Saving multiple active windows that have been manipulated onscreen...

t-lg
Hello

I am sorry to trouble you with what is probably a very simple answer, but I am not a coder and am at my wits end trying to make some code work, that someone else wrote which I think may be cobbled together from other bits of code.

The code takes you through multiple steps to correct for a cameras non-linear response and to control for lighting conditions by calibrating to a grey standard in the image. All of the calculations themselves are fine but it is saving the images that is the problem. The code allows you to open up two raw files, which are then linearised and calibrated to a section of the grey standard you select in the active window - no problem there. But when it moves on to the saveas part I get the following undefined variable error in:
savepath = <saveDir> + "Reflectance_"+fileList[i];

From what I understand the fileList[i] command is used for batch processing, however in these images I need to manually select the grey standard so I don't think it is appropriate for this. In addition, I would like to save the calibrated images that are onscreen in the active window back to the directory from which I opened it with something like "Reflectance_" appended to the file name, in tif format. I would need to do this for both images.

After this is done, these two images are then aligned, which once complete will also need to be saved in the same directory with a new name concatenating the two file names i.e. "_aligned_with_"

Finally, I would like the menu to start all over again from the select file bit so that I can keep processing images in a semi-automated fashion. I would be very grateful for some assistance. I think the main problems are in //SAVE IMAGE as well as right at the end in //Naming.

To try and make this more straightforward I have deleted alot of the other macros that do work so the main code is here:
// SETTINGS

        infoPath = getDirectory("plugins")+"Linearisation/Cameras";

        infoList=getFileList(infoPath);
        infoNames = newArray(infoList.length);
                for(a=0; a<infoList.length; a++)
                infoNames[a] = replace(infoList[a], ".txt","");

        Dialog.create("Linearisation & Normalisation Settings");
                Dialog.addMessage("Linearisation settings:");
                Dialog.addChoice("Visible", infoNames, "Nikon D90 ISO400 Visible 16bit"); // change the last value here to change the default
                Dialog.addChoice("UV", infoNames, "Nikon D90 ISO400 UV 16bit");
                //Dialog.addCheckbox("Normalise Images", true);
                Dialog.addMessage("\nReflectance of visible spectrum grey standard:");
                Dialog.addNumber("Red %", 40);
                Dialog.addNumber("Green %", 40);
                Dialog.addNumber("Blue %", 40);
                Dialog.addMessage("\nReflectance of UV spectrum grey standard:");
                Dialog.addNumber("Red %", 40);
                Dialog.addNumber("Green %", 40);
                Dialog.addNumber("Blue %", 40);
                Dialog.addCheckbox("Grey standard in separate photo", false);
                //Dialog.addCheckbox("Single grey standard for image series", false);
                Dialog.addMessage("\nOptimising the dynamic range across visible and UV photos\nensures no data are lost due to overexposure. This effectively\nignores the overall brightness of the standard, instead using\nonly its colour for normalisation");
                Dialog.addCheckbox("Optimise dynamic range", true);
        Dialog.show();


        vChoice = Dialog.getChoice();
        uChoice = Dialog.getChoice();;
        visRedStandard = Dialog.getNumber();
        visGreenStandard = Dialog.getNumber();;
        visBlueStandard = Dialog.getNumber();;;
        uvRedStandard = Dialog.getNumber();;;;
        uvGreenStandard = Dialog.getNumber();;;;;
        uvBlueStandard = Dialog.getNumber();;;;;;
        //normaliseChoice = Dialog.getCheckbox();
        standardLocation = Dialog.getCheckbox();
        maximiseRange = Dialog.getCheckbox();;



// ALIGNMENT OPTIONS

        inputChannelsArray = newArray("Red","Green","Blue");
        outputChannelsArray = newArray("Visible Red","Visible Green","Visible Blue", "UV Red", "UV Green", "UV Blue", "DELETE");

        Dialog.create("Alignment Options");
                Dialog.addMessage("Select the channels to align");
                Dialog.addChoice("Visible Image", inputChannelsArray, "Blue");
                Dialog.addChoice("UV Image", inputChannelsArray, "Blue");
                Dialog.addMessage("\nSelect Channels to keep");
                Dialog.addChoice("Channel 1", outputChannelsArray, "Visible Red");
                Dialog.addChoice("Channel 2", outputChannelsArray, "Visible Green");
                Dialog.addChoice("Channel 3", outputChannelsArray, "Visible Blue");
                Dialog.addChoice("Channel 4", outputChannelsArray, "UV Blue");
                Dialog.addChoice("Channel 5", outputChannelsArray, "UV Red");
                Dialog.addChoice("Channel 6", outputChannelsArray, "DELETE");
        Dialog.show();

        inputSelection1 = Dialog.getChoice();
        inputSelection2 = Dialog.getChoice();;

        outputSelection = newArray(6);

        outputSelection[0] = Dialog.getChoice();;;
        outputSelection[1] = Dialog.getChoice();;;;
        outputSelection[2] = Dialog.getChoice();;;;;
        outputSelection[3] = Dialog.getChoice();;;;;;
        outputSelection[4] = Dialog.getChoice();;;;;;;
        outputSelection[5] = Dialog.getChoice();;;;;;;;


visRedChannelKeep = 0;
visGreenChannelKeep = 0;
visBlueChannelKeep = 0;
uvRedChannelKeep = 0;
uvGreenChannelKeep = 0;
uvBlueChannelKeep = 0;

for(i=0; i<6; i++){
        if(outputSelection[i] == "Visible Red")
                visRedChannelKeep = 1;
        if(outputSelection[i] == "Visible Green")
                visGreenChannelKeep = 1;
        if(outputSelection[i] == "Visible Blue")
                visBlueChannelKeep = 1;
        if(outputSelection[i] == "UV Red")
                uvRedChannelKeep = 1;
        if(outputSelection[i] == "UV Green")
                uvGreenChannelKeep = 1;
        if(outputSelection[i] == "UV Blue")
                uvBlueChannelKeep = 1;
}//i

//________________________________________________________________________________________

//SELECT IMAGE DIRECTORY

        visPath=File.openDialog("Select RAW visible photo"); // get file locations
        uvPath=File.openDialog("Select RAW UV photo"); // get file locations

        visWindowArray = split(visPath, "\\");
        visWindow = replace(visWindowArray[visWindowArray.length-1],".NEF", ".tiff");
        //print(visWindow);
        uvWindowArray = split(uvPath, "\\");
        uvWindow = replace(uvWindowArray[uvWindowArray.length-1],".NEF", ".tiff");

//SAVE IMAGE

                savePath = saveDir+"Reflectance_"+fileList[i];
                saveAs("Tiff", savePath);
        run("Close");

// Naming

       
        visName = replace(paths[0], ".tiff", "");
        uvName = replace(paths[1], ".tiff", "");


        rename(visName + "_aligned_with_" + uvName);

        savePathArray = split(paths[3], ".");
       
        savePath = savePathArray[0];

        savePath = savePath + "_aligned_with_" + uvName + ".tif";

        saveAs("TIFF", savePath);

        setBatchMode(false);

        print("\\Clear");

} //macro

// the end



With thanks for any assistance...



Reply | Threaded
Open this post in threaded view
|

Re: Saving multiple active windows that have been manipulated onscreen...

Jean-Philippe Grossier
Hi,

The problem in your macro is that you never set the saveDir. So the macro
can't find any directory.
Either add someting like:
saveDir= getDirectory("choose a save directory");
or if you want to save in the same folder of your input images, write:
saveDir=visPath; (or uvPath I don't know which one you like).

Hope this was helpfull

jean-philippe Grossier


2013/4/4 t-lg <[hidden email]>

> Hello
>
> I am sorry to trouble you with what is probably a very simple answer, but I
> am not a coder and am at my wits end trying to make some code work, that
> someone else wrote which I think may be cobbled together from other bits of
> code.
>
> The code takes you through multiple steps to correct for a cameras
> non-linear response and to control for lighting conditions by calibrating
> to
> a grey standard in the image. All of the calculations themselves are fine
> but it is saving the images that is the problem. The code allows you to
> open
> up two raw files, which are then linearised and calibrated to a section of
> the grey standard you select in the active window - no problem there. But
> when it moves on to the saveas part I get the following undefined variable
> error in:
> savepath = <saveDir> + "Reflectance_"+fileList[i];
>
> From what I understand the fileList[i] command is used for batch
> processing,
> however in these images I need to manually select the grey standard so I
> don't think it is appropriate for this. In addition, I would like to save
> the calibrated images that are onscreen in the active window back to the
> directory from which I opened it with something like "Reflectance_"
> appended
> to the file name, in tif format. I would need to do this for both images.
>
> After this is done, these two images are then aligned, which once complete
> will also need to be saved in the same directory with a new name
> concatenating the two file names i.e. "_aligned_with_"
>
> Finally, I would like the menu to start all over again from the select file
> bit so that I can keep processing images in a semi-automated fashion. I
> would be very grateful for some assistance. I think the main problems are
> in
> //SAVE IMAGE as well as right at the end in //Naming.
>
> To try and make this more straightforward I have deleted alot of the other
> macros that do work so the main code is here:
> // SETTINGS
>
>         infoPath = getDirectory("plugins")+"Linearisation/Cameras";
>
>         infoList=getFileList(infoPath);
>         infoNames = newArray(infoList.length);
>                 for(a=0; a<infoList.length; a++)
>                 infoNames[a] = replace(infoList[a], ".txt","");
>
>         Dialog.create("Linearisation & Normalisation Settings");
>                 Dialog.addMessage("Linearisation settings:");
>                 Dialog.addChoice("Visible", infoNames, "Nikon D90 ISO400
> Visible 16bit");
> // change the last value here to change the default
>                 Dialog.addChoice("UV", infoNames, "Nikon D90 ISO400 UV
> 16bit");
>                 //Dialog.addCheckbox("Normalise Images", true);
>                 Dialog.addMessage("\nReflectance of visible spectrum grey
> standard:");
>                 Dialog.addNumber("Red %", 40);
>                 Dialog.addNumber("Green %", 40);
>                 Dialog.addNumber("Blue %", 40);
>                 Dialog.addMessage("\nReflectance of UV spectrum grey
> standard:");
>                 Dialog.addNumber("Red %", 40);
>                 Dialog.addNumber("Green %", 40);
>                 Dialog.addNumber("Blue %", 40);
>                 Dialog.addCheckbox("Grey standard in separate photo",
> false);
>                 //Dialog.addCheckbox("Single grey standard for image
> series", false);
>                 Dialog.addMessage("\nOptimising the dynamic range across
> visible and UV
> photos\nensures no data are lost due to overexposure. This
> effectively\nignores the overall brightness of the standard, instead
> using\nonly its colour for normalisation");
>                 Dialog.addCheckbox("Optimise dynamic range", true);
>         Dialog.show();
>
>
>         vChoice = Dialog.getChoice();
>         uChoice = Dialog.getChoice();;
>         visRedStandard = Dialog.getNumber();
>         visGreenStandard = Dialog.getNumber();;
>         visBlueStandard = Dialog.getNumber();;;
>         uvRedStandard = Dialog.getNumber();;;;
>         uvGreenStandard = Dialog.getNumber();;;;;
>         uvBlueStandard = Dialog.getNumber();;;;;;
>         //normaliseChoice = Dialog.getCheckbox();
>         standardLocation = Dialog.getCheckbox();
>         maximiseRange = Dialog.getCheckbox();;
>
>
>
> // ALIGNMENT OPTIONS
>
>         inputChannelsArray = newArray("Red","Green","Blue");
>         outputChannelsArray = newArray("Visible Red","Visible
> Green","Visible
> Blue", "UV Red", "UV Green", "UV Blue", "DELETE");
>
>         Dialog.create("Alignment Options");
>                 Dialog.addMessage("Select the channels to align");
>                 Dialog.addChoice("Visible Image", inputChannelsArray,
> "Blue");
>                 Dialog.addChoice("UV Image", inputChannelsArray, "Blue");
>                 Dialog.addMessage("\nSelect Channels to keep");
>                 Dialog.addChoice("Channel 1", outputChannelsArray,
> "Visible Red");
>                 Dialog.addChoice("Channel 2", outputChannelsArray,
> "Visible Green");
>                 Dialog.addChoice("Channel 3", outputChannelsArray,
> "Visible Blue");
>                 Dialog.addChoice("Channel 4", outputChannelsArray, "UV
> Blue");
>                 Dialog.addChoice("Channel 5", outputChannelsArray, "UV
> Red");
>                 Dialog.addChoice("Channel 6", outputChannelsArray,
> "DELETE");
>         Dialog.show();
>
>         inputSelection1 = Dialog.getChoice();
>         inputSelection2 = Dialog.getChoice();;
>
>         outputSelection = newArray(6);
>
>         outputSelection[0] = Dialog.getChoice();;;
>         outputSelection[1] = Dialog.getChoice();;;;
>         outputSelection[2] = Dialog.getChoice();;;;;
>         outputSelection[3] = Dialog.getChoice();;;;;;
>         outputSelection[4] = Dialog.getChoice();;;;;;;
>         outputSelection[5] = Dialog.getChoice();;;;;;;;
>
>
> visRedChannelKeep = 0;
> visGreenChannelKeep = 0;
> visBlueChannelKeep = 0;
> uvRedChannelKeep = 0;
> uvGreenChannelKeep = 0;
> uvBlueChannelKeep = 0;
>
> for(i=0; i<6; i++){
>         if(outputSelection[i] == "Visible Red")
>                 visRedChannelKeep = 1;
>         if(outputSelection[i] == "Visible Green")
>                 visGreenChannelKeep = 1;
>         if(outputSelection[i] == "Visible Blue")
>                 visBlueChannelKeep = 1;
>         if(outputSelection[i] == "UV Red")
>                 uvRedChannelKeep = 1;
>         if(outputSelection[i] == "UV Green")
>                 uvGreenChannelKeep = 1;
>         if(outputSelection[i] == "UV Blue")
>                 uvBlueChannelKeep = 1;
> }//i
>
>
> //________________________________________________________________________________________
>
> //SELECT IMAGE DIRECTORY
>
>         visPath=File.openDialog("Select RAW visible photo");    // get
> file locations
>         uvPath=File.openDialog("Select RAW UV photo");  // get file
> locations
>
>         visWindowArray = split(visPath, "\\");
>         visWindow = replace(visWindowArray[visWindowArray.length-1],".NEF",
> ".tiff");
>         //print(visWindow);
>         uvWindowArray = split(uvPath, "\\");
>         uvWindow = replace(uvWindowArray[uvWindowArray.length-1],".NEF",
> ".tiff");
>
> //SAVE IMAGE
>
>                 savePath = saveDir+"Reflectance_"+fileList[i];
>                 saveAs("Tiff", savePath);
>         run("Close");
>
> // Naming
>
>
>         visName = replace(paths[0], ".tiff", "");
>         uvName = replace(paths[1], ".tiff", "");
>
>
>         rename(visName + "_aligned_with_" + uvName);
>
>         savePathArray = split(paths[3], ".");
>
>         savePath = savePathArray[0];
>
>         savePath = savePath + "_aligned_with_" + uvName + ".tif";
>
>         saveAs("TIFF", savePath);
>
>         setBatchMode(false);
>
>         print("\\Clear");
>
> } //macro
>
> // the end
>
>
>
> With thanks for any assistance...
>
>
>
>
>
>
>
> --
> View this message in context:
> http://imagej.1557.n6.nabble.com/Saving-multiple-active-windows-that-have-been-manipulated-onscreen-tp5002544.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Saving multiple active windows that have been manipulated onscreen...

t-lg
Thank you, in the end I split them into separate functions and that seems to work better.