Package ij.measure

Examples of ij.measure.Calibration


    }
    if (stack!=null) {
      imp = new ImagePlus("Imported Stack", stack);
      if (imp.getBitDepth()==16 || imp.getBitDepth()==32)
        imp.getProcessor().setMinAndMax(min, max);
                Calibration cal = imp.getCalibration();
                if (fi.fileType==FileInfo.GRAY16_SIGNED)
                  cal.setSigned16BitCalibration();
      imp.show();
    }
  }
View Full Code Here


      "Are you sure you want to convert this\nstack to "
      +size+" separate windows?");
      if (!ok)
        {imp.unlock(); return;}
    }
    Calibration cal = imp.getCalibration();
    CompositeImage cimg = imp.isComposite()?(CompositeImage)imp:null;
    if (imp.getNChannels()!=imp.getStackSize()) cimg = null;
    for (int i=1; i<=size; i++) {
      String label = stack.getShortSliceLabel(i);
      String title = label!=null&&!label.equals("")?label:getTitle(imp, i);
View Full Code Here

    if (IJ.debugMode) IJ.log("FolderOpener: "+directory+" ("+list.length+" files)");
    int width=0, height=0, stackSize=1, bitDepth=0;
    ImageStack stack = null;
    double min = Double.MAX_VALUE;
    double max = -Double.MAX_VALUE;
    Calibration cal = null;
    boolean allSameCalibration = true;
    IJ.resetEscape();   
    try {
      for (int i=0; i<list.length; i++) {
        IJ.redirectErrorMessages();
        ImagePlus imp = (new Opener()).openImage(directory, list[i]);
        if (imp!=null) {
          width = imp.getWidth();
          height = imp.getHeight();
          bitDepth = imp.getBitDepth();
          fi = imp.getOriginalFileInfo();
          if (arg==null) {
            if (!showDialog(imp, list))
              return;
          } else {
            n = list.length;
            start = 1;
            increment = 1;
          }
          break;
        }
      }
      if (width==0) {
        IJ.error("Import Sequence", "This folder does not appear to contain any TIFF,\n"
        + "JPEG, BMP, DICOM, GIF, FITS or PGM files.");
        return;
      }

      if (filter!=null && (filter.equals("") || filter.equals("*")))
        filter = null;
      if (filter!=null) {
        int filteredImages = 0;
          for (int i=0; i<list.length; i++) {
          if (isRegex&&list[i].matches(filter))
            filteredImages++;
          else if (list[i].indexOf(filter)>=0)
            filteredImages++;
           else
             list[i] = null;
         }
          if (filteredImages==0) {
            if (isRegex)
              IJ.error("Import Sequence", "None of the file names match the regular expression.");
            else
               IJ.error("Import Sequence", "None of the "+list.length+" files contain\n the string '"+filter+"' in their name.");
           return;
          }
          String[] list2 = new String[filteredImages];
          int j = 0;
          for (int i=0; i<list.length; i++) {
           if (list[i]!=null)
             list2[j++] = list[i];
         }
          list = list2;
        }
      if (sortFileNames)
        list = sortFileList(list);

      if (n<1)
        n = list.length;
      if (start<1 || start>list.length)
        start = 1;
      if (start+n-1>list.length)
        n = list.length-start+1;
      int count = 0;
      int counter = 0;
      ImagePlus imp = null;
      for (int i=start-1; i<list.length; i++) {
        if ((counter++%increment)!=0)
          continue;
        Opener opener = new Opener();
        opener.setSilentMode(true);
        IJ.redirectErrorMessages();
        if (!openAsVirtualStack||stack==null)
          imp = opener.openImage(directory, list[i]);
        if (imp!=null && stack==null) {
          width = imp.getWidth();
          height = imp.getHeight();
          stackSize = imp.getStackSize();
          bitDepth = imp.getBitDepth();
          cal = imp.getCalibration();
          if (convertToRGB) bitDepth = 24;
          ColorModel cm = imp.getProcessor().getColorModel();
          if (openAsVirtualStack) {
            stack = new VirtualStack(width, height, cm, directory);
            ((VirtualStack)stack).setBitDepth(bitDepth);
          } else if (scale<100.0)           
            stack = new ImageStack((int)(width*scale/100.0), (int)(height*scale/100.0), cm);
          else
            stack = new ImageStack(width, height, cm);
          info1 = (String)imp.getProperty("Info");
        }
        if (imp==null)
          continue;
        if (imp.getWidth()!=width || imp.getHeight()!=height) {
          IJ.log(list[i] + ": wrong size; "+width+"x"+height+" expected, "+imp.getWidth()+"x"+imp.getHeight()+" found");
          continue;
        }
        String label = imp.getTitle();
        if (stackSize==1) {
          String info = (String)imp.getProperty("Info");
          if (info!=null)
            label += "\n" + info;
        }
        if (imp.getCalibration().pixelWidth!=cal.pixelWidth)
          allSameCalibration = false;
        ImageStack inputStack = imp.getStack();
        for (int slice=1; slice<=stackSize; slice++) {
          ImageProcessor ip = inputStack.getProcessor(slice);
          String label2 = label;
          if (stackSize>1) {
            String sliceLabel = inputStack.getSliceLabel(slice);
            if (sliceLabel!=null)
              label2=sliceLabel;
            else if (label2!=null && !label2.equals(""))
              label2 += ":"+slice;
          }
          int bitDepth2 = imp.getBitDepth();
          if (!openAsVirtualStack) {
            if (convertToRGB) {
              ip = ip.convertToRGB();
              bitDepth2 = 24;
            }
            if (bitDepth2!=bitDepth) {
              if (bitDepth==8) {
                ip = ip.convertToByte(true);
                bitDepth2 = 8;
              } else if (bitDepth==24) {
                ip = ip.convertToRGB();
                bitDepth2 = 24;
              }
            }
            if (bitDepth2!=bitDepth) {
              IJ.log(list[i] + ": wrong bit depth; "+bitDepth+" expected, "+bitDepth2+" found");
              break;
            }
          }
          if (slice==1) count++;
          IJ.showStatus(count+"/"+n);
          IJ.showProgress(count, n);
          if (scale<100.0)
            ip = ip.resize((int)(width*scale/100.0), (int)(height*scale/100.0));
          if (ip.getMin()<min) min = ip.getMin();
          if (ip.getMax()>max) max = ip.getMax();
          //if (depth>1) label2 = null;
          if (openAsVirtualStack) {
            if (slice==1) ((VirtualStack)stack).addSlice(list[i]);
          } else
            stack.addSlice(label2, ip);
        }
        if (count>=n)
          break;
        if (IJ.escapePressed())
          {IJ.beep(); break;}
        //System.gc();
      }
    } catch(OutOfMemoryError e) {
      IJ.outOfMemory("FolderOpener");
      if (stack!=null) stack.trim();
    }
    if (stack!=null && stack.getSize()>0) {
      ImagePlus imp2 = new ImagePlus(title, stack);
      if (imp2.getType()==ImagePlus.GRAY16 || imp2.getType()==ImagePlus.GRAY32)
        imp2.getProcessor().setMinAndMax(min, max);
      if (fi==null)
        fi = new FileInfo();
      fi.fileFormat = FileInfo.UNKNOWN;
      fi.fileName = "";
      fi.directory = directory;
      imp2.setFileInfo(fi); // saves FileInfo of the first image
      if (allSameCalibration) {
        // use calibration from first image
        if (scale!=100.0 && cal.scaled()) {
          cal.pixelWidth /= scale/100.0;
          cal.pixelHeight /= scale/100.0;
        }
        if (cal.pixelWidth!=1.0 && cal.pixelDepth==1.0)
          cal.pixelDepth = cal.pixelWidth;
        if (cal.pixelWidth<=0.0001 && cal.getUnit().equals("cm")) {
          cal.pixelWidth *= 10000.0;
          cal.pixelHeight *= 10000.0;
          cal.pixelDepth *= 10000.0;
          cal.setUnit("um");
        }
        imp2.setCalibration(cal);
      }
      if (info1!=null && info1.lastIndexOf("7FE0,0010")>0) {
        stack = DicomTools.sort(stack);
View Full Code Here

  }
 
  /** Save the image as tab-delimited text using the specified path. */
  public boolean saveAsText(String path) {
    try {
      Calibration cal = imp.getCalibration();
      int precision = Analyzer.getPrecision();
      int measurements = Analyzer.getMeasurements();
      boolean scientificNotation = (measurements&Measurements.SCIENTIFIC_NOTATION)!=0;
      if (scientificNotation)
        precision = -precision;
View Full Code Here

    IJ.error("FileSaver", "An error occured writing the file.\n \n" + msg);
  }

  /** Returns a string containing information about the specified  image. */
  public String getDescriptionString() {
    Calibration cal = imp.getCalibration();
    StringBuffer sb = new StringBuffer(100);
    sb.append("ImageJ="+ImageJ.VERSION+"\n");
    if (fi.nImages>1 && fi.fileType!=FileInfo.RGB48)
      sb.append("images="+fi.nImages+"\n");
    int channels = imp.getNChannels();
    if (channels>1)
      sb.append("channels="+channels+"\n");
    int slices = imp.getNSlices();
    if (slices>1)
      sb.append("slices="+slices+"\n");
    int frames = imp.getNFrames();
    if (frames>1)
      sb.append("frames="+frames+"\n");
    if (imp.isHyperStack()) sb.append("hyperstack=true\n");
    if (imp.isComposite()) {
      String mode = ((CompositeImage)imp).getModeAsString();
      sb.append("mode="+mode+"\n");
    }
    if (fi.unit!=null)
      sb.append("unit="+(fi.unit.equals("\u00B5m")?"um":fi.unit)+"\n");
    if (fi.valueUnit!=null && fi.calibrationFunction!=Calibration.CUSTOM) {
      sb.append("cf="+fi.calibrationFunction+"\n");
      if (fi.coefficients!=null) {
        for (int i=0; i<fi.coefficients.length; i++)
          sb.append("c"+i+"="+fi.coefficients[i]+"\n");
      }
      sb.append("vunit="+fi.valueUnit+"\n");
      if (cal.zeroClip()) sb.append("zeroclip=true\n");
    }
   
    // get stack z-spacing and fps
    if (cal.frameInterval!=0.0) {
      if ((int)cal.frameInterval==cal.frameInterval)
        sb.append("finterval="+(int)cal.frameInterval+"\n");
      else
        sb.append("finterval="+cal.frameInterval+"\n");
    }
    if (!cal.getTimeUnit().equals("sec"))
      sb.append("tunit="+cal.getTimeUnit()+"\n");
    if (fi.nImages>1) {
      if (fi.pixelDepth!=0.0 && fi.pixelDepth!=1.0)
        sb.append("spacing="+fi.pixelDepth+"\n");
      if (cal.fps!=0.0) {
        if ((int)cal.fps==cal.fps)
View Full Code Here

  public static void setMinAndMax(double min, double max, int channels) {
    setMinAndMax(getImage(), min, max, channels);
  }

  private static void setMinAndMax(ImagePlus img, double min, double max, int channels) {
    Calibration cal = img.getCalibration();
    min = cal.getRawValue(min);
    max = cal.getRawValue(max);
    if (channels==7)
      img.setDisplayRange(min, max);
    else
      img.setDisplayRange(min, max, channels);
    img.updateAndDraw();
View Full Code Here

      else if (displayMode.indexOf("over")!=-1)
        mode = ImageProcessor.OVER_UNDER_LUT;
      else if (displayMode.indexOf("no")!=-1)
        mode = ImageProcessor.NO_LUT_UPDATE;
    }
    Calibration cal = img.getCalibration();
    lowerThreshold = cal.getRawValue(lowerThreshold);
    upperThreshold = cal.getRawValue(upperThreshold);
    img.getProcessor().setThreshold(lowerThreshold, upperThreshold, mode);
    if (mode != ImageProcessor.NO_LUT_UPDATE) {
      img.getProcessor().setLutAnimation(true);
      img.updateAndDraw();
    }
View Full Code Here

  ImagePlus doOperation(ImagePlus img1, ImagePlus img2) {
    ImagePlus img3 = null;
    int mode = getBlitterMode();
    ImageProcessor ip1 = img1.getProcessor();
    ImageProcessor ip2 = img2.getProcessor();
    Calibration cal1 = img1.getCalibration();
    Calibration cal2 = img2.getCalibration();
    if (createWindow)
      ip1 = createNewImage(ip1, ip2);
    else {
      ImageWindow win = img1.getWindow();
      if (win!=null)
View Full Code Here

    }
    return mode;
  }
 
  ImagePlus duplicateStack(ImagePlus img1) {
    Calibration cal = img1.getCalibration();
    ImageStack stack1 = img1.getStack();
    int width = stack1.getWidth();
    int height = stack1.getHeight();
    int n = stack1.getSize();
    ImageStack stack2 = img1.createEmptyStack();
    try {
      for (int i=1; i<=n; i++) {
        ImageProcessor ip1 = stack1.getProcessor(i);
        ip1.resetRoi();
        ImageProcessor ip2 = ip1.crop();
        if (floatResult) {
          ip2.setCalibrationTable(cal.getCTable());
          ip2 = ip2.convertToFloat();
        }
        stack2.addSlice(stack1.getSliceLabel(i), ip2);
      }
    }
View Full Code Here

  /** Returns the perimeter length. */
  public double getLength() {
    double pw=1.0, ph=1.0;
    if (imp!=null) {
      Calibration cal = imp.getCalibration();
      pw = cal.pixelWidth;
      ph = cal.pixelHeight;
    }
    return Math.PI*(width*pw+height*ph)/2.0;
  }
 
View Full Code Here

TOP

Related Classes of ij.measure.Calibration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.