<p>
Returns the sum of all the pixels in the image across all bands.
</p>

@param input Input image. Not modified.
@return Sum of pixel intensity values
429424
public static double sum( ImageBase input ) {

		if( input instanceof ImageGray) {
			if (GrayU8.class == input.getClass()) {
				return ImageStatistics.sum((GrayU8) input);
			} else if (GrayS8.class == input.getClass()) {
				return ImageStatistics.sum((GrayS8) input);
			} else if (GrayU16.class == input.getClass()) {
				return ImageStatistics.sum((GrayU16) input);
			} else if (GrayS16.class == input.getClass()) {
				return ImageStatistics.sum((GrayS16) input);
			} else if (GrayS32.class == input.getClass()) {
				return ImageStatistics.sum((GrayS32) input);
			} else if (GrayS64.class == input.getClass()) {
				return ImageStatistics.sum((GrayS64) input);
			} else if (GrayF32.class == input.getClass()) {
				return ImageStatistics.sum((GrayF32) input);
			} else if (GrayF64.class == input.getClass()) {
				return ImageStatistics.sum((GrayF64) input);
			} else {
				throw new IllegalArgumentException("Unknown image Type");
			}
		} else if( input instanceof ImageInterleaved ) {
			if (InterleavedU8.class == input.getClass()) {
				return ImageStatistics.sum((InterleavedU8) input);
			} else if (InterleavedS8.class == input.getClass()) {
				return ImageStatistics.sum((InterleavedS8) input);
			} else if (InterleavedU16.class == input.getClass()) {
				return ImageStatistics.sum((InterleavedU16) input);
			} else if (InterleavedS16.class == input.getClass()) {
				return ImageStatistics.sum((InterleavedS16) input);
			} else if (InterleavedS32.class == input.getClass()) {
				return ImageStatistics.sum((InterleavedS32) input);
			} else if (InterleavedS64.class == input.getClass()) {
				return ImageStatistics.sum((InterleavedS64) input);
			} else if (InterleavedF32.class == input.getClass()) {
				return ImageStatistics.sum((InterleavedF32) input);
			} else if (InterleavedF64.class == input.getClass()) {
				return ImageStatistics.sum((InterleavedF64) input);
			} else {
				throw new IllegalArgumentException("Unknown image Type");
			}
		} else if( input instanceof Planar ) {
			double sum = 0;
			Planar in = (Planar) input;
			for (int i = 0; i < in.getNumBands(); i++) {
				sum += sum( in.getBand(i));
			}
			return sum;
		} else {
			throw new IllegalArgumentException("Image type not yet supported "+input.getClass().getSimpleName());
		}
	}
401229
public FDistort input( ImageBase input ) {
		if( this.input == null || this.input.width != input.width || this.input.height != input.height ) {
			distorter = null;
		}
		this.input = input;
		inputType = input.getImageType();
		return this;
	}
146240
public static int[] getImageSize(InputStream input) throws IOException
    {
        try {
            ImageInputStream imageInput = ImageIO.createImageInputStream(input);
            BufferedImage image = ImageIO.read(imageInput);
            return new int[]{image.getWidth(), image.getHeight()};
        } finally {
            input.close();
        }
    }
654849
public static int sum( InterleavedS32 img ) {

		if( BoofConcurrency.USE_CONCURRENT ) {
			return ImplImageStatistics_MT.sum(img);
		} else {
			return ImplImageStatistics.sum(img);
		}
	}
123251
public static <T extends ImageGray<T>>
	void orderBandsIntoRGB(Planar<T> image , BufferedImage input ) {

		boolean swap = swapBandOrder(input);

		// Output formats are: RGB and RGBA

		if( swap ) {
			if( image.getNumBands() == 3 ) {
				int bufferedImageType = input.getType();
				if( bufferedImageType == BufferedImage.TYPE_3BYTE_BGR ||
						bufferedImageType == BufferedImage.TYPE_INT_BGR )
				{
					T tmp = image.getBand(0);
					image.bands[0] = image.getBand(2);
					image.bands[2] = tmp;
				}
			} else if( image.getNumBands() == 4 ) {
				T[] temp = (T[]) Array.newInstance(image.getBandType(),4);

				int bufferedImageType = input.getType();
				if( bufferedImageType == BufferedImage.TYPE_INT_ARGB ) {
					temp[0] = image.getBand(1);
					temp[1] = image.getBand(2);
					temp[2] = image.getBand(3);
					temp[3] = image.getBand(0);
				} else if( bufferedImageType == BufferedImage.TYPE_4BYTE_ABGR ) {
					temp[0] = image.getBand(3);
					temp[1] = image.getBand(2);
					temp[2] = image.getBand(1);
					temp[3] = image.getBand(0);
				}

				image.bands[0] = temp[0];
				image.bands[1] = temp[1];
				image.bands[2] = temp[2];
				image.bands[3] = temp[3];
			}
		}
	}
1278456
public void process( GrayF32 input ) {

		scaleSpace.initialize(input);
		detections.reset();

		do {
			// scale from octave to input image
			pixelScaleToInput = scaleSpace.pixelScaleCurrentToInput();

			// detect features in the image
			for (int j = 1; j < scaleSpace.getNumScales()+1; j++) {

				// not really sure how to compute the scale for features found at a particular DoG image
				// using the average resulted in less visually appealing circles in a test image
				sigmaLower  = scaleSpace.computeSigmaScale( j - 1);
				sigmaTarget = scaleSpace.computeSigmaScale( j    );
				sigmaUpper  = scaleSpace.computeSigmaScale( j + 1);

				// grab the local DoG scale space images
				dogLower  = scaleSpace.getDifferenceOfGaussian(j-1);
				dogTarget = scaleSpace.getDifferenceOfGaussian(j  );
				dogUpper  = scaleSpace.getDifferenceOfGaussian(j+1);

				detectFeatures(j);
			}
		} while( scaleSpace.computeNextOctave() );
	}
972660
public void process(GrayF32 input ) {
		constructPyramid(input);

		corners.reset();

		// top to bottom. This way the intensity image is at the input image's scale. Which is useful
		// for visualiztion purposes
		double scale = Math.pow(2.0,pyramid.size()-1);
		for (int level = pyramid.size()-1; level >= 0; level--) {
			// find the corners
			detector.process(pyramid.get(level));

			// Add found corners to this level's list
			PyramidLevel featsLevel = featureLevels.get(level);

			FastQueue<ChessboardCorner> corners = detector.getCorners();
			featsLevel.corners.reset();
			for (int i = 0; i < corners.size; i++) {
				ChessboardCorner cf = corners.get(i);

				// convert the coordinate into input image coordinates
				double x = cf.x*scale;
				double y = cf.y*scale;
				// Compensate for how the pyramid was computed using an average down sample. It shifts
				// the coordinate system.
//				if( scale > 1 ) {
//					x += 0.5*scale;
//					y += 0.5*scale;
//				}

				ChessboardCorner cl = featsLevel.corners.grow();
				cl.first = true;
				cl.set(x,y,cf.orientation,cf.intensity);
			}
			scale /= 2.0;
		}

		// Create a combined set of features from all the levels. Only add each feature once by searching
		// for it in the next level down
		for (int levelIdx = 0; levelIdx < pyramid.size(); levelIdx++) {
			PyramidLevel level0 = featureLevels.get(levelIdx);

			// mark features in the next level as seen if they match ones in this level
			if( levelIdx+1< pyramid.size() ) {
				PyramidLevel level1 = featureLevels.get(levelIdx+1);
				markSeenAsFalse(level0.corners,level1.corners);
			}
		}

		for (int levelIdx = 0; levelIdx < pyramid.size(); levelIdx++) {
			PyramidLevel level = featureLevels.get(levelIdx);
			// only add corners if they were first seen in this level
			for (int i = 0; i < level.corners.size; i++) {
				ChessboardCorner c = level.corners.get(i);
				if( c.first )
					corners.grow().set(c);
			}
		}
	}
124557
static public double rastrigin(double[] x) {

    double sum = 0.0;

    for (int i = 0; i < x.length; i++) {
      sum += (x[i] * x[i]) - (10.0 * Math.cos(PIx2 * x[i])) + 10.0;
    }

    return (sum);
  }
853233
private static int computeHMargin( AbstractType input ) {

		int basis = MIN_H_MARGIN;
		if( input != null
				&& input.getName().length() > 17 ) {
			// Beyond 17 characters, we give 3 pixels for every new characters.
			basis += 3 * (input.getName().length() - 17);
		}

		return basis;
	}
1114189
public static <T extends ImageBase<T>> double meanDiffSq( T inputA , T inputB ) {

		if( inputA instanceof ImageGray) {
			if (GrayU8.class == inputA.getClass()) {
				return ImageStatistics.meanDiffSq((GrayU8) inputA, (GrayU8) inputB);
			} else if (GrayS8.class == inputA.getClass()) {
				return ImageStatistics.meanDiffSq((GrayS8) inputA, (GrayS8) inputB);
			} else if (GrayU16.class == inputA.getClass()) {
				return ImageStatistics.meanDiffSq((GrayU16) inputA, (GrayU16) inputB);
			} else if (GrayS16.class == inputA.getClass()) {
				return ImageStatistics.meanDiffSq((GrayS16) inputA, (GrayS16) inputB);
			} else if (GrayS32.class == inputA.getClass()) {
				return ImageStatistics.meanDiffSq((GrayS32) inputA, (GrayS32) inputB);
			} else if (GrayS64.class == inputA.getClass()) {
				return ImageStatistics.meanDiffSq((GrayS64) inputA, (GrayS64) inputB);
			} else if (GrayF32.class == inputA.getClass()) {
				return ImageStatistics.meanDiffSq((GrayF32) inputA, (GrayF32) inputB);
			} else if (GrayF64.class == inputA.getClass()) {
				return ImageStatistics.meanDiffSq((GrayF64) inputA, (GrayF64) inputB);
			} else {
				throw new IllegalArgumentException("Unknown image Type");
			}
		} else if( inputA instanceof ImageInterleaved ) {
			if (InterleavedU8.class == inputA.getClass()) {
				return ImageStatistics.meanDiffSq((InterleavedU8) inputA, (InterleavedU8) inputB);
			} else if (InterleavedS8.class == inputA.getClass()) {
				return ImageStatistics.meanDiffSq((InterleavedS8) inputA, (InterleavedS8) inputB);
			} else if (InterleavedU16.class == inputA.getClass()) {
				return ImageStatistics.meanDiffSq((InterleavedU16) inputA, (InterleavedU16) inputB);
			} else if (InterleavedS16.class == inputA.getClass()) {
				return ImageStatistics.meanDiffSq((InterleavedS16) inputA, (InterleavedS16) inputB);
			} else if (InterleavedS32.class == inputA.getClass()) {
				return ImageStatistics.meanDiffSq((InterleavedS32) inputA, (InterleavedS32) inputB);
			} else if (InterleavedS64.class == inputA.getClass()) {
				return ImageStatistics.meanDiffSq((InterleavedS64) inputA, (InterleavedS64) inputB);
			} else if (InterleavedF32.class == inputA.getClass()) {
				return ImageStatistics.meanDiffSq((InterleavedF32) inputA, (InterleavedF32) inputB);
			} else if (InterleavedF64.class == inputA.getClass()) {
				return ImageStatistics.meanDiffSq((InterleavedF64) inputA, (InterleavedF64) inputB);
			} else {
				throw new IllegalArgumentException("Unknown image Type");
			}
		} else if( inputA instanceof Planar ) {
			double mean = 0;
			Planar inA = (Planar) inputA;
			Planar inB = (Planar) inputB;
			for (int i = 0; i < inA.getNumBands(); i++) {
				mean += meanDiffSq( inA.getBand(i), inB.getBand(i));
			}
			return mean/inA.getNumBands();
		} else {
			throw new IllegalArgumentException("Image type not yet supported "+inputA.getClass().getSimpleName());
		}
	}
912762
public static <T extends ImageGray<T>> double variance(T input , double mean ) {

		if( GrayU8.class == input.getClass() ) {
			return ImageStatistics.variance((GrayU8)input,mean);
		} else if( GrayS8.class == input.getClass() ) {
			return ImageStatistics.variance((GrayS8)input,mean);
		} else if( GrayU16.class == input.getClass() ) {
			return ImageStatistics.variance((GrayU16)input,mean);
		} else if( GrayS16.class == input.getClass() ) {
			return ImageStatistics.variance((GrayS16)input,mean);
		} else if( GrayS32.class == input.getClass() ) {
			return ImageStatistics.variance((GrayS32)input,mean);
		} else if( GrayS64.class == input.getClass() ) {
			return ImageStatistics.variance((GrayS64)input,mean);
		} else if( GrayF32.class == input.getClass() ) {
			return ImageStatistics.variance((GrayF32)input,(float)mean);
		} else if( GrayF64.class == input.getClass() ) {
			return ImageStatistics.variance((GrayF64)input,mean);
		} else {
			throw new IllegalArgumentException("Unknown image Type");
		}
	}
855063
public static BufferedImage readQuietly(final InputStream input)
	{
		BufferedImage img = null;
		try
		{
			img = ImageIO.read(input);
		}
		catch (IOException e)
		{
			log.log(Level.SEVERE, "Reading image failed.", e);
		}
		return img;
	}
1296443
public static <T extends ImageBase<T>> void abs( T input , T output )
	{
		if( input instanceof ImageGray) {
			if (GrayS8.class == input.getClass()) {
				PixelMath.abs((GrayS8) input, (GrayS8) output);
			} else if (GrayS16.class == input.getClass()) {
				PixelMath.abs((GrayS16) input, (GrayS16) output);
			} else if (GrayS32.class == input.getClass()) {
				PixelMath.abs((GrayS32) input, (GrayS32) output);
			} else if (GrayS64.class == input.getClass()) {
				PixelMath.abs((GrayS64) input, (GrayS64) output);
			} else if (GrayF32.class == input.getClass()) {
				PixelMath.abs((GrayF32) input, (GrayF32) output);
			} else if (GrayF64.class == input.getClass()) {
				PixelMath.abs((GrayF64) input, (GrayF64) output);
			}
			// otherwise assume it is an unsigned image type
		} else if( input instanceof ImageInterleaved ) {
			if (InterleavedS8.class == input.getClass()) {
				PixelMath.abs((InterleavedS8) input, (InterleavedS8) output);
			} else if (InterleavedS16.class == input.getClass()) {
				PixelMath.abs((InterleavedS16) input, (InterleavedS16) output);
			} else if (InterleavedS32.class == input.getClass()) {
				PixelMath.abs((InterleavedS32) input, (InterleavedS32) output);
			} else if (InterleavedS64.class == input.getClass()) {
				PixelMath.abs((InterleavedS64) input, (InterleavedS64) output);
			} else if (InterleavedF32.class == input.getClass()) {
				PixelMath.abs((InterleavedF32) input, (InterleavedF32) output);
			} else if (InterleavedF64.class == input.getClass()) {
				PixelMath.abs((InterleavedF64) input, (InterleavedF64) output);
			}
		} else {
			Planar in = (Planar)input;
			Planar out = (Planar)output;

			for (int i = 0; i < in.getNumBands(); i++) {
				abs(in.getBand(i),out.getBand(i));
			}
		}
	}
1270377
public double sum() {
        double sum = 0;
        TIntDoubleIterator iter = edges.iterator();
        while (iter.hasNext()) {
            iter.advance();
            sum += iter.value();
        }
        return sum;
    }
603542
function(pixels, data) {
    const pixel = pixels[0];
    const value = vgi(pixel);
    summarize(value, data.counts);
    if (value >= data.threshold) {
      pixel[0] = 0;
      pixel[1] = 255;
      pixel[2] = 0;
      pixel[3] = 128;
    } else {
      pixel[3] = 0;
    }
    return pixel;
  }
1295533
@Override
    public ImageSource apply(ImageSource input) {
        int w = input.getWidth();
        int h = input.getHeight();

        MatrixSource output = new MatrixSource(w, h);

        Vector3 s = new Vector3(1, 0, 0);
        Vector3 t = new Vector3(0, 1, 0);

        for (int y = 0; y < h; y++) {
            for (int x = 0; x < w; x++) {

                if (x < border || x == w - border || y < border || y == h - border) {
                    output.setRGB(x, y, VectorHelper.Z_NORMAL);
                    continue;
                }

                float dh = input.getR(x + 1, y) - input.getR(x - 1, y);
                float dv = input.getR(x, y + 1) - input.getR(x, y - 1);

                s.set(scale, 0, dh);
                t.set(0, scale, dv);

                Vector3 cross = s.crs(t).nor();
                int rgb = VectorHelper.vectorToColor(cross);
                output.setRGB(x, y, rgb);
            }
        }

        return new MatrixSource(output);
    }
435605
@Override
	public void setInput( Input input ) {
		super.setInput(input);
		orientation.reshape(input.width,input.height);
		magnitude.reshape(input.width,input.height);

		computePixelFeatures();
	}