// Varve counter by Janne Jääskeläinen // Department of geology and mineralogy // University of Turku 2006 showStatus("Starting varveCounter"); // ImageJ requirements requires("1.34m"); // If "Log" window is open, we close it now... if (isOpen("Log")) { selectWindow("Log"); run("Close"); } // First we open dialog for user input. // User defines the smallest distance between different varves // (in pixels). width=512; height=512; Dialog.create("Varve counter"); Dialog.addNumber("Smallest distance between varves (in pixels):", 50); Dialog.addCheckbox("Show full result data", false); Dialog.addCheckbox("Show plot", false); Dialog.addCheckbox("Draw varves", true); Dialog.addNumber("Line thickness (in pixels):", 4); Dialog.show(); scope = Dialog.getNumber(); showFullData = Dialog.getCheckbox(); showPlot = Dialog.getCheckbox(); showVarves = Dialog.getCheckbox(); thick = Dialog.getNumber(); // Get profile and calculate the slope data in "Log" window profile = getProfile(); // Average values of x in the defined scope area xAvg = newArray(profile.length); // Average values of y in the defined scope area yAvg = newArray(profile.length); // y[i] - yAvg(in scope area) ySumma = newArray(profile.length); // x[i] - xAvg(in scope area) xSumma = newArray(profile.length); // (x[i] - xAvg(in scope area)) * (y[i] - yAvg(in scope area)) xy = newArray(profile.length); // (x[i] - xAvg(in scope area)) * (x[i] - xAvg(in scope area)) xx = newArray(profile.length); // [sigma(x[i] - xAvg(in scope area)) * (y[i] - yAvg(in scope area))] / // [sigma(x[i] - xAvg(in scope area)) * (x[i] - xAvg(in scope area))] slope = newArray(profile.length); // 0 or 1, depending on the sign of the slope ("+" or "-") slopeChange = newArray(profile.length); // if 0 followed 0 or 1 followed by 1, then 0, else 1. varveEstim = newArray(profile.length); showProgress(0.0); // Calculates average of x and y in the user defined scope area showStatus("Calculating slope data..."); for (i=0; i profile.length){amis = profile.length;} for (j=i; j< amis; j++){ xTotal += j; yTotal += profile[j]; } xAvg[i] = xTotal/scope; yAvg[i] = yTotal/scope; } showProgress(0.14); // Calculates "x[i] - xAvg(in scope area)" and "y[i] ? // yAvg(in scope area)". for (i=0; i profile.length){damis = profile.length;} for (j=i; j< damis; j++){ xySummis += xy[j]; xxSummis += xx[j]; } slope[i] = xySummis/xxSummis; } showProgress(0.42); // Now we can calculate from each slope parameter 0 or 1 (is it bigger // or smaler than zero). for (i=0; i