boolean setThresholdLevels(ImagePlus imp, ImageProcessor ip) {
   double t1 = ip.getMinThreshold();
   double t2 = ip.getMaxThreshold();
   boolean invertedLut = imp.isInvertedLut();
   boolean byteImage = ip instanceof ByteProcessor;
   if (ip instanceof ShortProcessor) imageType = SHORT;
   else if (ip instanceof FloatProcessor) imageType = FLOAT;
   else imageType = BYTE;
   if (t1 == ImageProcessor.NO_THRESHOLD) {
     ImageStatistics stats = imp.getStatistics();
     if (imageType != BYTE || (stats.histogram[0] + stats.histogram[255] != stats.pixelCount)) {
       IJ.error(
           "Particle Analyzer",
           "A thresholded image or 8-bit binary image is\n"
               + "required. Threshold levels can be set using\n"
               + "the Image->Adjust->Threshold tool.");
       canceled = true;
       return false;
     }
     boolean threshold255 = invertedLut;
     if (Prefs.blackBackground) threshold255 = !threshold255;
     if (threshold255) {
       level1 = 255;
       level2 = 255;
       fillColor = 64;
     } else {
       level1 = 0;
       level2 = 0;
       fillColor = 192;
     }
   } else {
     level1 = t1;
     level2 = t2;
     if (imageType == BYTE) {
       if (level1 > 0) fillColor = 0;
       else if (level2 < 255) fillColor = 255;
     } else if (imageType == SHORT) {
       if (level1 > 0) fillColor = 0;
       else if (level2 < 65535) fillColor = 65535;
     } else if (imageType == FLOAT) fillColor = -Float.MAX_VALUE;
     else return false;
   }
   imageType2 = imageType;
   if (redirectIP != null) {
     if (redirectIP instanceof ShortProcessor) imageType2 = SHORT;
     else if (redirectIP instanceof FloatProcessor) imageType2 = FLOAT;
     else if (redirectIP instanceof ColorProcessor) imageType2 = RGB;
     else imageType2 = BYTE;
   }
   return true;
 }