/*Makes unbiased counting frame as non-destructive overlay and calculates disector volume. "Number of frames" determines how many frames are drawn. "Frames area" determines the size of frames. "Central point" used to decide does the frame belong to the reference space. "Disector volume" calculates the volume of disector probe when scale and distance between sections are set. Anything that touches "Forbidden line" should be excluded from count. Anything that touches "Acceptance line" should be included into count. Objects in frames that are out of reference space are counted but the area(volume) of these frames are not included into the final estimation. Parameters of the grid are reflected in the "Frame(s) Parameters" window. Version: 1.0 Date: 04/09/2014 Author: Aleksandr Mironov amj-box@mail.ru */ requires("1.46b"); //help html = "" +"

Unbiased Counting Frame(s)

" +"used to count number of objects in the area or the volume

" +"based on Gundersen HJG (J.Microsc. 1977, 111:219-223)

" +"Options:

" +"Number of frames - determines how many frames are drawn
" +"Random Offset - randomizes frame location
" +"New Overlay - removes previous overlays
" +"Central point - used to decide does the frame belong to the reference space
" +"Calculate Disector Volume - calculates the volume of disector probe when scale
" +"and distance between sections are set

" +"Set Scale to get correct printout of the grid parameters,
" +"which are reflected in the 'Frame(s) Parameters' window

" +"Counting rules:

" +"Anything that touches Forbidden line should be excluded from count
" +"Anything that touches Acceptance line should be included into count

" +"Objects in frames that are out of reference space are counted but the area(volume)
" +"of these frames are not included into the final estimation.

" //Creating dialog box Dialog.create("Unbiased Counting Frame(s), ver. 1.0"); Dialog.addNumber("Number of frames in X =", 1); Dialog.addNumber("Number of frames in Y =", 1); Dialog.addNumber("Frame(s) area =", 50,0,2,"% of image area"); Dialog.addNumber("Line width =", 2,0,2,"pixels"); Dialog.addCheckbox("Random Offset", true); Dialog.addCheckbox("New Overlay", true); Dialog.addCheckbox("Central Point", true); Dialog.addCheckbox("Calculate Disector Volume", false); Dialog.addChoice("Forbidden line:", newArray("red", "green", "cyan", "magenta", "blue", "yellow", "orange", "black", "white")); Dialog.addChoice("Acceptance line:", newArray("green", "red", "cyan", "magenta", "blue", "yellow", "orange", "black", "white")); Dialog.addHelp(html); Dialog.show(); //frame dimensions name = getTitle(); nx = Dialog.getNumber(); ny = Dialog.getNumber(); pct = Dialog.getNumber(); t = Dialog.getNumber(); t1 = t/2; a = getWidth(); b = getHeight(); a1 = a*sqrt(pct/100); b1 = b*sqrt(pct/100); a2 = a1/nx; b2 = b1/ny; //creating random offset r1 = random; r2 = random; offset = Dialog.getCheckbox(); if (offset == false) r1 = r2 = 0.5; x = (a - a1)/(nx+1); y = (b - b1)/(ny+1); xr = x*r1; yr = y*r2; new = Dialog.getCheckbox(); if (new == true) run("Remove Overlay"); point = Dialog.getCheckbox(); //getting colour c1 = Dialog.getChoice(); c2 = Dialog.getChoice(); //initial coordinates X; x1 = xr+x/2; x2 = a2+x1; x4 = x1+a2/2; x5 = x4 - a2/30; x6 = x4 + a2/30; //X loop; for (i=0; i