// This Macros are made for PETIS Image Analysis. // Created by Naoki Kawachi. // Version 2.1.1 08/May/2012 //////////Macor in Pull Down Menu////////// macro "---PETIS Format Import Utilities---" {} macro "PETIS_3 Text Format [f1]" {importPETIS3TextImage();} macro "ALL PETIS_3 Text Format [f2]" {importAllPTETIS3TextImages();} macro "PETIS_4 Analyze Format [f3]" {importPETIS4AnaImage();} macro "Gamma Camera Text Format [f10]" {importGammaCTextImage();} macro "-" {} macro "---PETIS Images Analysis Utilities---" {} macro "Set PETIS Image Frames [f4]" {setPETIS_ImageFrame();} macro "PETIS Image Multiplier [f5]" {PETISimageMultiplier();} macro "Re-Stack PETIS Image [f6]" {reStackPETIS_Images();} macro "-" {} macro "---PETIS Numerical Analysis Utilities---" {} macro "ROIs Submit [f7]" {roiSubmit();} macro "Get PETIS TAC [f8]" {getPETIS_TAC();} macro "TACs Analysis [f9]" {tacAnalysis();} macro "-" {} macro "---Presantation Utilities---" {} macro " PETIS Color Bar " {setColorBar();} macro " PETIS Time Bar " {setTimeBar();} macro " PETIS Lap Time Stamp " {setLapTimeStamp();} macro " PETIS Montage " {makePETIS_Montage();} macro "-" {} macro "---Look up Tables---" {} macro " RGB Color" { getLut(reds, greens, blues); G256_RGB_LUT(reds,greens,blues); setLut(reds, greens, blues); } macro " RGBw Color" { getLut(reds, greens, blues); G256_RGB_LUT(reds,greens,blues); reds[255] = 255; greens[255] = 255; blues[255] = 255; //Write White setLut(reds, greens, blues); } macro " NIH Color" { getLut(reds, greens, blues); G256_NIH_LUT(reds,greens,blues); setLut(reds, greens, blues); } macro " NIHw Color" { getLut(reds, greens, blues); G256_NIH_LUT(reds,greens,blues); reds[255] = 255; greens[255] = 255; blues[255] = 255; //Write White setLut(reds, greens, blues); } macro " FIRE Color" {run("Fire");} macro " Gray Color" {run("Grays");} macro " Invert LUT" { getLut(reds, greens, blues); for (i=0; iend;i--){ setSlice(i); run("Delete Slice"); } for (i=start-1;i>0;i--){ setSlice(i); run("Delete Slice"); } } // (6) // This Function Multiple PETIS Image (each Frames). function PETISimageMultiplier() { name=getTitle(); width=getWidth();height=getHeight();frame=nSlices; n=nImages; image_name=newArray(n); for (i=0; i1){ title = getTitle(); Dialog.create("Select Target Image"); Dialog.addMessage("Target Images is "+title); Dialog.show(); selectWindow(title); } else if (nImages==1){ title = getTitle(); selectWindow(title); } else if (nImages==0){ open(""); } ////2. Read Image Informations////// name=getTitle(); name_head=split(name, "."); name_head=name_head[0]; width=getWidth();height=getHeight();frame=nSlices; step = floor(frame/10); ////3. Set New Stack Image Parameters////// selectWindow(name); Dialog.create("Set New Frame Info"); Dialog.addNumber("Enter Start Frame No.", 1); Dialog.addNumber("How Many Steps?",step); Dialog.addString("Restack Image File Name", name_head+"_restack"); Dialog.show(); start = Dialog.getNumber(); step = Dialog.getNumber(); new_name = Dialog.getString(); new_frame = floor((frame-start+1) / step); tag = "Frame interval"; period = getTag(tag); period = split(period," "); period = (0+period[0])*step; tag="PETIS Comment"; comment="PETIS Comment:"+getTag(tag); tag="PETIS Measurement Date"; PETIS_date="PETIS Measurement Date:"+getTag(tag); tag="PETIS Positron RI"; PETIS_RI="PETIS Positron RI:"+getTag(tag); tag="PETIS Blank"; PETIS_Blank="PETIS Blank:"+getTag(tag); ////4. Make New Stack Images ////// newImage(new_name,"32-bit",width,height,new_frame); run("Properties...", "width="+width+" height="+height+" channels=1 depth=1 frames="+new_frame+" unit=mm pixel_width=1.10000 pixel_height=1.10000 voxel_depth=1.00000 frame="+period+" origin=0,0"); PETIS_header = "Info:"+comment+"\n"+PETIS_date+"\n"+PETIS_RI+"\n"+PETIS_Blank; setMetadata(PETIS_header); for (l=1;l<=new_frame;l++){ selectWindow(name); pixel_count=newArray(width*height); for (k=start;k<=start+step-1;k++){ setSlice(k+step*(l-1)); for (j=0;j> lineColor=newArray("black","red","blue","green","orange","darkGray","magenta","yellow","gray","cyan","pink","lightGray"); //<> windowList = getList("window.titles"); if (windowList.length==0) print("No non-image windows are open"); else { print("Non-image windows:"); for (i=0; i> nRoi=roiManager("count"); indexesRoi=newArray(nRoi); indexesRoiName=newArray(nRoi); for (i=0; i> //1. Selection Dialog Dialog.create("Select Target Image and ROIs for Analysis"); Dialog.addMessage("Select Target Image"); Dialog.addChoice(" ", imageTitle, imageTitle[0]); Dialog.addMessage("Select Submitted ROIs for Analysis"); for (i=0; i> selectWindow(targetImage); name=getTitle(); //Image Name dir=getDirectory("image"); //Image Dir if (dir == "") dir = "This Image on the ImageJ Memory"; tag="Frame interval"; str=getTag(tag); period=split(str," "); period=0+period[0]; //Frame interval (sec) if (period==0) period = 1; tag="PETIS Comment"; comment=getTag(tag); //PETIS Comment tag="PETIS Measurement Date"; mdate=getTag(tag); //Measurement Date tag="PETIS Positron RI"; positronRI=getTag(tag); //Name of RI ns = nSlices; //Number of Frames nAD = ns*newNRoi; //Number of All Data //<> area=newArray(nAD);mean=newArray(nAD); intDen=newArray(nAD); time=newArray(ns);mtime=newArray(ns); for (i=0; i> Dialog.create("Time Activity Time Save Dialog"); Dialog.addChoice("This TAC_Graph Save as .xls file?",newArray("Save TAC", "No"),"Save TAC"); Dialog.addNumber("Decimal places (0-9)",4); //Dialog.addCheckbox("Save Area Data", false); Dialog.addCheckbox("Save Mean Data", false); Dialog.addCheckbox("Save Integrated Density Data", true); Dialog.addCheckbox("Save with ROIs File", true); Dialog.addMessage(""); Dialog.addCheckbox("Save TAC PNG File", true); Dialog.show(); ans = Dialog.getChoice(); dn = Dialog.getNumber(); //area_save=Dialog.getCheckbox(); mean_save=Dialog.getCheckbox(); intDen_save=Dialog.getCheckbox(); roi_save=Dialog.getCheckbox(); tacpng_save=Dialog.getCheckbox(); if (roi_save==0) print("ROIs_will not be saved."); if (ans == "No"){ exit(); } saveAs("Results",""); saveFileDir=File.directory; saveFileName=File.name; saveFilePath= saveFileDir +File.name; saveFileNameOnly=split(saveFileName,"."); setBatchMode(true); selectWindow("Results"); run("Close"); //<> roiManager("Select",indexesRoi); roiManager("Save",saveFileDir+"/"+saveFileNameOnly[0]+"_ROIs.zip"); f = File.open(saveFilePath); print(f,"##\tImage File Name = "+name); print(f,"##\tImage File Directory = "+dir); print(f,"##\tComment ="+comment); print(f,"##\tMeasurement date ="+mdate); print(f,"##\tPositron RI ="+positronRI); print(f,"##\tSaved ROI File = "+saveFileDir+""+saveFileNameOnly[0]+"_ROIs.zip"); //<> line=""; for (j=0; j> print(f,line); line="Frame"; line= line +"\tTime (sec)"; for (j=0; j> for (i=0; i> if (tacpng_save==1) saveAs("PNG", saveFileDir+"/"+saveFileNameOnly[0]+"_TACs.png"); } // (11) // This Function Add Color Bar at Leftside of Stack Image. function setColorBar() { name=getTitle(); width=getWidth(); height=getHeight(); frame=nSlices; getMinAndMax(min,max); Dialog.create("Color Bar"); Dialog.addChoice("Select",newArray("Add Color Bar", "Reset Color Bar", "Clear Color Bar"),"Add Color Bar"); Dialog.show(); ans = Dialog.getChoice(); if(ans == "Add Color Bar"){ tag = "Display range"; str=getTag(tag); range=split(str," "); lower=0+range[0]; upper=0+range[2]; new_width=width+10; run("Canvas Size...", "width="+new_width+" height="+height+" position=Center-Right zero"); for (k=1;k<=frame;k++){ setSlice(k); pixel_count=newArray(height); for (j=0;j1){ title = getTitle(); Dialog.create("Select Target Image"); Dialog.addMessage("Target Images is "+title); Dialog.show(); selectWindow(title); } else if (nImages==1){ title = getTitle(); selectWindow(title); } else if (nImages==0){ open(""); } ////2. Read Image Informations////// depth=nSlices; name = getTitle(); if(lengthOf(name)>4) title = substring(name,0,lengthOf(name)-4); else title = name; tag="PETIS Comment"; comment="PETIS Comment:"+getTag(tag); tag="PETIS Measurement Date"; PETIS_date="PETIS Measurement Date:"+getTag(tag); tag="PETIS Positron RI"; PETIS_RI="PETIS Positron RI:"+getTag(tag); tag="PETIS Blank"; PETIS_Blank="PETIS Blank:"+getTag(tag); tag="Frame interval"; str=getTag(tag); PETIS_Period="PETIS Stack Image Frame Interval:"+str; ////3. Make Montage Image////// rows = floor(depth / 5); Dialog.create("Make Montage with PETIS Images"); Dialog.addMessage("This Stack Image has "+depth+" frames."); Dialog.addNumber("columns", 5); Dialog.addNumber("rows", rows); Dialog.addNumber("first frame", 1); Dialog.addNumber("last frame", depth); Dialog.addNumber("border", 2); Dialog.show(); columns = Dialog.getNumber(); rows = Dialog.getNumber(); first = Dialog.getNumber(); last = Dialog.getNumber(); boader = Dialog.getNumber(); run("Make Montage...", "columns="+columns+" rows="+rows+" scale=1 first="+first+" last="+last+" increment=1 border="+boader+""); PETIS_header = "Info:"+comment+"\n"+PETIS_date+"\n"+PETIS_RI+"\n"+PETIS_Blank+"\n"+PETIS_Period; setMetadata(PETIS_header); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // This function returns the PETIS Header Value of the specified // tag (e.g., "Measurement period") as a string. Returns "" if the tag is not found. function getTagPETIS(headerfile,tag) { header = File.openAsString(headerfile); index1 = indexOf(header,tag); if (index1 == -1) return ""; index1 = indexOf(header, ":", index1); if (index1 == -1) return ""; index2 = indexOf(header, "\n", index1); value = substring(header, index1+1, index2); return value; } // This function returns the value of the specified // tag (e.g., "Depth") as a string. Returns "" if the tag is not found. function getTag(tag) { info = getImageInfo(); index1 = indexOf(info, tag); if (index1==-1) return ""; index1 = indexOf(info, ":", index1); if (index1==-1) return ""; index2 = indexOf(info, "\n", index1); value = substring(info, index1+1, index2); return value; } // This function returns the value of the specified // tag (e.g., "Depth") as a string. Returns "" if the tag is not found. function getTag2(tag) { info = getImageInfo(); index1 = indexOf(info, tag); if (index1==-1) return ""; index1 = indexOf(info, "(", index1); if (index1==-1) return ""; index2 = indexOf(info, ")", index1); value = substring(info, index1+1, index2); return value; } // This function returns the value of the frame number (in info, Slice: 1/xxxx) // as a string. Returns "" if the frame number is not found. function getFrame(tag) { info = getImageInfo(); index1 = indexOf(info, tag); if (index1==-1) return ""; index1 = indexOf(info, "/", index1); if (index1==-1) return ""; index2 = indexOf(info, "\n", index1); value = substring(info, index1+1, index2); return value; } function getMin(array){ n=lengthOf(array); minValue=array[0]; for (i=0; i array[i]) { minValue=array[i]; } } return minValue; } function getMax(array){ n=lengthOf(array); maxValue=array[0]; for (i=0; i