Snippets
Created by
Dave Mason
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | // @string(label = "XY pixels", value = 256,persist=false) cubeDim // @string(label = "Pixel Size (um)", value = 0.1,persist=false) pixSize // @string(label = "Number of Features", min=1,value = 5,persist=false) numFeats // @string(label = "Feature Size (pixels)", value = 5,persist=false) featSize // @string(label = "Number of frames", value = 100,persist=false) timeFrames // @string(label = "Interval (s)", value = 0.1,persist=false) dT // @string(label = "Diffusion Coefficient (um^2/s)", value = 20,persist=false) Diffusion // @Boolean(label = "Avoid Edges?", description = "If checked, will not create spots within 10% of the edge", value = true,persist=false) avoidEdges // // // - Dave Mason [dnmason@liv.ac.uk] // - Centre for Cell Imaging [http://cci.liv.ac.uk] //-------------------------------------------------------------------------------- // CREATE BROWNIAN DATA FOR TEACHING TRACKING // setBatchMode(true); run("Options...", "iterations=1 count=1 black do=Nothing"); if (1==2){ //-- Set Cube dimension in pixels cubeDim=512; //-- What is the pixel size? pixSize=0.1; //--um/pixel //-- Number of features per slice: numFeats=15; //-- How big do you want the features in pixels? featSize=5; //-- How many time frames? timeFrames=500; //-- Movement Parameters //D=0.003; // um^2/s D=0.1; // pixels^2/s D=D/(pixSize*pixSize); // um^2/s dT=0.05; // s //dT=1; // s } cubeDim=parseFloat(cubeDim); pixSize=parseFloat(pixSize); numFeats=parseFloat(numFeats); featSize=parseFloat(featSize); timeFrames=parseFloat(timeFrames); dT=parseFloat(dT); D=parseFloat(D); k=sqrt(2*D*dT); //-- Make a new stack with identical x, y dimensions newImage("Tracks", "8-bit grayscale-mode", cubeDim, cubeDim, 1, 1, timeFrames); //-- Set foreground colour so points are drawn in white setForegroundColor(255, 255, 255); //-- Make an array to hold the values sX=newArray(timeFrames+1); sY=newArray(timeFrames+1); //-- For each particle make starting coordinates for (i=1;i<numFeats+1;i++){ setSlice(1); //-- Set starting coordinates and optionally bias middle of frame if (avoidEdges==true){ sX[1]=floor(random*(cubeDim*0.8))+(cubeDim*0.1); sY[1]=floor(random*(cubeDim*0.8))+(cubeDim*0.1); }else{ sX[1]=floor(random*cubeDim); sY[1]=floor(random*cubeDim); } //-- Draw in starting positions makeOval(sX[1], sY[1], featSize, featSize); //-- Draw the point into the image (using foreground colour) run("Draw", "slice"); //-- Deselect everything run("Select None"); //-- Make the track for (j=2;j<timeFrames+1;j++){ sX[j]=sX[j-1]+(k*randn()); sY[j]=sY[j-1]+(k*randn()); //-- Draw in features setSlice(j); //makeOval(round(sX[j]), round(sY[j]), featSize, featSize); makeOval(sX[j], sY[j], featSize, featSize); //-- Draw the point into the image (using foreground colour) run("Draw", "slice"); //-- Deselect everything run("Select None"); } // j loop (timepoints) //-- Fill the holes run("Fill Holes", "stack"); } // i loop (features) setSlice(1); //-- Do some post processing run("Gaussian Blur...", "sigma="+(featSize/2)+" stack"); run("Add Specified Noise...", "stack standard=10"); //-- Set the calibration to match the Motion Parameters run("Properties...", "unit=µm pixel_width="+pixSize+" pixel_height="+pixSize+" voxel_depth=1.0000000 frame=["+dT+" sec]"); //-- Print a summary to the log print("----------------------------------"); print("Image Properties:"); print("----------------------------------"); print("Dimensions: "+cubeDim); print("Pixel size: "+pixSize); print("Timeframes: "+timeFrames); print("Interval: "+dT+" s"); print("----------------------------------"); print(" Trajectory Properties:"); print("----------------------------------"); print("Creating "+numFeats+" features"); print("Feature size: "+featSize+" um"); print("Diffusion Coefficient: "+D+" um^2/s"); print("----------------------------------"); setBatchMode(false); //-- Functions function randn() { //-- Use the Box-Muller method to produce normally distributed random numbers U=random(); V=random(); return sqrt(-2*log(U))*cos(2*3.14*V); } |
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.