/* This macro calculates the distribution/space-filling indexes (H) of black pixels for each bitmap image of a set, grouped in a folder. H indexes are calculated through alternated convolutions of 3x3 square and cross kernels. Two permeation curves are constructed starting with one or the other kernel and results are interpolated to obtain index values. The macro is limited to the analysis of images with H indexes lower than 500. The percentage of initial black pixels is calculated for every image (binary - inverted LUT) of the folder and the maximal value obtained is set as the normalization value. The macro generates an output .txt file reporting the normalization value, initial area covered by black pixels together with raw and normalized H90%, H95% and H99% indexes. Version 1.1 date 07.03.2008 For theoretical background see M. Righi et al. Laboratory Investigation, 2009; 89(9), 1063-1070; doi:10.1038/labinvest.2009.76. A modification of this macro that analyzes multiple folders can be found at http://www.fcm.in.cnr.it/H-index/software.php Please contact author for full instructions. Author: M.Righi - Institute of Neuroscience, CNR - Milano - Italy. E-mail: m.righi@in.cnr.it */ macro "H distribution" {halo();} function halo() { requires("1.38a"); // Variable definitions Identificativo = "Calculting H indexes in folder v. 1.1 date 07.03.2008"; A = 0; P = newArray(500); N = 0.00; hh = 0; ww = 0; img = ""; // Automatic Time setup getDateAndTime(year, month, week, day, hour, min, sec, msec); mese = month+1; // Choosing the folder to be analyzed dir1 = getDirectory("Please select the folder with the images "); restit = File.getName(dir1); list = getFileList(dir1); dir2 = getDirectory("Where should I save the results?"); results=File.open(dir2+restit+".txt"); firstline = "Analyzed folder: "+dir1+"\nAt day: "+day+"."+mese+"."+year+" time: "+hour+":"+min+":"+sec+"\n\nMacro used: AutoNormFolderH.txt\n"; print(results, Identificativo); print(results, firstline); setBatchMode(true); for (i=0; i N) { N = P[j]; img = list[j]; } } print(results, "Normalization value = "+N+"\tdue to image: "+img+"\n\n"); newris="Image: \t\tArea: \tH90%: \tH95%: \tH99%: \tnH90%: \tnH95%: \tnH99%: \n"; print(results, newris); for (i=0; i 0) { while (P[k] < 99.5) { r++; k++; if (r>1) { r = 0; run("Convolve...", "text1=[1 1 1 1 1 1 1 1 1]"); } else { run("Convolve...", "text1=[0 1 0 1 1 1 0 1 0]"); } getStatistics(area, mean, min, max, std, histogram); B = histogram[255]; if (k < 500) { P[k] = 100*B/area; } else { P[k] = 100; } } // Calculating interpolations for (j=0; j90) { while (H1 == false) { H90 = (l-1)+(90-S[l-1])/(S[l]-S[l-1]); H1 = true; } } } for (l=1; l<499; l++) { if (S[l]>95) { while (H2 == false) { H95 = (l-1)+(95-S[l-1])/(S[l]-S[l-1]); H2 = true; } } } for (l=1; l<499; l++) { if (S[l]>99) { while (H3 == false) { H99 = (l-1)+(99-S[l-1])/(S[l]-S[l-1]); H3 = true; } } } if (H1 == false) { H90 = 500; } if (H2 == false) { H95 = 500; } if (H3 == false) { H99 = 500; } // Calculating normalized H indexes if (P[0] == N) { HN = 0; Norm = true; } if (P[0] < N) { for (l=1; l<499; l++) { if (S[l] > N) { while (H4 == false) { HN = (l-1)+(N-S[l-1])/(S[l]-S[l-1]); H4 = true; } } } Norm = true; } if (H4 == false) { HN = 0; } // Output raw and normalized H indexes if (Norm == true) { nH90 = H90-HN; nH95 = H95-HN; nH99 = H99-HN; print(results, list[i]+"\t\t"+P[0]+"\t"+H90+"\t"+H95+"\t"+H99+"\t"+nH90+"\t"+nH95+"\t"+nH99+"\n"); } else { print(results, list[i]+"\t\t"+P[0]+"\t"+H90+"\t"+H95+"\t"+H99+"\tWARNING! Normalized area value lower than initial value!\n"); } } else { hh = getHeight(); ww = getWidth(); if (hh > ww) { print(results, list[i]+"\t\t"+P[0]+"\t"+hh+"\t"+hh+"\t"+hh+"\t"+hh+"\t"+hh+"\t"+hh+"\n"); } else { print(results, list[i]+"\t\t"+P[0]+"\t"+ww+"\t"+ww+"\t"+ww+"\t"+ww+"\t"+ww+"\t"+ww+"\n"); } } close(); } // Closing output file and ending macro getDateAndTime(year, month, week, day, ora, minuto, secondo, msec); mese = month+1; lastline = "\n\nEnd of analysis at day: "+day+"."+mese+"."+year+" time: "+ora+":"+minuto+":"+secondo+"\n"; print(results, lastline); File.close(results); setBatchMode(false); showMessage("End of Analysis"); }