high%throughput,microscopy,course:,p11, - kota...
TRANSCRIPT
Try,the,program,working.,,Open,the,Image,(2ch,stack),
,File,>,Open,,,
TASK:,AutomaPc,measurement,of,intensity,changes,over,Pme,at,the,vicinity,of,nuclear,membrane.,
Task,
Try,the,program,working.,,Open,the,Image,(2ch,stack),
,File,>,Open,,,Open,Script,Editor,
,File,>,New,>,Script,,From,the,Script,Editor,Menu,,,
,File,>,Open,>,(choose,nucRim2.py),,Execute:,
,Click,“Run”,in,the,script,editor,,
TASK:,AutomaPc,measurement,of,intensity,changes,over,Pme,at,the,vicinity,of,nuclear,membrane,
Task,
1.,Create,Mask,
2.,Measure,intensity,According,to,the,mask,
Measurement,of,Intensity,Changes,at,Nuclear,Edge,
2%2,Basics,
2-2-1 Hello World! (Fiji)
[File&>&New&>&Script]&
&
Set,language,to,ImageJ,Macro,in,the,editor,&
[Language&5>&ImageJ¯o],,
1. Create a new macro
2. And then write as follows:
print("Hello,World!");,, Printout in the Log Window
4. Save the macro as “HelloWorld.ijm”. [File -> Save As…]
3. In Script Editor menu, [Run > Run ]
2%2,Basics,
2-2-1 Hello World! (Fiji)
print("Hello,World!");,,
Print() command
Semi-colon at the end of command is very important
Parameter “Hello World”
To,see,command,reference:,,% Double,click,the,command,% [Tools,>,Open,Help,for,Macro,FuncPon],
2%2,Basics,
2-2-1 Hello World! (Fiji)
[File&>&New]&
&
Set,language,to,ImageJ,Macro,in,the,editor,&
[Language&5>&ImageJ¯o],,
1. Create a new tab in script editor.
2. And then write as follows (omit numbers)
1:,macro,"print_out",{,2:,,,,,print("Hello,World!");,3:,},
3. Install the macro. In the Editor menu
[Run&5>&Install&Macro]&
,,,,,,,,,,,,,,,,,,,,,,,,,,,,(or,command,%,I),,
Printout in the Log Window
Tabulate!
5. Save the macro as “HelloWorld.ijm”. [File -> Save As…]
4. In Fiji menu, [Plugins -> Macro -> Print out]
(currently there is a bug in Install Macro)
2%2,Basics,
Second way to run script
[Run -> Run] , or control-R (win) command-R (mac)
By the way, you could start up script editor by ctrl-{ (win)
2%2,Basics,
2-2-1 Hello World!: EXERCISE
Code&1&
1:,macro,"print_out",{,2:,,,,,print("Hello,World!");,3:,},
Exercise&25152:,,(1) Add,another,line,“print("\\Clear");”,aeer,the,second,line,
(don’t,forget,the,semi%colon,at,the,end!).,,(2) Then,test,also,when,you,insert,the,same,command,in,the,
third,line.,What,happened?&&&
Code&1.5,1:,macro,"print_out",{,2: ,print("\\Clear");,3: ,print("Hello,World!");,4:,},
Code&1.75,1:,macro,"print_out",{,2:, ,print("Hello,World!");,3: ,print("\\Clear");,4:,},
2%2,Basics,
2-2-1 Hello World!: EXERCISE
1:,macro,"print_out",{,2:,,,,,print("Hello,World!");,3:,},
Exercise&25153:,MulPple,macros,can,exist,in,a,single,file.,We,call,this,“macro&sets”.,Duplicate,the,code,you,wrote,by,copying,and,pasPng,under,the,original.,The&second¯o&
should&have&a&different&name.,In,the,example,here,,the,second,macro,is,named,“pirnt_out2”.,
2%2,Basics,
2-2-2 Variables, Strings
Code&2,1:,,macro,"print_out",{,2: ,text,=,”Hello,World!";,3: ,print(text);,4: ,text,=,”Bye,World!";,5: ,print(text);,6:,},
String Assignments String Variable
Code&3,1:,macro,"print_out",{,2:, ,text1,=,"Hello";,3:, ,text2,=,",World!";,4:, ,text3,=,text1,+,text2;,5:, ,print(text3);,6:},
Exercise&2525251:&Add&more&string&variables&and&
make&a&longer&sentence.&Check&your¯o&by&
running&it.&
String concatenation
2%2,Basics,
2-2-2 Variables, Strings
Numerical variable Assignments
Code&4,1:,macro,"print_out_calc",{,2: ,a,=,1;,3: ,b,=,2;,4: ,c,=,a,+,b;,5:, ,print("\\Clear"); , ,,6: ,print(c);,7: ,print(a,+,"+"+,b,+,"="+c);,8: ,txt=""+a,+,"+"+,b,+,"="+c;,9: ,print(txt);,10:,},
Numerical variable
message_text,=,256;,
message_text,=,“256”;,
!�Nummerical
!�String function
txt=a,+,"+"+,b,+,"="+c;,,
Exercise&25252:&Modify,the,code,4,,so,that,the,calculaPon,involves,subtracPon,(%),,mulPplicaPon,(*),and,division,(/).,,,
2%2,Basics,
2-2-3 parameter input by user
Code&5,1:,macro,"input_print_out_calc",{,2:, ,a,=,getNumber("a?",,10);,3: ,b,=,getNumber("b?",,5);,4: ,c,=,a*b;,5: ,print("\\Clear");,6: ,print(c);,7:},
Syntax: ,getNumber(message,string,,default,number),,return,value:,user,input,number,
Numerical Function Clears Log Window
2%2,Basics,
2-2-3 parameter input by user
Syntax: ,getString(message,string,,default,string),,return,value:,user,input,string,
Code&6,1:,macro,"input_print_out_str",{,2: ,a,=,getString("a?",,“hello”);,3: ,b,=,getString("b?",,“,world!”);,4: ,c,=,a+b;,5: ,print("\\Clear");,6: ,print(c);,7:,},
String Function
Exercise&25351:&Run,the,code,6,and,input,1,for,a,and,2,for,b.,What,happened?,Explain&the&reason.,,
2%2,Basics,
2-2-4 Including ImageJ Macro Commands into your macro
�Macro Recorder” a very powerful tool for macro programming
[PlugIns&5>&Macros&5>&Record…],,
1.,[File&5>&New],(size,can,be,anything),,
2.,[Process&5>&Noise&5>&Salt&and&Pepper],,
3. [Process -> Filters -> Gaussian Blur] (diameter=2)
4.,[Image&5>&Adjust&5>&Threshold..]&then,“Apply”,,
2%2,Basics,
2-2-4 Including ImageJ Macro Commands into your macro
1.,[File&5>&New],(size,can,be,anything),,
2.,[Process&5>&Noise&5>&Salt&and&Pepper],,
3. [Process -> Filters -> Gaussian Blur] (diameter=2)
4.,[Image&5>&Adjust&5>&Threshold..]&then,“Apply”,,
Code&7,1:,macro,"GB2_Thr",{,2: ,newImage("test",,"8%bit,Black",,300,,300,,1);,3: ,run("Salt,and,Pepper");,4: ,run("Gaussian,Blur...",,"radius=2");,5: ,setThreshold(32,,100);,6: ,run("Convert,to,Mask");,7:,},,
newImage(Ztle,&type,&width,&height,&depth),,Opens,a,new,image,or,stack,using,the,name,#tle.,The,string,type,should,contain"8%bit",,"16%bit",,"32%bit",or,"RGB".,In,addiPon,,it,can,contain,"white",,"black",or,"ramp",(the,default,is,"white").,As,an,example,,use,"16%bit,ramp",to,create,a,16%bit,image,containing,a,grayscale,ramp.,Width,and,height,specify,the,width,and,height,of,the,image,in,pixels.,Depth,specifies,the,number,of,stack,slices.,,,
From “Build-in Macro Functions”
newImage("test",,"8%bit,Black",,300,,300,,1);,
2%2,Basics,
2-2-4 Including ImageJ Macro Commands into your macro
1.,[File&5>&New],(size,can,be,anything),,
2.,[Process&5>&Noise&5>&Salt&and&Pepper],,
3. [Process -> Filters -> Gaussian Blur] (sigma=2)
4.,[Image&5>&Adjust&5>&Threshold..]&then,“Apply”,,
Code&7,1:,macro,"GB2_Thr",{,2: ,newImage("test",,"8%bit,Black",,300,,300,,1);,3: ,run("Salt,and,Pepper");,4: ,run("Gaussian,Blur...",,“sigma=2");,5: ,setThreshold(0,,7);,6: ,run("Convert,to,Mask");,7:,},,
2%3,CondiPon,and,Loops,
25351&Loop:&for5statement&
�
Code&9,1:,macro,"loop1",{,2:& &txt&=&“whatever”;,3: &for(,i,=0,;,i,<5,;,i,+=,1,),{,4: , ,print(i,+,“:,”,+,txt);,5: ,},6:,},,
line,3,for(i=0;6i<5;6i+=1),sets,the,looping,condiPon.,,
initialize counter
Condition for exiting the loop
Increment per loop
i++
����braces are again to define the boundary of “for” looping
2%3,CondiPon,and,Loops,
25351&Loop:&for5statement&
�
Code&9,1:,macro,"loop1",{,2:& &txt&=&“whatever”;,3: &for(i=0;,i<5;,i+=1),{,4: , ,print(i,+,“:,”,+,txt);,5: ,},6:,},,
Exercise 2-3-1-1:
(1) Change the first parameter in for(i=0;i<5;i+=1) so that the macro prints out only 1 line.
(2) Change the second parameter in for(i=0;i<5;i+=1) so that the macro prints out 10 lines.
(3) Change the third parameter in for(i=0;i<5;i+=1) so that the macro prints out 10 lines.
!�i=4
!�i<10
!�i+=0.5
2%3%2,Stack,Management,by,for%statement.,,
2%3,CondiPon,and,Loops,
Code&10&
1:,macro,"Measure,Ave,Intensity,Stack",{,2: ,frames=nSlices;,3: ,run("Set,Measurements...",,",,mean,redirect=None,decimal=3");,4: ,run("Clear,Results");,5: ,for(i=0;,i<frames;,i++),{,6: , ,currentslice=i+1;,7: , ,setSlice(currentslice);,8: , ,run("Measure");,9: ,},10:,},
2%3%2,Stack,Management,by,for%statement.,,
2%3,CondiPon,and,Loops,
Code&10&
1:,macro,"Measure,Ave,Intensity,Stack",{,2: ,frames=nSlices;,3: ,run("Set,Measurements...",,",,mean,redirect=None,decimal=3");,4: ,run("Clear,Results");,5: ,for(i=0;,i<frames;,i++),{,6: , ,currentslice=i+1;,7: , ,setSlice(currentslice);,8: , ,run("Measure");,9: ,},10:,},
nSlices Returns the number of slices in the current stack. Returns 1 if the current image is not a stack.
setSlice(n),Displays,the,nth,slice,of,the,acPve,stack.,Does,nothing,if,the,acPve,image,is,not,a,stack.,,
1.,Create,Mask,
2.,Measure,intensity,According,to,the,mask,
Measurement,of,Intensity,Changes,at,Nuclear,Edge,
Let’s,do,it,,,first,manually,,then,macro.,,
We,compose,a,code,using,singleCell.Pf,,since,this,will,then,be,much,faster,with,calculaPon.,,,This,file,is,in,the,server.,,
1.,Gaussian,blur,,,Process,>,Filter,>,Gaussian,Blur,,,(sigma,=,1.5,,do,stack),
,,2.,Find,Threshold,
,Image,>,Adjust,>,Threshold,,(Otsu,method),
3.,Apply,Threshold,,(Click,‘Apply’),
4.,Find,Threshold,again,,(Otsu,method),
5.,Analyze,parPcles,,Analyze,>,Analyze,ParPcles,,,OpPons::,
6.,Invert,LUT,,Image,>,Look%up,Table,, ,>,Invert,LUT,
7.,Duplicate,Stack,,Image,>,Duplicate,
,,,7.0.,,Set,IteraPons,,Process,>,Binary,>,OpPons,,(iteraPons,2,or,3,,dark,background),
,,,7.,1.,Original:,Dilate,,Process,>,Binary,>,Dilate,
,,,7.,2.,Duplicate:,Erode,,Process,>,Binary,>,Erode,
,3.,Subtract,(1,–,2),
,Process,>,Image,Calculator,,(keep,original,,difference),
DetecPng,Nucleus,Rim,
1.,Gaussian,blur,,,Process,>,Filter,>,Gaussian,Blur,,,(sigma,=,1.5,,do,stack),
,,2.,Find,Threshold,
,Image,>,Adjust,>,Threshold,,(Otsu,method),
3.,Apply,Threshold,,(Click,‘Apply’),
4.,Find,Threshold,again,,(Otsu,method),
5.,Analyze,parPcles,,Analyze,>,Analyze,ParPcles,,,,
6.,Invert,LUT,,Image,>,Look%up,Table,, ,>,Invert,LUT,
DetecPng,Nucleus,Rim:,Now&record&what&you&do.&&
7.,Duplicate,Stack,,Image,>,Duplicate,
,,,7.0.,,Set,IteraPons,,Process,>,Binary,>,OpPons,,(iteraPons,2,or,3,,dark,background),
,,,7.,1.,Original:,Dilate,,Process,>,Binary,>,Dilate,
,,,7.,2.,Duplicate:,Erode,,Process,>,Binary,>,Erode,
,3.,Subtract,(1,–,2),
,Process,>,Image,Calculator,,(keep,original,,difference),
Recording,Results&
Click!,
Then,acPvate,(click),the,original,image,,Click,Run.,
If,you,are,lucky,enough,,it,works…,
selectWindow("original.tif"); run("Duplicate...", "title=original-1.tif duplicate range=1-15"); run("Gaussian Blur...", "sigma=1.50 stack"); //run("Threshold..."); setAutoThreshold("Otsu dark"); run("Convert to Mask", "method=Otsu background=Dark calculate black"); setAutoThreshold("Otsu dark"); run("Analyze Particles...", "size=800-Infinity pixel circularity=0.00-1.00 show=Masks display exclude clear include stack"); run("Invert LUT"); run("Duplicate...", "title=[Mask of original-2.tif] duplicate range=1-15"); run("Options...", "iterations=3 count=1 black edm=Overwrite do=Nothing"); selectWindow("Mask of original-1.tif"); run("Dilate", "stack"); selectWindow("Mask of original-2.tif"); run("Erode", "stack"); imageCalculator("Difference create stack", "Mask of original-1.tif","Mask of original-2.tif"); selectWindow("Result of Mask of original-1.tif");
Improve,this,,to,make,it,become,general.,,
selectWindow("original.tif"); window,name,is,fixed.,,Not,general.,,
origID = getImageID(); selectImage(origID); orgName = getTitle();
ID,number,of,the,acPve,window,is,sampled.,,,Can,call,up,that,window,later.,,,
Test:,,id = getImageID(); print(id); name = getTitle(); print();
orgID = getImageID(); run("Duplicate...", "title=original-1.tif duplicate range=1-15"); run("Gaussian Blur...", "sigma=1.50 stack"); //run("Threshold..."); setAutoThreshold("Otsu dark"); run("Convert to Mask", "method=Otsu background=Dark calculate black"); setAutoThreshold("Otsu dark"); run("Analyze Particles...", "size=800-Infinity pixel circularity=0.00-1.00 show=Masks display exclude clear include stack"); run("Invert LUT"); run("Duplicate...", "title=[Mask of original-2.tif] duplicate range=1-15"); run("Options...", "iterations=3 count=1 black edm=Overwrite do=Nothing"); selectWindow("Mask of original-1.tif"); run("Dilate", "stack"); selectWindow("Mask of original-2.tif"); run("Erode", "stack"); imageCalculator("Difference create stack", "Mask of original-1.tif","Mask of original-2.tif"); selectWindow("Result of Mask of original-1.tif");
Improve,this,,to,make,it,become,general.,,
Stack,Size?,
run("command"[,&"opZons"])&
,Executes,an,ImageJ,menu,command.,The,opPonal,second,argument,contains,values,that,are,automaPcally,entered,into,dialog,boxes,(must,be,GenericDialog,or,OpenDialog).,Use,the,Command,Recorder,(Plugins>Macros>Record),to,generate,run(),funcPon,calls.,Use,string,concatentaPon,to,pass,a,variable,as,an,argument.,With,ImageJ,1.43,and,later,,variables,can,be,passed,without,using,string,concatenaPon,by,adding,"&",to,the,variable,name.,
run("Duplicate...", "title=original-1.tif duplicate range=1-15");
options = "title=dup.tif duplicate range=1-” + nSlices; run("Duplicate...", options);
Test:, print(nSlices); options = "title=dup.tif duplicate range=1-” + nSlices; print(options);
command, opPons,
Anatomy,of,‘run’&
orgID = getImageID(); options = "title=dup.tif duplicate range=1-” + nSlices; run("Duplicate...", options); run("Gaussian Blur...", "sigma=1.50 stack"); //run("Threshold..."); setAutoThreshold("Otsu dark"); run("Convert to Mask", "method=Otsu background=Dark calculate black"); setAutoThreshold("Otsu dark"); run("Analyze Particles...", "size=800-Infinity pixel circularity=0.00-1.00 show=Masks display exclude clear include stack"); run("Invert LUT"); options = "title=erode.tif duplicate range=1-” + nSlices; run("Duplicate...", options); run("Options...", "iterations=3 count=1 black edm=Overwrite do=Nothing"); selectWindow("Mask of original-1.tif"); run("Dilate", "stack"); selectWindow("Mask of original-2.tif"); run("Erode", "stack"); imageCalculator("Difference create stack", "Mask of original-1.tif","Mask of original-2.tif"); selectWindow("Result of Mask of original-1.tif");
Improve,this,,to,make,it,become,general.,,
Use,ImageID,,not,Image,Ptle,
orgID = getImageID(); options = "title=dup.tif duplicate range=1-” + nSlices; run("Duplicate...", options); dupID = getImageID(); run("Gaussian Blur...", "sigma=1.50 stack"); //run("Threshold..."); setAutoThreshold("Otsu dark"); run("Convert to Mask", "method=Otsu background=Dark calculate black"); setAutoThreshold("Otsu dark"); run("Analyze Particles...", "size=800-Infinity pixel circularity=0.00-1.00 show=Masks display exclude clear include stack"); dilateID = getImageID(); run("Invert LUT"); options = "title=erode.tif duplicate range=1-” + nSlices; run("Duplicate...", options); erodeID = getImageID(); run("Options...", "iterations=3 count=1 black edm=Overwrite do=Nothing"); selectImage(dilateID); run("Dilate", "stack"); selectImage(erodeID); run("Erode", "stack"); imageCalculator("Difference create stack", dilateID, erodeID); //selectWindow("Result of Mask of original-1.tif");
Improve,this,,to,make,it,become,general.,,
Analyze,>,Set,Measurements…,(Area,,Standard,DeviaPon,,Mean,,Min,&,Max),,Analyze,>,Measure,
Simple,measurement&
Edit,>,SelecPon,>,Create,SelecPon,,Edit,>,SelecPon,>,Make,Inverse,,Analyze,>,Measure,,
Analyze,>,Set,Measurements…,(redirect,to:,channel,1),,
RedirecPng,Measurements,(use,mask,to,measure,signal),
(with,2,stacks,,rim,stack,and,signal,stack,opened),,Image,>,Color,.,Merge,Channels…,
,red,channel:,signal,,green:,nucleus,rim,,ignore,LUT!,
,Image,>,Color,>,Split,Channels,,,Analyze,>,Set,Measurements…,
,(Area,,Standard,DeviaPon,,Mean,,Min,&,Max),,(redirect,to:,channel,1,name),
,Edit,>,SelecPon,>,Create,SelecPon,,Edit,>,SelecPon,>,Make,Inverse,,Analyze,>,Measure,
Redirected,measurement&
…,Convert,this,to,a,macro.,!,Macro,Recorder.,,
run("Split Channels"); run("Set Measurements...", "area mean standard min integrated stack limit redirect=C1-Merged decimal=2"); run("Create Selection"); run("Make Inverse"); run("Measure");
orgName = getTitle(); run("Split Channels"); c1 = "C1-" + orgName; c2 = "C2-" + orgName; opt ="area mean standard min integrated stack limit redirect="+c1+" decimal=2"; run("Set Measurements...", opt); run("Create Selection"); run("Make Inverse"); run("Measure");
Measures,only,one,frame…,
Redirected,measurement,(macro)&
orgName = getTitle(); run("Split Channels"); c1 = "C1-" + orgName; c2 = "C2-" + orgName; opt ="area mean standard min integrated stack limit redirect="+c1+" decimal=2"; run("Set Measurements...", opt); selectWindow(c2); for (i =0; i < nSlices; i++){
setSlice(i+1); run("Create Selection"); run("Make Inverse"); run("Measure");
}
Redirected,measurement,(macro)&
Add,For,loop!,
Finally,,combine,them,all,as,a,single,macro.,,…,do,it,yourself,,or,if,we,do,not,have,Pme:,,,h{ps://gist.github.com/3911066,