// Demo fill tesselation with minimum number of colours // Make Demo image with large number of ROIs in ROI Manager run("Close All"); newImage("RandomDots", "8-bit random", 512, 512, 1); randPicID=getImageID(); setThreshold(220,255);// random dots, tweak lower threshold to change number of ROIs setOption("BlackBackground", true); run("Convert to Mask"); run("Voronoi"); setThreshold(1,255); setOption("BlackBackground", true); run("Convert to Mask"); run("Invert"); initROIs=roiManager("count"); print ('original ROIs ',initROIs); run("Analyze Particles...", "add"); nfinalROIs=roiManager("count"); print (' final ',nfinalROIs); print ('original ROIs ',initROIs,' final ',nfinalROIs); // Intensity codes ROIs sequentially - Code NOT NEEDED fcol=1; for (n=nfinalROIs-1;n>=initROIs;n=n-1) { //print(n); roiManager('select',n); setForegroundColor(fcol, fcol,fcol); fcol=fcol+1; run("Fill", "slice"); if (fcol==256) fcol=1; } rename("Glasbey Inverted"); run("Select None"); roiManager("Show None"); run("glasbey inverted"); // Make new image with minimum set of non touching colours run("Select None"); newImage("MinColoured", "8-bit black", 512, 512, 1); selectImage("MinColoured"); // sequentially for each ROI for (n=nfinalROIs-1;n>=initROIs;n=n-1) { //print('ROI ',n); roiManager('select',n); run("Enlarge...", "enlarge=2");// expand ROI to cover adjacent ROIs getRawStatistics(npix,mea,min,max,std,histarray);// histogram holds the intensities adjacent ROIs // find the lowest unused intensity - of surrounding ROIs for (m=1; m<256;m++) { //print('colour loop ',m); // use <=2 to exclude diagonal connections if (histarray[m]<=2) { fcol=m;// lowest non zero intensity m=999;// crash out of loop } } roiManager('select',n);// back to unenlarged ROI setForegroundColor(fcol, fcol,fcol); run("Fill", "slice");// fill the ROI // wait(100); } rename("Min Colour"); run("Select None"); run("glasbey inverted"); print('all done'); -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html