import ij.*; import ij.process.*; import ij.gui.*; import java.awt.*; import ij.plugin.filter.*; import ij.measure.ResultsTable; public class autoSplitSelect_DeFFT implements PlugInFilter { ImagePlus imp; public int setup(String arg, ImagePlus imp) { this.imp = imp; return DOES_ALL; } public void run(ImageProcessor ip) { int antal =4; int j, i = 1; int roiw, roih, noise=30; int roix, roiy =0; int countx, county =0; int line = 1; Roi myroi, fftroi= new Roi(0,0,10,10); ImagePlus impFFT, impInvFFT; ResultsTable svar; ip.setLineWidth(line); ip.setColor(Color.RED); ip.setFont(Font.decode("Arial-Bold-15")); IJ.run("Set Measurements...", "R Theta"); GenericDialog antalbox = new GenericDialog("Areas?"); antalbox.addNumericField("How many pieces?", 4, 0); antalbox.showDialog(); antal = (int) antalbox.getNextNumber(); roiw = ip.getWidth() / antal; roih = ip.getHeight() / antal; while (county < antal) { countx=0; roix=0; while (countx0) { j=1; while(j>0) { impFFT.setRoi(fftroi); new WaitForUserDialog("Title", "Draw rectangules around maxima, then click OK.").show(); fftroi=impFFT.getRoi(); IJ.run("Find Maxima...", "noise="+noise+" output=[Point Selection] [Exclude edge maxima] [Preview point selection]"); GenericDialog again = new GenericDialog("Klar?"); again.setCancelLabel("Scrap"); again.addMessage("Next area? change noise tolerence? or scrap this one and move on?"); again.enableYesNoCancel("Next", "Change"); again.centerDialog(false); again.setLocation(500, 500); again.showDialog(); if(again.wasCanceled()) { j=0; } else if (again.wasOKed()) { j=0; i=0; doFFT(impFFT, fftroi, noise, countx+antal*county, ResultsTable.getResultsTable()); impInvFFT=doInvFFT(impFFT, 0, countx+antal*county); WindowManager.setTempCurrentImage(imp); IJ.run("Add Image...", "x="+roix+" y="+roiy+" opacity=100"); impInvFFT.changes=false; impInvFFT.close(); } else { GenericDialog choose= new GenericDialog("Noise?"); choose.addNumericField("Enter new noise tolerence", noise, 0); choose.showDialog(); noise=(int) choose.getNextNumber(); j=1; } } } else { doFFT(impFFT, fftroi, noise, countx+antal*county, ResultsTable.getResultsTable()); impInvFFT=doInvFFT(impFFT, ResultsTable.getResultsTable().getCounter()-1, countx+antal*county); WindowManager.setTempCurrentImage(imp); IJ.run("Add Image...", "x="+roix+" y="+roiy+" opacity=100"); impInvFFT.changes=false; impInvFFT.close(); } impFFT.close(); ip.drawString(Integer.toString(countx+antal*county), roix+15, roiy+30); countx=countx+1; roix=roix+roiw; } roiy = roiy+roih; county=county+1; } ResultsTable.getResultsTable().show("Results"); new WaitForUserDialog("Title", "Färdig :-)").show(); } public void doFFT(ImagePlus imp4, Roi prevRoi, int noise2, int imgcount2, ResultsTable svar2) { imp4.setRoi(prevRoi); IJ.run("Find Maxima...", "noise="+noise2+" output=[Point Selection] [Exclude edge maxima] [Preview point selection]"); IJ.run("Measure"); svar2 = ResultsTable.getResultsTable(); svar2.addValue("number", (double) imgcount2); if(imgcount2==0) svar2.addValue("R", 0); svar2.updateResults(); } public ImagePlus doInvFFT(ImagePlus imp2, int rowcount, int imgcount) { imp2.getProcessor().setColor(Color.BLACK); imp2.getProcessor().fill(new Roi(0,0, imp2.getWidth(), imp2.getHeight())); imp2.getProcessor().setColor(Color.WHITE); IJ.run("Draw"); if(ResultsTable.getResultsTable().getValue("R", rowcount)!=0) { imp2.setRoi(new PointRoi(imp2.getWidth()/2, imp2.getHeight()/2)); IJ.run("Draw"); } IJ.run("Inverse FFT"); ImagePlus imp3 = WindowManager.getCurrentImage(); imp3.getProcessor().setFont(Font.decode("Arial-Bold-15")); imp3.getProcessor().setColor(Color.RED); imp3.getProcessor().drawString(Integer.toString(imgcount), 15, 30); imp.updateAndDraw(); imp2.changes=false; imp2.close(); return imp3; } }