| 
					
	
	
	
	
				 | 
				
					
	
	 
		Hi All
  I've written a simple plugin to normalise pixel values, making a new 
 8-bit normalised copy of the original 16-bit DICOM image.
  When I try to run the plugin, IJ complains, saying that the image is 
 locked.  If I try to unlock it (Plugins->Utilities->Reset...), ImageJ 
 tells me that the image is not locked.  What can I change to make this 
 plugin work?
  Cheers
  Mike
  import ij.IJ;
 import ij.ImagePlus;
 import ij.gui.GenericDialog;
 import ij.process.ImageProcessor;
 import ij.process.ByteProcessor;
 import ij.plugin.filter.PlugInFilter;
  public class Normalise_Topo implements PlugInFilter {
         public int setup(String arg, ImagePlus img) {
                 return DOES_16 + DOES_8G;
         }
          public void run(ImageProcessor ip){
                 IJ.run("Invert");
                 int min = 4000; int max = 15000;
                 GenericDialog gd = new GenericDialog("Set Standards");
          gd.addNumericField("Al:",min,0);
          gd.addNumericField("Nylon:",max,0);
          gd.showDialog();
          if (gd.wasCanceled()) {
              IJ.error("PlugIn canceled!");
              return;
          }
          min = (int)gd.getNextNumber();
          max = (int)gd.getNextNumber();
                 int w = ip.getWidth();
                 int h = ip.getHeight();
                 int[] p = new int[w*h];
                 for (int y = 0; y<h; y++){
                         for (int x = 0; x<w; x++){
                                 p[y*w+x] = (ip.getPixel(x,y)-min)*255/(max-min);
                         }
                 }
                 IJ.run("close");
                 
                 ImageProcessor norm = new ByteProcessor(w,h);
                 for (int y = 0; y<h; y++){
                         for (int x = 0; x<w; x++){
                                 norm.putPixel(x,y, p[y*w+x]);
                         }
                 }
                 String title = "Normalised Image";
                 ImagePlus normIm = new ImagePlus(title, norm);
                 normIm.show();
         }
 }
 
	
	
	
	 
				 |