@Override public void reshape(int width, int height, int numberOfBands) { if( this.numBands != numberOfBands ) { if (isSubimage()) throw new IllegalArgumentException("Can't reshape sub-images"); this.numBands = -1; // force it to redeclare memory this.width = width; this.height = height; setNumberOfBands(numberOfBands); } else { reshape(width, height); } }
public void process( BufferedImage input ) { setInputImage(input); image.reshape(input.getWidth(),input.getHeight()); transform.reshape(input.getWidth(),input.getHeight()); magnitude.reshape(input.getWidth(),input.getHeight()); phase.reshape(input.getWidth(),input.getHeight()); ConvertBufferedImage.convertFrom(input, image, true); fft.forward(image,transform); GDiscreteFourierTransformOps.shiftZeroFrequency(transform,true); GDiscreteFourierTransformOps.magnitude(transform, magnitude); GDiscreteFourierTransformOps.phase(transform, phase); // Convert it to a log scale for visibility GPixelMath.log(magnitude, magnitude); SwingUtilities.invokeLater(new Runnable() { public void run() { setPreferredSize(new Dimension(image.width+50,image.height+20)); processedImage = true; }}); doRefreshAll(); }
/** * Sets this image equal to the specified image. Automatically resized to match the input image. * * @param orig The original image whose value is to be copied into this one */ @SuppressWarnings({"SuspiciousSystemArraycopy"}) @Override public void setTo(T orig) { if (orig.width != width || orig.height != height || orig.numBands != numBands ) reshape(orig.width,orig.height,orig.numBands); if (!orig.isSubimage() && !isSubimage()) { System.arraycopy(orig._getData(), orig.startIndex, _getData(), startIndex, stride * height); } else { int indexSrc = orig.startIndex; int indexDst = startIndex; for (int y = 0; y < height; y++) { System.arraycopy(orig._getData(), indexSrc, _getData(), indexDst, width * numBands); indexSrc += orig.stride; indexDst += stride; } } }
public static <T extends ImageInterleaved<T>>T convertFrom( IplImage input , T output ) { ImageDataType dataType = depthToBoofType(input.depth()); int numBands = input.nChannels(); int width = input.width(); int height = input.height(); if( output != null ) { if( output.isSubimage() ) throw new IllegalArgumentException("Can't handle sub-images"); if( output.getDataType() != dataType ) throw new IllegalArgumentException("Expected data type of " +dataType+" found "+output.getDataType()+" instead"); output.numBands = numBands; output.reshape(width,height); } else { output = (T)GeneralizedImageOps.createInterleaved(dataType,width,height,numBands); } switch( dataType ) { case U8: case S8: convertFrom_I(input,(InterleavedI8)output); break; case S16: convertFrom_I(input,(InterleavedS16)output); break; case S32: convertFrom_I(input,(InterleavedS32)output); break; case F32: convertFrom_I(input,(InterleavedF32)output); break; case F64: convertFrom_I(input,(InterleavedF64)output); break; default: throw new RuntimeException("Add support for type "+dataType); } return output; }
public static <T extends ImageInterleaved>T convertFrom( IplImage input , T output ) { ImageDataType dataType = depthToBoofType(input.depth()); int numBands = input.nChannels(); int width = input.width(); int height = input.height(); if( output != null ) { if( output.isSubimage() ) throw new IllegalArgumentException("Can't handle sub-images"); if( output.getDataType() != dataType ) throw new IllegalArgumentException("Expected data type of " +dataType+" found "+output.getDataType()+" instead"); output.numBands = numBands; output.reshape(width,height); } else { output = GeneralizedImageOps.createInterleaved(dataType,width,height,numBands); } switch( dataType ) { case U8: case S8: convertFrom_I(input,(InterleavedI8)output); break; case S16: convertFrom_I(input,(InterleavedS16)output); break; case S32: convertFrom_I(input,(InterleavedS32)output); break; case F32: convertFrom_I(input,(InterleavedF32)output); break; case F64: convertFrom_I(input,(InterleavedF64)output); break; default: throw new RuntimeException("Add support for type "+dataType); } return output; }