This plugin implement the Ryall sharpness index with array dimensions input
from 3 to any odd values to set by user. Cheers Lucena Reference: GOLDSMITH, N.T., Deep Focus; A digital Image Processing Technique to Produce Improved Focal Depth in Light Microscopy, Image Anal. Stereol. 19, 163-167, (2000). import ij.measure.*; import ij.*; import ij.plugin.*; import ij.plugin.filter.PlugInFilter; import ij.process.*; import ij.gui.*; import java.awt.*; import java.util.*; public class Depth_from_focus implements PlugIn{ public void run(String arg) { if (IJ.versionLessThan("1.19s")) return; ImagePlus imp = WindowManager.getCurrentImage(); if (imp==null) {IJ.noImage(); return;} if ( imp.getType()!=imp.GRAY8) {IJ.error("Stack with 8-bit grayscale image required"); return ;} GenericDialog gd=new GenericDialog ("Parameters of 3D-Reconstruction"); gd.addNumericField("Distance between slices:",1,3); //gd.addStringField("Unit:","µm"); gd.addNumericField("Dimension Kernel(square):",3,3); gd.showDialog(); if (gd.wasCanceled()) return ; int distance=(int) gd.getNextNumber(); //String unit=gd.getNextString();,unit,String unit int dimension=(int)gd.getNextNumber(); int uc =dimension/2; if (dimension!=(2*uc+1)||dimension<3){ IJ.showMessage("Invalid Dimension!\n"+ "Enter odd numbers equal or greater than 3"); return; } int vc =uc; Sharpnessindex(imp, imp.getProcessor(),distance,uc,vc); } public void Sharpnessindex (ImagePlus imp, ImageProcessor ip,int distance, int uc, int vc) { int width = ip.getWidth(); int height = ip.getHeight(); int ii,i,offset; float sharpness[] = new float[width * height]; float depthimage[]=new float[width * height]; byte[] pixels=new byte[width * height]; byte[] pixels2=new byte[width * height]; ImageWindow win = imp.getWindow(); win.running = true; int nSlices=imp.getStackSize(); long startTime = System.currentTimeMillis(); IJ.showStatus("Building the elevation and composite images..."); for (int s=1;s<=nSlices;s++) { IJ.showProgress((double)s/(nSlices)); if(!win.running)break; imp.setSlice(s); byte[] pixels1=(byte[])(ip.getPixels()); ii = 0; for (int y=0; y<height; y++) { offset = y*width; for(int x=0; x<width; x++) { i = offset+x; int pix = 0xff & pixels1[i]; // pixels2[ii] = (byte) pix; ii++; } } for(int y=vc; y<height-vc; y++) { for(int x=uc; x<width-uc; x++) { float sum = 0; for(int v=-vc; v <= vc; v++) { offset = x+(y+v)*width; for(int u = -uc; u <= uc; u++) { sum +=Math.abs(pixels2[offset+u]-pixels2[x+y*width]); } } if (sharpness[x+y*width]<sum){sharpness[x+y*width] = sum; depthimage[x+y*width]=(float) (s*distance); pixels[x+y*width]=pixels2[x+y*width]; } } } } long time = System.currentTimeMillis()-startTime; double seconds = time/1000.0; IJ.write("Reconstruction Time:"+IJ.d2s(seconds)+"seconds"); ImageProcessor ip2 = new ByteProcessor(width, height, pixels, null); ImagePlus imp2 = imp.createImagePlus(); imp2.setProcessor("Composite Image", ip2); ImageProcessor ip3 = new FloatProcessor(width, height, depthimage, null); ImagePlus imp3 = imp.createImagePlus(); imp3.setProcessor("Depth Image", ip3); imp2.show(); imp2.updateAndDraw(); imp3.show(); imp3.updateAndDraw(); } //End of rotine } |
Free forum by Nabble | Edit this page |