<p>
Inverts the image's intensity:<br>
O<sub>x,y</sub> = max - I<sub>x,y</sub><br>
</p>

@param input  Input image. Not modified.
@param output If not null, the output image.  If null a new image is declared and returned.  Modified.
@return Output image.
512731
public static GrayF32 invert(GrayF32 input, float max , GrayF32 output) {
		output = InputSanityCheck.checkDeclare(input, output);

		ImplGrayImageOps.invert(input,max,output);

		return output;
	}
62438
public static GrayU8 invert(GrayU8 input , GrayU8 output)
	{
		output = InputSanityCheck.checkDeclare(input, output);

		if( BoofConcurrency.USE_CONCURRENT ) {
			ImplBinaryImageOps_MT.invert(input, output);
		} else {
			ImplBinaryImageOps.invert(input, output);
		}

		return output;
	}
1301630
public static void bufferDepthToU16( ByteBuffer input , GrayU16 output ) {
		int indexIn = 0;
		for( int y = 0; y < output.height; y++ ) {
			int indexOut = output.startIndex + y*output.stride;
			for( int x = 0; x < output.width; x++ , indexOut++ ) {
				output.data[indexOut] = (short)((input.get(indexIn++) & 0xFF) | ((input.get(indexIn++) & 0xFF) << 8 ));
			}
		}
	}
641
public static <T extends ImageBase<T>, O extends ImageBase>
	void add(T inputA, T inputB, O output) {
		if( inputA instanceof ImageGray) {
			if (GrayU8.class == inputA.getClass()) {
				PixelMath.add((GrayU8) inputA, (GrayU8) inputB, (GrayU16) output);
			} else if (GrayS8.class == inputA.getClass()) {
				PixelMath.add((GrayS8) inputA, (GrayS8) inputB, (GrayS16) output);
			} else if (GrayU16.class == inputA.getClass()) {
				PixelMath.add((GrayU16) inputA, (GrayU16) inputB, (GrayS32) output);
			} else if (GrayS16.class == inputA.getClass()) {
				PixelMath.add((GrayS16) inputA, (GrayS16) inputB, (GrayS32) output);
			} else if (GrayS32.class == inputA.getClass()) {
				PixelMath.add((GrayS32) inputA, (GrayS32) inputB, (GrayS32) output);
			} else if (GrayS64.class == inputA.getClass()) {
				PixelMath.add((GrayS64) inputA, (GrayS64) inputB, (GrayS64) output);
			} else if (GrayF32.class == inputA.getClass()) {
				PixelMath.add((GrayF32) inputA, (GrayF32) inputB, (GrayF32) output);
			} else if (GrayF64.class == inputA.getClass()) {
				PixelMath.add((GrayF64) inputA, (GrayF64) inputB, (GrayF64) output);
			} else {
				throw new IllegalArgumentException("Unknown image Type: " + inputA.getClass().getSimpleName());
			}
		} else if (inputA instanceof Planar) {
			Planar inA = (Planar)inputA;
			Planar inB = (Planar)inputB;
			Planar out = (Planar)output;

			for (int i = 0; i < inA.getNumBands(); i++) {
				add(inA.getBand(i),inB.getBand(i),out.getBand(i));
			}
		}
	}
1034672
public static void scaleDown2(GrayF32 input , GrayF32 output ) {
		
		output.reshape(input.width / 2, input.height / 2);

		for (int y = 0; y < output.height; y++) {
			int indexInput = 2*y*input.stride;
			int indexOutput = y*output.stride;
			for (int x = 0; x < output.width; x++,indexInput+=2) {
				output.data[indexOutput++] = input.data[indexInput];
			}
		}
	}
1340105
protected void imageToOutput( double x , double y , Point2D_F64 pt ) {
		pt.x = x/scale - tranX/scale;
		pt.y = y/scale - tranY/scale;
	}
344817
public void massage( T input , T output ) {
		if( clip ) {
			T inputAdjusted = clipInput(input, output);

			// configure a simple change in scale for both axises
			transform.a11 = input.width / (float) output.width;
			transform.a22 = input.height / (float) output.height;
			// this change is automatically reflected in the distortion class.  It is configured to cache nothing

			distort.apply(inputAdjusted, output);
		} else {
			// scale each axis independently.  It will have the whole image but it will be distorted
			transform.a11 = input.width / (float) output.width;
			transform.a22 = input.height / (float) output.height;

			distort.apply(input, output);
		}

	}
171060
public static <T extends ImageGray<T>>
	void scaleImageUp(T input , T output , int scale, InterpolatePixelS<T> interp ) {
		if( scale <= 1 )
			throw new IllegalArgumentException("Scale must be >= 2");
		if( input instanceof GrayF32) {
			ImplPyramidOps.scaleImageUp((GrayF32)input,(GrayF32)output,scale,(InterpolatePixelS)interp);
		} else if( input instanceof GrayU8) {
			ImplPyramidOps.scaleImageUp((GrayU8)input,(GrayU8)output,scale,(InterpolatePixelS)interp);
		} else {
			throw new IllegalArgumentException("Image type not yet supported");
		}
	}
327111
byte[] encodeLikeAnEngineer(final byte[] input) {

        if (input == null) {
            throw new NullPointerException("input");
        }

        final byte[] output = new byte[input.length << 1];

        int index = 0; // index in output
        for (int i = 0; i < input.length; i++) {
            output[index++] = (byte) encodeHalf((input[i] >> 4) & 0x0F);
            output[index++] = (byte) encodeHalf((input[i] & 0x0F));
        }

        return output;
    }
23420
public static void RGB_to_PLU8(Picture input, Planar<GrayU8> output) {
		if( input.getColor() != ColorSpace.RGB )
			throw new RuntimeException("Unexpected input color space!");
		if( output.getNumBands() != 3 )
			throw new RuntimeException("Unexpected number of bands in output image!");

		output.reshape(input.getWidth(),input.getHeight());

		int dataIn[] = input.getData()[0];

		GrayU8 out0 = output.getBand(0);
		GrayU8 out1 = output.getBand(1);
		GrayU8 out2 = output.getBand(2);

		int indexIn = 0;
		int indexOut = 0;
		for (int i = 0; i < output.height; i++) {
			for (int j = 0; j < output.width; j++, indexOut++ ) {
				int r = dataIn[indexIn++];
				int g = dataIn[indexIn++];
				int b = dataIn[indexIn++];

				out2.data[indexOut] = (byte)r;
				out1.data[indexOut] = (byte)g;
				out0.data[indexOut] = (byte)b;
			}
		}
	}
465249
public FDistort output( ImageBase output ) {
		if( this.output == null || this.output.width != output.width || this.output.height != output.height ) {
			distorter = null;
		}
		this.output = output;
		return this;
	}
999547
public static <T extends ImageBase<T>>
	T median(T input, @Nullable T output, int radius , @Nullable WorkArrays work) {
		if( input instanceof GrayU8) {
			return (T)BlurImageOps.median((GrayU8) input, (GrayU8) output, radius, (IWorkArrays)work);
		} else if( input instanceof GrayF32) {
			return (T)BlurImageOps.median((GrayF32) input, (GrayF32) output, radius);
		} else if( input instanceof Planar) {
			return (T)BlurImageOps.median((Planar)input,(Planar)output,radius, work);
		} else  {
			throw new IllegalArgumentException("Unsupported image type");
		}
	}
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();
        }
    }
66908
public ImageSource apply(ImageSource input) {
        ImageSource originalImage = input;

        int width = originalImage.getWidth();
        int height = originalImage.getHeight();

        boolean[][] matrix = new boolean[width][height]; // black n white boolean matrix; true = blck, false = white

        // Copy
        ImageSource filteredImage = new MatrixSource(input);

        int[] histogram = OtsuBinarize.imageHistogram(originalImage);

        int totalNumberOfpixels = height * width;

        int threshold = OtsuBinarize.threshold(histogram, totalNumberOfpixels);

        int black = 0;
        int white = 255;

        int gray;
        int alpha;
        int newColor;

        for (int i = 0; i < width; i++) {
            for (int j = 0; j < height; j++) {
                gray = originalImage.getGray(i, j);

                if (gray > threshold) {
                    matrix[i][j] = false;
                } else {
                    matrix[i][j] = true;
                }

            }
        }

        int blackTreshold = letterThreshold(originalImage, matrix);

        for (int i = 0; i < width; i++) {
            for (int j = 0; j < height; j++) {
                gray = originalImage.getGray(i, j);
                alpha = originalImage.getA(i, j);

                if (gray > blackTreshold) {
                    newColor = white;
                } else {
                    newColor = black;
                }

                newColor = ColorHelper.getARGB(newColor, newColor, newColor, alpha);
                filteredImage.setRGB(i, j, newColor);
            }
        }

        return filteredImage;
    }
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;
	}
584780
public static <I extends ImageGray<I>, T extends ImageGray>
	T transform( I input , T transformed ) {
		if( input instanceof GrayF32) {
			return (T)IntegralImageOps.transform((GrayF32)input,(GrayF32)transformed);
		} else if( input instanceof GrayF64) {
			return (T)IntegralImageOps.transform((GrayF64)input,(GrayF64)transformed);
		} else if( input instanceof GrayU8) {
			return (T)IntegralImageOps.transform((GrayU8)input,(GrayS32)transformed);
		} else if( input instanceof GrayS32) {
			return (T)IntegralImageOps.transform((GrayS32)input,(GrayS32)transformed);
		} else if( input instanceof GrayS64) {
			return (T)IntegralImageOps.transform((GrayS64)input,(GrayS64)transformed);
		} else {
			throw new IllegalArgumentException("Unknown input type: "+input.getClass().getSimpleName());
		}
	}
821722
public static void rotateCW( InterleavedS64 input , InterleavedS64 output ) {
		if( input.width != output.height || input.height != output.width || input.numBands != output.numBands )
			throw new IllegalArgumentException("Incompatible shapes");

		int h = input.height-1;

		for( int y = 0; y < input.height; y++ ) {
			int indexSrc = input.startIndex + y*input.stride;
			for (int x = 0; x < input.width; x++) {
				int indexDst = output.getIndex(h-y,x);

				int end = indexSrc + input.numBands;
				while( indexSrc != end ) {
					output.data[indexDst++] = input.data[indexSrc++];
				}
			}
		}
	}