Converting Vsi to Tiff causes undesired color changes

I’ve modified some code I found on github to convert vsi to Tiff images, but after it runs all of my images have a blue hue and any warm colors are totally ruined.

Even when I don’t use a macro, I simply open the image with the Bio-Formats importer and don’t split the channels, the blue is added once I save as a TIFF file. This change does NOT happen when saving as a PNG file.

On the top is the desired (opened by bio-formats in Fiji) and the bottom is after running it through my macro.

Here is the relevant code for where I split the channels and merge them, then save them into the TIFF file format.

//Get desired series to process
Dialog.create("Series");
Dialog.addString("Desired Series", "1", 5);
Dialog.show();
seriesNum = Dialog.getString();
suffix = ".vsi";

//Add a new identifier per series processed to prevent overwriting of images
Dialog.create("Unique Identifier");
Dialog.addString("Unique Identifier", "label", 5);
Dialog.show();
identifier = Dialog.getString();


//This creates the dialogue for focal plane selection.
Dialog.create("Please select which focal plane (Z) you wish to use, you can look at the focal planes in OlyVia first...");
Dialog.addNumber("Zplane#", 1);
Dialog.show();
zplane = Dialog.getNumber();


inDir = getDirectory("Choose Directory Containing " + suffix + " Files ");
outDir = inDir;
setBatchMode(true);
processFiles(inDir, outDir, "");
print("Done!");

function processFiles(inBase, outBase, sub) {
  flattenFolders = true; // this flag controls output directory structure
  print("Processing folder: " + sub);
  list = getFileList(inBase + sub);
  if (!flattenFolders) File.makeDirectory(outBase + sub);
  for (i=0; i<list.length; i++) {
    path = sub + list[i];
    //upath = toUpperCase(path); Leave this line commented out, you only need it if the file extension is case sensitive. Again, this is future proofing against olympus altering the file extension.
    upath = path; //This code was easier to write, and might be replaced by the the previous line (some day) which someone suggested to me.
    if (File.isDirectory(inBase + path)) {
      processFiles(inBase, outBase, path);
      
    }
    else if (endsWith(upath, suffix)) {

    print("Importing " + suffix + " = " + list[i] + ", Z-Plane#" + zplane);

//The top line here does not use the zplane variable to select a focal plane to import. The second line uses the zplane string to selectively import that plane.
//If you are using a virtual z image, you must select the focal plane you want to import. The top line here will simply use plane #1, which is rarely an in focus image.
//obsolete command//run("Bio-Formats Importer", "open=["+inBase + path+"] autoscale color_mode=Custom split_channels view=Hyperstack stack_order=XYCZT series_1 series_0_channel_0_red=0 series_0_channel_0_green=0 series_0_channel_0_blue=255 series_0_channel_1_red=0 series_0_channel_1_green=255 series_0_channel_1_blue=0 series_0_channel_2_red=255 series_0_channel_2_green=0 series_0_channel_2_blue=0");
run("Bio-Formats Importer", "open=[" + inBase + path + "] autoscale color_mode=Default specify_range split_channels rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT series_" + seriesNum +" c_begin_1=1 c_end_1=3 c_step_1=1 z_begin_1=zplane z_end_1=zplane z_step_1=0 series_" + seriesNum +"_channel_0_red=255 series_" + seriesNum +"_channel_0_green=0 series_" + seriesNum +"_channel_0_blue=0 series_" + seriesNum +"_channel_1_red=0 series_" + seriesNum +"_channel_1_green=255 series_" + seriesNum +"_channel_1_blue=0 series_" + seriesNum +"_channel_2_red=0 series_" + seriesNum + "_channel_2_green=0 series_" + seriesNum +"_channel_2_blue=255");


print("Blue...");
selectImage(1);
title1 = getTitle();

print("Green...");
selectImage(2);
title2 = getTitle();

print("Red...");
selectImage(3);
title3 = getTitle();

//Merges channels and flattens image to a single layer
print("Merging Channels...");
run("Merge Channels...", "red=&title3 green=&title2 blue=&title1");

//Saves files in .tiff format
print("Saving .tiff");
saveAs("Tiff", outBase + path);

    }
  }
}

Where is this code changing the colors?

Hi,
I tried your macro code on a sample VSI image, using latest Fiji and Bio-Formats 6.1.1 and had to modify the code a bit to get it to work…

imageDir = "/path/to/directory/"
seriesNum = 0
run("Bio-Formats Importer", "open=[" + imageDir + "Image_01.vsi] autoscale color_mode=Default specify_range split_channels rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT series_" + seriesNum +" c_begin_1=1 c_end_1=3 c_step_1=1 z_begin_1=zplane z_end_1=zplane z_step_1=0 series_" + seriesNum +"_channel_0_red=255 series_" + seriesNum +"_channel_0_green=0 series_" + seriesNum +"_channel_0_blue=0 series_" + seriesNum +"_channel_1_red=0 series_" + seriesNum +"_channel_1_green=255 series_" + seriesNum +"_channel_1_blue=0 series_" + seriesNum +"_channel_2_red=0 series_" + seriesNum + "_channel_2_green=0 series_" + seriesNum +"_channel_2_blue=255");


print("Blue...");
selectImage(1);
title1 = getTitle();

print("Green...");
selectImage(2);
title2 = getTitle();

print("Red...");
selectImage(3);
title3 = getTitle();

//Merges channels and flattens image to a single layer
print("Merging Channels...");
run("Merge Channels...", "red=&title3 green=&title2 blue=&title1");

//Saves files in .tiff format
print("Saving .tiff");
saveAs("Tiff", imageDir + "saved.tiff");

This seemed to work fine for me. The tiff looks the same as the original.
Can you see if this works for you. And if not, could you upload a sample file to https://www.openmicroscopy.org/qa2/qa/upload/ so we can try to reproduce your problem.
Thanks,

Will.

Hey Will,

Thanks for the reply! I’ve tested the code you posted and it gives me the same results,

Above is a more obvious example of this color change that is happening. I’ve updated my main post with my entire code, rather than just what I thought was relevant. The only change is the top half of the code that parses through the directory structure.

I’ve uploaded a zip of my test image directory to the website that you linked, but I’m not sure how to link it here. https://www.openmicroscopy.org/qa2/qa2/qa/feedback/27725/?token=04a0aca792823cce09f76c28826ae624

This is the link I get after clicking feedback, and the ticket ID is 27725. Not sure if you have access to this or not because when I follow the link it brings up a 404 page.

Hi, sorry, I’m getting confused. I think I have repeated what you’re seeing with your data, but what I see is the original vsi image is more blue, and the exported tif is warmer colours.
This seems the opposite way around from what you were describing above, “the blue is added once I save as a TIFF file”.

This is what I’m seeing:

02

15

To me, the TIFF looks “warmer” and less blue than the original.
I used all the default values for the dialogs in your Macro.

Anyway, I guess the point is that the TIFF should look the same as the Original (not warmer OR colder)!
I don’t have an answer to this just now and our Bio-Formats expert is on holiday, but I’ll refer this to him when he returns shortly.

Regards,
Will.

Just to confirm, I tried your updated Macro code with the other VSI file I have and I don’t see any change of colours.

I also tried importing your image into OMERO and then exporting as TIFF and this also seems unchanged.

09

OK, I think I figured it out.
You’ve got the red and blue channels switched.
If you edit this line to:

run("Merge Channels...", "red=&title1 green=&title2 blue=&title3");

it works fine and the TIFF looks the same as the VSI.

Regards,

Will.