zvi to RGB more code

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

zvi to RGB more code

Fabrice Senger
Hi again,

i'm still working on a macro to open zvi files as RGB stacks, the code
has evolved but still I would appreciate feed-back.
In this case, what I do not like , is that the "Channels" window is
still open...but it is faster then my prvious code.


Here the code :

setBatchMode(true);


run("Data Browser", "open= autoscale custom_colorize view=[Standard
ImageJ] stack_order=Default 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("Channels Tool...");
Stack.setDisplayMode("composite");
run("Stack to RGB", "slices keep");

setBatchMode(false)

--
Senger Fabrice
Reply | Threaded
Open this post in threaded view
|

Re: zvi to RGB more code

Glen MacDonald-2
Dear Senger,
Your channel assignments are hard coded into the macro, which assumes that it will only be used with
3 channel files containing blue, green and red fluorophores.  Will this always be the case?  I'm
including this macro I just finished to open a dataset using a dialog window for users to assign
channels to desired LUT.  I'm sure it needs improvement too.

Glen MacDonald
Core for Communication Research
Virginia Merrill Bloedel Hearing Research Center
Box 357923
University of Washington
Seattle, WA 98195-7923
(206) 616-4156

-------------------------------------
//Written by Glen MacDonald, Core for Communication Research
//Virginia Merrill Bloedel Hearing Research Center
//Box 357923
//University of Washington
//Seattle, WA 98195-7923
//[hidden email]
//Requires the LOCI_tools plugin.  On running the first macro, select a file, the dialog window will
// display number of channels and bit depth.  Select merge options of "RGB", "Composite Hyperstack"
// or "No Merge"  Select a channels (0-n) for each color channel.  Error trapping: If you choose a
//channel not present, the macro goes through the motions of opening the file then exits with a
//message that the channel is not present. Placing any channel into 2 colors will create an RGB merge.

var name,pType;
macro "Import Channel Order [1]"{
requires("1.41c");
run("Bio-Formats Macro Extensions");
path=File.openDialog("Select a file");
id=path;
name=File.getName(path);//gets the filename in this path
Ext.setId(id);
Ext.getSizeC(sizeC);//delivers the number of channels
Ext.getPixelType(pixelType);
pelType=pixelType;
matchPixelType(pType);
Dialog.create("Channel Merge Options");
Dialog.addChoice("Merge Type:", newArray("RGB", "Hyperstack", "No merge"),"RGB");
Dialog.addMessage("Assign "+sizeC+" stacks to merged color channels.\nBit depth is "+pType+" per
pixel.");
Dialog.addMessage("Red merged channel:");
Dialog.addChoice("Channels:", newArray("None","0", "1", "2", "3","4"),"2");
Dialog.addMessage("Green merged channel:");
Dialog.addChoice("Channels:", newArray("None","0", "1", "2", "3","4"),"1");
Dialog.addMessage("Blue merged channel:");
Dialog.addChoice("Channels:", newArray("None","0", "1", "2", "3","4"),"0");
Dialog.addMessage("Gray merged channel:");
Dialog.addChoice("Channels:", newArray("None","0", "1", "2", "3","4"),"None");
Dialog.show();
merge=Dialog.getChoice();
if (merge=="RGB")
  create = " ";
if (merge=="Hyperstack")
  create = "create";
if (merge!="No merge"){
  setBatchMode(true);
  options="open=["+path+"] view=[Standard ImageJ] stack_order=Default split_channels
autoscale"; //set options for bio-formats
  showStatus("opening file");
  run("Bio-Formats Importer",options);
  nameCh=name+" - C=";
  red= Dialog.getChoice();
  grn= Dialog.getChoice();
  blu= Dialog.getChoice();
  gry= Dialog.getChoice();
  chno=0;
  if (red!= "None"){
  redc =nameCh+red;
  chno=red;
  }else
  redc = "*None*";
  if (grn != "None"){
  grnc =nameCh+grn;
  if (chno<grn)
  chno=grn;
  }else
  grnc = "*None*";
  if (blu != "None"){
  bluc =nameCh+blu;
  if (chno<blu)
  chno=blu;
  }else
  bluc = "*None*";
  if (gry != "None"){
  gryc =nameCh+gry;
  if (chno<gry)
  chno=gry;
  }else
  gryc = "*None*";
  chno=chno+1;
  if (chno>sizeC)
  exit("You selected too many channels, only "+sizeC+" channels are present.");
      createtype="red=["+redc+"] green=["+grnc+"] blue=["+bluc+"] gray=["+gryc+"] "+create;
  run("Merge Channels...", createtype);
//example: run("Merge Channels...", "red=[Image0007.oif - C=0] green=[Image0007.oif - C=1]
blue=[Image0007.oif - C=2] gray=*None* create keep");
  prefix=substring(name,0,indexOf(name,"."));
  rename(prefix+"_merge");
  setBatchMode(false);
  }
  else{
  options="open=["+path+"] view=[Standard ImageJ] stack_order=Default split_channels
autoscale";
  showStatus("opening file");
  run("Bio-Formats Importer",options);
  }
}

function matchPixelType(pelType){
if (matches(pixelType,"uint8"))
  pType = "unsigned 8-bits";
if (matches(pixelType,"uint16"))
  pType = "unsigned 16-bits";
if (matches(pixelType,"uint32"))
  pType = "unsigned 32-bits";
if (matches(pixelType,"int8"))
  pType = "signed 8-bits";
if (matches(pixelType,"int16"))
  pType = "signed 16-bits";
if (matches(pixelType,"int32"))
  pType = "signed 32-bits";
if (matches(pixelType,"float"))
  pType = "floating point 32-bits";
if (matches(pixelType,"double"))
  pType = "64-bits double precision";
}

macro "Composite Hyperstack to RGB [2]"{
run("Channels Tool...");
run("Stack to RGB");
}

-----------------------------------------
On Fri, 10 Jul 2009, Senger Fabrice wrote:

> Hi again,
>
> i'm still working on a macro to open zvi files as RGB stacks, the code has
> evolved but still I would appreciate feed-back.
> In this case, what I do not like , is that the "Channels" window is still
> open...but it is faster then my prvious code.
>
>
> Here the code :
>
> setBatchMode(true);
>
>
> run("Data Browser", "open= autoscale custom_colorize view=[Standard ImageJ]
> stack_order=Default 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("Channels Tool...");
> Stack.setDisplayMode("composite");
> run("Stack to RGB", "slices keep");
>
> setBatchMode(false)
>
> --
> Senger Fabrice
Reply | Threaded
Open this post in threaded view
|

Re: zvi to RGB more code

Fabrice Senger
Glen H MacDonald a écrit :

> Dear Senger, Your channel assignments are hard coded into the macro,
> which assumes that it will only be used with 3 channel files
> containing blue, green and red fluorophores.  Will this always be the
> case?  I'm including this macro I just finished to open a dataset
> using a dialog window for users to assign channels to desired LUT.  
> I'm sure it needs improvement too.
>
> Glen MacDonald
> Core for Communication Research
> Virginia Merrill Bloedel Hearing Research Center
> Box 357923
> University of Washington
> Seattle, WA 98195-7923
> (206) 616-4156
>
> -------------------------------------
> //Written by Glen MacDonald, Core for Communication Research
> //Virginia Merrill Bloedel Hearing Research Center
> //Box 357923
> //University of Washington
> //Seattle, WA 98195-7923
> //[hidden email]
> //Requires the LOCI_tools plugin.  On running the first macro, select
> a file, the dialog window will
> // display number of channels and bit depth.  Select merge options of
> "RGB", "Composite Hyperstack"
> // or "No Merge"  Select a channels (0-n) for each color channel.  
> Error trapping: If you choose a //channel not present, the macro goes
> through the motions of opening the file then exits with a //message
> that the channel is not present. Placing any channel into 2 colors
> will create an RGB merge.
>
> var name,pType;
> macro "Import Channel Order [1]"{
> requires("1.41c");
> run("Bio-Formats Macro Extensions");
> path=File.openDialog("Select a file");
> id=path;
> name=File.getName(path);//gets the filename in this path
> Ext.setId(id);
> Ext.getSizeC(sizeC);//delivers the number of channels
> Ext.getPixelType(pixelType);
> pelType=pixelType;
> matchPixelType(pType);
> Dialog.create("Channel Merge Options");
> Dialog.addChoice("Merge Type:", newArray("RGB", "Hyperstack", "No
> merge"),"RGB"); Dialog.addMessage("Assign "+sizeC+" stacks to merged
> color channels.\nBit depth is "+pType+" per pixel.");
> Dialog.addMessage("Red merged channel:");
> Dialog.addChoice("Channels:", newArray("None","0", "1", "2",
> "3","4"),"2"); Dialog.addMessage("Green merged channel:");
> Dialog.addChoice("Channels:", newArray("None","0", "1", "2",
> "3","4"),"1");
> Dialog.addMessage("Blue merged channel:");
> Dialog.addChoice("Channels:", newArray("None","0", "1", "2",
> "3","4"),"0");
> Dialog.addMessage("Gray merged channel:");
> Dialog.addChoice("Channels:", newArray("None","0", "1", "2",
> "3","4"),"None");
> Dialog.show();
> merge=Dialog.getChoice();
> if (merge=="RGB")
>     create = " ";
> if (merge=="Hyperstack")
>     create = "create"; if (merge!="No merge"){
>     setBatchMode(true);
>     options="open=["+path+"] view=[Standard ImageJ]
> stack_order=Default split_channels autoscale"; //set options for
> bio-formats
>     showStatus("opening file");
>     run("Bio-Formats Importer",options);
>     nameCh=name+" - C=";
>     red= Dialog.getChoice();
>     grn= Dialog.getChoice();
>     blu= Dialog.getChoice();
>     gry= Dialog.getChoice();
>     chno=0;
>     if (red!= "None"){
>         redc =nameCh+red;
>         chno=red;
>     }else
>         redc = "*None*";
>     if (grn != "None"){
>         grnc =nameCh+grn;
>         if (chno<grn)
>             chno=grn;
>     }else
>         grnc = "*None*";
>     if (blu != "None"){
>         bluc =nameCh+blu;
>         if (chno<blu)
>             chno=blu;
>     }else
>         bluc = "*None*";
>     if (gry != "None"){
>         gryc =nameCh+gry;
>         if (chno<gry)
>             chno=gry;
>     }else
>         gryc = "*None*";
>     chno=chno+1;
>     if (chno>sizeC)
>     exit("You selected too many channels, only "+sizeC+" channels are
> present.");
>      createtype="red=["+redc+"] green=["+grnc+"] blue=["+bluc+"]
> gray=["+gryc+"] "+create;
>     run("Merge Channels...", createtype);
> //example: run("Merge Channels...", "red=[Image0007.oif - C=0]
> green=[Image0007.oif - C=1] blue=[Image0007.oif - C=2] gray=*None*
> create keep");
>     prefix=substring(name,0,indexOf(name,"."));
>     rename(prefix+"_merge");
>     setBatchMode(false);
>     }
>     else{
>         options="open=["+path+"] view=[Standard ImageJ]
> stack_order=Default split_channels autoscale";
>         showStatus("opening file");
>         run("Bio-Formats Importer",options);
>     }
> }
>
> function matchPixelType(pelType){
> if (matches(pixelType,"uint8"))
>     pType = "unsigned 8-bits";
> if (matches(pixelType,"uint16"))
>     pType = "unsigned 16-bits";
> if (matches(pixelType,"uint32"))
>     pType = "unsigned 32-bits";
> if (matches(pixelType,"int8"))
>     pType = "signed 8-bits";
> if (matches(pixelType,"int16"))
>     pType = "signed 16-bits";
> if (matches(pixelType,"int32"))
>     pType = "signed 32-bits";
> if (matches(pixelType,"float"))
>     pType = "floating point 32-bits";
> if (matches(pixelType,"double"))
>     pType = "64-bits double precision";
> }
>
> macro "Composite Hyperstack to RGB [2]"{
> run("Channels Tool...");
> run("Stack to RGB");
> }
>
> -----------------------------------------
> On Fri, 10 Jul 2009, Senger Fabrice wrote:
>
>> Hi again,
>>
>> i'm still working on a macro to open zvi files as RGB stacks, the
>> code has evolved but still I would appreciate feed-back.
>> In this case, what I do not like , is that the "Channels" window is
>> still open...but it is faster then my prvious code.
>>
>>
>> Here the code :
>>
>> setBatchMode(true);
>>
>>
>> run("Data Browser", "open= autoscale custom_colorize view=[Standard
>> ImageJ] stack_order=Default 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("Channels Tool...");
>> Stack.setDisplayMode("composite");
>> run("Stack to RGB", "slices keep");
>>
>> setBatchMode(false)
>>
>> --
>> Senger Fabrice
Hum,

I wrote this code to answer a specific question, and this will be then
further integrated into a more complex analysis...but, you are wright,
one of my aims is aswell to give people the freedom to open zvi files as
easily as with axiovision, therefore your code will be very helpfull to me.

All teh best,

Fabrice.

--
Senger Fabrice