@Override public void process(GrayU8 input) { ConvertImage.convert(input, grayF); PixelMath.divide(grayF,255.0f,grayF); dft.forward(grayF, transform); DiscreteFourierTransformOps.shiftZeroFrequency(transform, true); DiscreteFourierTransformOps.magnitude(transform, grayF); PixelMath.log(grayF,grayF); float max = ImageStatistics.maxAbs(grayF); PixelMath.multiply(grayF, 255f / max, grayF); ConvertBitmap.grayToBitmap(grayF, bitmap, bitmapTmp); } }
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());
public static void magnitudeAbs(ImageFlow flowImage, float maxValue, BufferedImage out) { GrayF32 magnitude = new GrayF32(flowImage.width,flowImage.height); for( int y = 0; y < flowImage.height; y++ ) { for( int x = 0; x < flowImage.width; x++ ) { ImageFlow.D f = flowImage.unsafe_get(x,y); if( !f.isValid() ) { out.setRGB(x,y,0xFF); } else { float m = Math.max(Math.abs(f.x),Math.abs(f.y)); magnitude.unsafe_set(x, y, m); } } } PixelMath.multiply(magnitude, 255 / maxValue, magnitude); PixelMath.boundImage(magnitude,0,255); ConvertBufferedImage.convertTo(magnitude,out); }
/** * Copies the target into the output image and applies the cosine window to it. */ protected void get_subwindow( T image , GrayF64 output ) { // copy the target region interp.setImage(image); int index = 0; for( int y = 0; y < workRegionSize; y++ ) { float yy = regionTrack.y0 + y*stepY; for( int x = 0; x < workRegionSize; x++ ) { float xx = regionTrack.x0 + x*stepX; if( interp.isInFastBounds(xx,yy)) output.data[index++] = interp.get_fast(xx,yy); else if( BoofMiscOps.checkInside(image, xx, yy)) output.data[index++] = interp.get(xx, yy); else { // randomize to make pixels outside the image poorly correlate. It will then focus on matching // what's inside the image since it has structure output.data[index++] = rand.nextFloat()*maxPixelValue; } } } // normalize values to be from -0.5 to 0.5 PixelMath.divide(output, maxPixelValue, output); PixelMath.plus(output, -0.5f, output); // apply the cosine window to it PixelMath.multiply(output,cosine,output); }
PixelMath.multiply((GrayU8) input, value, (GrayU8) output); } else if (GrayS8.class == input.getClass()) { PixelMath.multiply((GrayS8) input, value, (GrayS8) output); } else if (GrayU16.class == input.getClass()) { PixelMath.multiply((GrayU16) input, value, (GrayU16) output); } else if (GrayS16.class == input.getClass()) { PixelMath.multiply((GrayS16) input, value, (GrayS16) output); } else if (GrayS32.class == input.getClass()) { PixelMath.multiply((GrayS32) input, value, (GrayS32) output); } else if (GrayS64.class == input.getClass()) { PixelMath.multiply((GrayS64) input, value, (GrayS64) output); } else if (GrayF32.class == input.getClass()) { PixelMath.multiply((GrayF32) input, (float) value, (GrayF32) output); } else if (GrayF64.class == input.getClass()) { PixelMath.multiply((GrayF64) input, value, (GrayF64) output); } else { throw new IllegalArgumentException("Unknown image Type: " + input.getClass().getSimpleName()); PixelMath.multiply((InterleavedU8) input, value, (InterleavedU8) output); } else if (InterleavedS8.class == input.getClass()) { PixelMath.multiply((InterleavedS8) input, value, (InterleavedS8) output); } else if (InterleavedU16.class == input.getClass()) { PixelMath.multiply((InterleavedU16) input, value, (InterleavedU16) output); } else if (InterleavedS16.class == input.getClass()) { PixelMath.multiply((InterleavedS16) input, value, (InterleavedS16) output); } else if (InterleavedS32.class == input.getClass()) { PixelMath.multiply((InterleavedS32) input, value, (InterleavedS32) output); } else if (InterleavedS64.class == input.getClass()) { PixelMath.multiply((InterleavedS64) input, value, (InterleavedS64) output);
public synchronized void update( final CirculantTracker tracker ) { if( hasSelected ) { RectangleLength2D_F32 r = tracker.getTargetLocation(); selected.x0 = (int)r.x0; selected.y0 = (int)r.y0; selected.x1 = selected.x0 + (int)r.width; selected.y1 = selected.y0 + (int)r.height; GrayF64 template = tracker.getTargetTemplate(); GrayF64 response = tracker.getResponse(); if( this.template == null ) { this.template = new BufferedImage(template.width,template.height,BufferedImage.TYPE_INT_RGB); this.response = new BufferedImage(template.width,template.height,BufferedImage.TYPE_INT_RGB); tmp.reshape(template.width,template.height); } ConvertImage.convert(template,tmp); PixelMath.plus(tmp, 0.5f, tmp); PixelMath.multiply(tmp,255,0,255,tmp); ConvertBufferedImage.convertTo(tmp,this.template,true); ConvertImage.convert(response,tmp); VisualizeImageData.colorizeSign(tmp,this.response,-1); } repaint(); }
@Override public void setInputImage(GrayF32 image) { enlargedTemplate.reshape(image.width,image.height); fftImage.reshape(image.width,image.height); fftTemplate.reshape(image.width,image.height); fftMult.reshape(image.width,image.height); correlation.reshape(image.width,image.height); normalizedImage.reshape(image.width,image.height); maxValue = ImageStatistics.max(image)+0.0001f;// avoid divide by zero errors mean = ImageStatistics.mean(image); PixelMath.divide(image,maxValue,normalizedImage); PixelMath.minus(normalizedImage,mean/maxValue,normalizedImage); dft.forward(normalizedImage, fftImage); }
private double computeEdgeMSE(GrayF32 imageInv) { GrayF32 edge = new GrayF32(imageInv.width,imageInv.height); LaplacianEdge.process(image,edge); PixelMath.abs(edge,edge); float max = ImageStatistics.maxAbs(edge); PixelMath.divide(edge,max,edge); float total = ImageStatistics.sum(edge); double error = 0; for( int y = 0; y < image.height; y++ ) { for( int x = 0; x < image.width; x++ ) { double w = edge.get(x,y)/total; double e = (image.get(x,y)-imageInv.get(x,y)); error += (e*e)*w; } } return error; }
PixelMath.divide((GrayU8) input, denominator, (GrayU8) output); } else if (GrayS8.class == input.getClass()) { PixelMath.divide((GrayS8) input, denominator, (GrayS8) output); } else if (GrayU16.class == input.getClass()) { PixelMath.divide((GrayU16) input, denominator, (GrayU16) output); } else if (GrayS16.class == input.getClass()) { PixelMath.divide((GrayS16) input, denominator, (GrayS16) output); } else if (GrayS32.class == input.getClass()) { PixelMath.divide((GrayS32) input, denominator, (GrayS32) output); } else if (GrayS64.class == input.getClass()) { PixelMath.divide((GrayS64) input, denominator, (GrayS64) output); } else if (GrayF32.class == input.getClass()) { PixelMath.divide((GrayF32) input, (float) denominator, (GrayF32) output); } else if (GrayF64.class == input.getClass()) { PixelMath.divide((GrayF64) input, denominator, (GrayF64) output); } else { throw new IllegalArgumentException("Unknown image Type: " + input.getClass().getSimpleName()); PixelMath.divide((InterleavedU8) input, denominator, (InterleavedU8) output); } else if (InterleavedS8.class == input.getClass()) { PixelMath.divide((InterleavedS8) input, denominator, (InterleavedS8) output); } else if (InterleavedU16.class == input.getClass()) { PixelMath.divide((InterleavedU16) input, denominator, (InterleavedU16) output); } else if (InterleavedS16.class == input.getClass()) { PixelMath.divide((InterleavedS16) input, denominator, (InterleavedS16) output); } else if (InterleavedS32.class == input.getClass()) { PixelMath.divide((InterleavedS32) input, denominator, (InterleavedS32) output); } else if (InterleavedS64.class == input.getClass()) { PixelMath.divide((InterleavedS64) input, denominator, (InterleavedS64) output);
/** * Sets each pixel in the output image to be the absolute value of the input image. * Both the input and output image can be the same instance. * * @param input The input image. Not modified. * @param output Where the absolute value image is written to. Modified. */ public static void abs(GrayS8 input , GrayS8 output ) { InputSanityCheck.checkSameShape(input,output); int columns = input.width; abs(input.data,input.startIndex,input.stride, output.data,output.startIndex,output.stride, input.height,columns); }
if( input instanceof ImageGray ) { if (GrayU8.class == input.getClass()) { PixelMath.boundImage((GrayU8) input, (int) min, (int) max); } else if (GrayS8.class == input.getClass()) { PixelMath.boundImage((GrayS8) input, (int) min, (int) max); } else if (GrayU16.class == input.getClass()) { PixelMath.boundImage((GrayU16) input, (int) min, (int) max); } else if (GrayS16.class == input.getClass()) { PixelMath.boundImage((GrayS16) input, (int) min, (int) max); } else if (GrayS32.class == input.getClass()) { PixelMath.boundImage((GrayS32) input, (int) min, (int) max); } else if (GrayS64.class == input.getClass()) { PixelMath.boundImage((GrayS64) input, (long) min, (long) max); } else if (GrayF32.class == input.getClass()) { PixelMath.boundImage((GrayF32) input, (float) min, (float) max); } else if (GrayF64.class == input.getClass()) { PixelMath.boundImage((GrayF64) input, min, max); } else { throw new IllegalArgumentException("Unknown image Type: " + input.getClass().getSimpleName());
if( input instanceof ImageGray) { if (GrayU8.class == input.getClass()) { PixelMath.plus((GrayU8) input, (int) value, (GrayU8) output); } else if (GrayS8.class == input.getClass()) { PixelMath.plus((GrayS8) input, (int) value, (GrayS8) output); } else if (GrayU16.class == input.getClass()) { PixelMath.plus((GrayU16) input, (int) value, (GrayU16) output); } else if (GrayS16.class == input.getClass()) { PixelMath.plus((GrayS16) input, (int) value, (GrayS16) output); } else if (GrayS32.class == input.getClass()) { PixelMath.plus((GrayS32) input, (int) value, (GrayS32) output); } else if (GrayS64.class == input.getClass()) { PixelMath.plus((GrayS64) input, (long) value, (GrayS64) output); } else if (GrayF32.class == input.getClass()) { PixelMath.plus((GrayF32) input, (float) value, (GrayF32) output); } else if (GrayF64.class == input.getClass()) { PixelMath.plus((GrayF64) input, value, (GrayF64) output); } else { throw new IllegalArgumentException("Unknown image Type: " + input.getClass().getSimpleName()); PixelMath.plus((InterleavedU8) input, (int) value, (InterleavedU8) output); } else if (InterleavedS8.class == input.getClass()) { PixelMath.plus((InterleavedS8) input, (int) value, (InterleavedS8) output); } else if (InterleavedU16.class == input.getClass()) { PixelMath.plus((InterleavedU16) input, (int) value, (InterleavedU16) output); } else if (InterleavedS16.class == input.getClass()) { PixelMath.plus((InterleavedS16) input, (int) value, (InterleavedS16) output); } else if (InterleavedS32.class == input.getClass()) { PixelMath.plus((InterleavedS32) input, (int) value, (InterleavedS32) output);
PixelMath.minus((int) value, (GrayU8) input, (int) lower, (int) upper, (GrayU8) output); } else if (GrayS8.class == input.getClass()) { PixelMath.minus((int) value, (GrayS8) input, (int) lower, (int) upper, (GrayS8) output); } else if (GrayU16.class == input.getClass()) { PixelMath.minus((int) value, (GrayU16) input, (int) lower, (int) upper, (GrayU16) output); } else if (GrayS16.class == input.getClass()) { PixelMath.minus((int) value, (GrayS16) input, (int) lower, (int) upper, (GrayS16) output); } else if (GrayS32.class == input.getClass()) { PixelMath.minus((int) value, (GrayS32) input, (int) lower, (int) upper, (GrayS32) output); } else if (GrayS64.class == input.getClass()) { PixelMath.minus((long) value, (GrayS64) input, (long) lower, (long) upper, (GrayS64) output); } else if (GrayF32.class == input.getClass()) { PixelMath.minus((float) value, (GrayF32) input, (float) lower, (float) upper, (GrayF32) output); } else if (GrayF64.class == input.getClass()) { PixelMath.minus(value, (GrayF64) input, lower, upper, (GrayF64) output); } else { throw new IllegalArgumentException("Unknown image Type: " + input.getClass().getSimpleName()); PixelMath.minus((int) value, (InterleavedU8) input, (int) lower, (int) upper, (InterleavedU8) output); } else if (InterleavedS8.class == input.getClass()) { PixelMath.minus((int) value, (InterleavedS8) input, (int) lower, (int) upper, (InterleavedS8) output); } else if (InterleavedU16.class == input.getClass()) { PixelMath.minus((int) value, (InterleavedU16) input, (int) lower, (int) upper, (InterleavedU16) output); } else if (InterleavedS16.class == input.getClass()) { PixelMath.minus((int) value, (InterleavedS16) input, (int) lower, (int) upper, (InterleavedS16) output); } else if (InterleavedS32.class == input.getClass()) { PixelMath.minus((int) value, (InterleavedS32) input, (int) lower, (int) upper, (InterleavedS32) output); } else if (InterleavedS64.class == input.getClass()) { PixelMath.minus((long) value, (InterleavedS64) input, (long) lower, (long) upper, (InterleavedS64) output);
if( inputA instanceof ImageGray){ if( GrayU8.class == inputA.getClass() ) { PixelMath.subtract((GrayU8) inputA, (GrayU8)inputB, (GrayI16) output); } else if( GrayS8.class == inputA.getClass() ) { PixelMath.subtract((GrayS8) inputA, (GrayS8)inputB, (GrayS16) output); } else if( GrayU16.class == inputA.getClass() ) { PixelMath.subtract((GrayU16) inputA, (GrayU16)inputB, (GrayS32) output); } else if( GrayS16.class == inputA.getClass() ) { PixelMath.subtract((GrayS16) inputA, (GrayS16)inputB, (GrayS32) output); } else if( GrayS32.class == inputA.getClass() ) { PixelMath.subtract((GrayS32) inputA, (GrayS32)inputB, (GrayS32) output); } else if( GrayS64.class == inputA.getClass() ) { PixelMath.subtract((GrayS64) inputA, (GrayS64)inputB, (GrayS64) output); } else if( GrayF32.class == inputA.getClass() ) { PixelMath.subtract((GrayF32) inputA, (GrayF32)inputB, (GrayF32) output); } else if( GrayF64.class == inputA.getClass() ) { PixelMath.subtract((GrayF64) inputA, (GrayF64)inputB, (GrayF64) output); } else { throw new IllegalArgumentException("Unknown image Type: "+inputA.getClass().getSimpleName());
/** * Sets each pixel in the output image to log( 1 + input(x,y)) of the input image. * Both the input and output image can be the same instance. * * @param input The input image. Not modified. * @param output Where the log image is written to. Modified. */ public static <T extends ImageBase<T>> void log(T input , T output ) { if( input instanceof ImageGray ) { if (GrayF32.class == input.getClass()) { PixelMath.log((GrayF32) input, (GrayF32) output); } else if (GrayF64.class == input.getClass()) { PixelMath.log((GrayF64) input, (GrayF64) output); } else { throw new IllegalArgumentException("Unknown image Type: " + input.getClass().getSimpleName()); } } else if( input instanceof Planar ) { Planar in = (Planar)input; Planar out = (Planar)output; for (int i = 0; i < in.getNumBands(); i++) { log( in.getBand(i), out.getBand(i)); } } }
PixelMath.multiply((GrayU8) input, value, (int) lower, (int) upper, (GrayU8) output); } else if (GrayS8.class == input.getClass()) { PixelMath.multiply((GrayS8) input, value, (int) lower, (int) upper, (GrayS8) output); } else if (GrayU16.class == input.getClass()) { PixelMath.multiply((GrayU16) input, value, (int) lower, (int) upper, (GrayU16) output); } else if (GrayS16.class == input.getClass()) { PixelMath.multiply((GrayS16) input, value, (int) lower, (int) upper, (GrayS16) output); } else if (GrayS32.class == input.getClass()) { PixelMath.multiply((GrayS32) input, value, (int) lower, (int) upper, (GrayS32) output); } else if (GrayS64.class == input.getClass()) { PixelMath.multiply((GrayS64) input, value, (long) lower, (long) upper, (GrayS64) output); } else if (GrayF32.class == input.getClass()) { PixelMath.multiply((GrayF32) input, (float) value, (float) lower, (float) upper, (GrayF32) output); } else if (GrayF64.class == input.getClass()) { PixelMath.multiply((GrayF64) input, value, lower, upper, (GrayF64) output); } else { throw new IllegalArgumentException("Unknown image Type: " + input.getClass().getSimpleName()); PixelMath.multiply((InterleavedU8) input, value, (int) lower, (int) upper, (InterleavedU8) output); } else if (InterleavedS8.class == input.getClass()) { PixelMath.multiply((InterleavedS8) input, value, (int) lower, (int) upper, (InterleavedS8) output); } else if (InterleavedU16.class == input.getClass()) { PixelMath.multiply((InterleavedU16) input, value, (int) lower, (int) upper, (InterleavedU16) output); } else if (InterleavedS16.class == input.getClass()) { PixelMath.multiply((InterleavedS16) input, value, (int) lower, (int) upper, (InterleavedS16) output); } else if (InterleavedS32.class == input.getClass()) { PixelMath.multiply((InterleavedS32) input, value, (int) lower, (int) upper, (InterleavedS32) output); } else if (InterleavedS64.class == input.getClass()) { PixelMath.multiply((InterleavedS64) input, value, (long) lower, (long) upper, (InterleavedS64) output);
PixelMath.divide((GrayU8) input, denominator, (int) lower, (int) upper, (GrayU8) output); } else if (GrayS8.class == input.getClass()) { PixelMath.divide((GrayS8) input, denominator, (int) lower, (int) upper, (GrayS8) output); } else if (GrayU16.class == input.getClass()) { PixelMath.divide((GrayU16) input, denominator, (int) lower, (int) upper, (GrayU16) output); } else if (GrayS16.class == input.getClass()) { PixelMath.divide((GrayS16) input, denominator, (int) lower, (int) upper, (GrayS16) output); } else if (GrayS32.class == input.getClass()) { PixelMath.divide((GrayS32) input, denominator, (int) lower, (int) upper, (GrayS32) output); } else if (GrayS64.class == input.getClass()) { PixelMath.divide((GrayS64) input, denominator, (long) lower, (long) upper, (GrayS64) output); } else if (GrayF32.class == input.getClass()) { PixelMath.divide((GrayF32) input, (float) denominator, (float) lower, (float) upper, (GrayF32) output); } else if (GrayF64.class == input.getClass()) { PixelMath.divide((GrayF64) input, denominator, lower, upper, (GrayF64) output); } else { throw new IllegalArgumentException("Unknown image Type: " + input.getClass().getSimpleName()); PixelMath.divide((InterleavedU8) input, denominator, (int) lower, (int) upper, (InterleavedU8) output); } else if (InterleavedS8.class == input.getClass()) { PixelMath.divide((InterleavedS8) input, denominator, (int) lower, (int) upper, (InterleavedS8) output); } else if (InterleavedU16.class == input.getClass()) { PixelMath.divide((InterleavedU16) input, denominator, (int) lower, (int) upper, (InterleavedU16) output); } else if (InterleavedS16.class == input.getClass()) { PixelMath.divide((InterleavedS16) input, denominator, (int) lower, (int) upper, (InterleavedS16) output); } else if (InterleavedS32.class == input.getClass()) { PixelMath.divide((InterleavedS32) input, denominator, (int) lower, (int) upper, (InterleavedS32) output); } else if (InterleavedS64.class == input.getClass()) { PixelMath.divide((InterleavedS64) input, denominator, (long) lower, (long) upper, (InterleavedS64) output);
/** * Sets each pixel in the output image to be the absolute value of the input image. * Both the input and output image can be the same instance. * * @param input The input image. Not modified. * @param output Where the absolute value image is written to. Modified. */ public static void abs(GrayS16 input , GrayS16 output ) { InputSanityCheck.checkSameShape(input,output); int columns = input.width; abs(input.data,input.startIndex,input.stride, output.data,output.startIndex,output.stride, input.height,columns); }