/** * <p> * Converts an {@link boofcv.struct.image.InterleavedF32} into a {@link boofcv.struct.image.InterleavedF64}. * </p> * * @param input Input image which is being converted. Not modified. * @param output (Optional) The output image. If null a new image is created. Modified. * @return Converted image. */ public static InterleavedF64 convert(InterleavedF32 input, InterleavedF64 output) { if (output == null) { output = new InterleavedF64(input.width, input.height, input.numBands); } else { output.reshape(input.width,input.height,input.numBands); } ImplConvertImage.convert(input, output); return output; }
double ra = transform.getBand(x,y,0); double ia = transform.getBand(x,y,1); double rb = transform.getBand(x+hw,y+hh,0); double ib = transform.getBand(x+hw,y+hh,1); transform.setBand(x,y,0,rb); transform.setBand(x,y,1,ib); transform.setBand(x+hw,y+hh,0,ra); transform.setBand(x+hw,y+hh,1,ia); ra = transform.getBand(x+hw,y,0); ia = transform.getBand(x+hw,y,1); rb = transform.getBand(x,y+hh,0); ib = transform.getBand(x,y+hh,1); transform.setBand(x+hw,y,0,rb); transform.setBand(x+hw,y,1,ib); transform.setBand(x,y+hh,0,ra); transform.setBand(x,y+hh,1,ia); InterleavedF64 storageTL = new InterleavedF64(hw1,hh1,2); storageTL.setTo(transform.subimage(0, 0, hw1, hh1, null)); InterleavedF64 storageTR = new InterleavedF64(hw,hh1,2); storageTR.setTo(transform.subimage(hw1, 0, w, hh1, null)); transform.subimage(0,0,hw,hh, null).setTo(transform.subimage(hw1,hh1,w,h, null));
public static void convolve( Kernel2D_F64 kernel , InterleavedF64 src , InterleavedF64 dst ) { final double[] dataKernel = kernel.data; final double[] dataSrc = src.data; final double[] dataDst = dst.data; final int width = src.getWidth(); final int height = src.getHeight(); final int numBands = src.getNumBands(); int offsetL = kernel.offset; int offsetR = kernel.width-kernel.offset-1; for( int y = offsetL; y < height-offsetR; y++ ) { int indexDst = dst.startIndex + y*dst.stride+offsetL*numBands; for( int x = offsetL; x < width-offsetR; x++ ) { int indexSrcStart = src.startIndex + (y-offsetL)*src.stride + (x-offsetL)*numBands; for (int band = 0; band < numBands; band++) { double total = 0; int indexKer = 0; for( int ki = 0; ki < kernel.width; ki++ ) { int indexSrc = indexSrcStart+ki*src.stride + band; for( int kj = 0; kj < kernel.width; kj++ ) { total += (dataSrc[indexSrc] )* dataKernel[indexKer++]; indexSrc += numBands; } } dataDst[indexDst++] = total; } } } }
/** * Fills each band in the image with the specified values * * @param input An image. * @param values Array which contains the values each band is to be filled with. */ public static void fill(InterleavedF64 input, double[] values) { final int numBands = input.numBands; for (int y = 0; y < input.height; y++) { for( int band = 0; band < numBands; band++ ) { int index = input.getStartIndex() + y * input.getStride() + band; int end = index + input.width*numBands - band; double value = values[band]; for (; index < end; index += numBands ) { input.data[index] = value; } } } }
public static void convert( InterleavedF64 from, InterleavedI8 to ) { if (from.isSubimage() || to.isSubimage()) { final int N = from.width * from.getNumBands(); for (int y = 0; y < from.height; y++) { int indexFrom = from.getIndex(0, y); int indexTo = to.getIndex(0, y); for (int x = 0; x < N; x++) { to.data[indexTo++] = ( byte )( from.data[indexFrom++] ); } } } else { final int N = from.width * from.height * from.getNumBands(); for (int i = 0; i < N; i++) { to.data[i] = ( byte )( from.data[i] ); } } }
public static void vertical(Kernel1D_F64 kernel, InterleavedF64 input, InterleavedF64 output ) { final int offset = kernel.getOffset(); final int width = input.getWidth(); final int height = input.getHeight(); final int numBands = input.getNumBands(); final double[] pixel = new double[ numBands ]; final double[] total = new double[ numBands ]; for (int y = 0; y < height; y++) { for( int x = 0; x < width; x++ ) { Arrays.fill(total,0); double weight = 0; int startY = y - offset; int endY = startY + kernel.getWidth(); if( startY < 0 ) startY = 0; if( endY > height ) endY = height; for( int i = startY; i < endY; i++ ) { double v = kernel.get(i-y+offset); input.get(x,i, pixel); for (int band = 0; band < numBands; band++) { total[band] += pixel[band]*v; } weight += v; } for (int band = 0; band < numBands; band++) { total[band] /= weight; } output.set(x,y, total); } } }
public static void convert( InterleavedU8 from, InterleavedF64 to ) { if (from.isSubimage() || to.isSubimage()) { final int N = from.width * from.getNumBands(); for (int y = 0; y < from.height; y++) { int indexFrom = from.getIndex(0, y); int indexTo = to.getIndex(0, y); for (int x = 0; x < N; x++) { to.data[indexTo++] = ( double )( from.data[indexFrom++] & 0xFF); } } } else { final int N = from.width * from.height * from.getNumBands(); for (int i = 0; i < N; i++) { to.data[i] = ( double )( from.data[i] & 0xFF); } } }
@Override public void inverse(InterleavedF64 transform, GrayF64 image ) { DiscreteFourierTransformOps.checkImageArguments(image,transform); if( image.isSubimage() ) throw new IllegalArgumentException("Subimages are not supported"); checkDeclareAlg(image); // If he user lets us, modify the transform InterleavedF64 workImage; if(modifyInputs) { workImage = transform; } else { tmp.reshape(transform.width,transform.height); tmp.setTo(transform); workImage = tmp; } alg.complexInverse(workImage.data, true); // copy the real portion. imaginary should be zeros int N = image.width*image.height; for( int i = 0; i < N; i++ ) { image.data[i] = workImage.data[i*2]; } }
/** * Returns the value of the specified band in the specified pixel. * * @param x pixel coordinate. * @param y pixel coordinate. * @param band which color band in the pixel * @param value The new value of the element. */ public void setBand(int x, int y, int band, double value) { if (!isInBounds(x, y)) throw new ImageAccessException("Requested pixel is out of bounds."); if (band < 0 || band >= numBands) throw new ImageAccessException("Invalid band requested."); data[getIndex(x, y, band)] = value; }
public void unsafe_get(int x, int y, double[] storage) { int index = getIndex(x, y, 0); for (int i = 0; i < numBands; i++, index++) { storage[i] = data[index]; } }
protected void resizeImages( int workRegionSize ) { templateNew.reshape(workRegionSize, workRegionSize); template.reshape(workRegionSize, workRegionSize); cosine.reshape(workRegionSize,workRegionSize); k.reshape(workRegionSize,workRegionSize); kf.reshape(workRegionSize,workRegionSize); alphaf.reshape(workRegionSize,workRegionSize); newAlphaf.reshape(workRegionSize,workRegionSize); response.reshape(workRegionSize,workRegionSize); tmpReal0.reshape(workRegionSize,workRegionSize); tmpReal1.reshape(workRegionSize,workRegionSize); tmpFourier0.reshape(workRegionSize,workRegionSize); tmpFourier1.reshape(workRegionSize,workRegionSize); tmpFourier2.reshape(workRegionSize,workRegionSize); gaussianWeight.reshape(workRegionSize,workRegionSize); gaussianWeightDFT.reshape(workRegionSize,workRegionSize); }
public static void average( InterleavedF64 from , GrayF64 to ) { final int numBands = from.getNumBands(); int indexFrom = from.getIndex(0, y); int indexTo = to.getIndex(0, y); System.arraycopy(from.data,indexFrom,to.data,indexTo,from.width); int indexFrom = from.getIndex(0, y); int indexTo = to.getIndex(0, y); int indexEndTo = indexTo + from.width; int indexFrom = from.getIndex(0, y); int indexTo = to.getIndex(0, y); int indexEndTo = indexTo + from.width; int indexFrom = from.getIndex(0, y); int indexTo = to.getIndex(0, y);
@Override public void setF(int index, float[] value) { for( int i = 0; i < image.getNumBands(); i++ ) { image.data[index++] = value[i]; } }
@Override public ImageType<InterleavedF64> getImageType() { return orig.getImageType(); }
@Override public InterleavedF64 createNew(int imgWidth, int imgHeight) { if (imgWidth == -1 || imgHeight == -1) return new InterleavedF64(); return new InterleavedF64(imgWidth, imgHeight, numBands); } }
public static double get(ImageInterleaved img, int x, int y , int band ) { if (img instanceof InterleavedU8) { return ((InterleavedU8) img).getBand(x, y, band); } else if (img instanceof InterleavedS8) { return ((InterleavedS8) img).getBand(x, y, band); } else if (img instanceof InterleavedS16) { return ((InterleavedS16) img).getBand(x, y, band); } else if (img instanceof InterleavedU16) { return ((InterleavedU16) img).getBand(x, y, band); } else if (img instanceof InterleavedS32) { return ((InterleavedS32) img).getBand(x, y, band); } else if (img instanceof InterleavedS64) { return ((InterleavedS64) img).getBand(x, y, band); } else if (img instanceof InterleavedF32) { return ((InterleavedF32) img).getBand(x, y, band); } else if (img instanceof InterleavedF64) { return ((InterleavedF64) img).getBand(x, y, band); } else { throw new IllegalArgumentException("Unknown or incompatible image type: " + img.getClass().getSimpleName()); } }
final int width = input.getWidth(); final int height = input.getHeight(); final int numBands = input.getNumBands(); input.get(j,y, pixel); for (int band = 0; band < numBands; band++) { total[band] += pixel[band]*v; total[band] /= weight; output.set(x,y, total );
public static void convert( InterleavedF64 from, InterleavedF32 to ) { if (from.isSubimage() || to.isSubimage()) { final int N = from.width * from.getNumBands(); for (int y = 0; y < from.height; y++) { int indexFrom = from.getIndex(0, y); int indexTo = to.getIndex(0, y); for (int x = 0; x < N; x++) { to.data[indexTo++] = ( float )( from.data[indexFrom++] ); } } } else { final int N = from.width * from.height * from.getNumBands(); for (int i = 0; i < N; i++) { to.data[i] = ( float )( from.data[i] ); } } }
/** * Fills one band in the image with the specified value * * @param input An image. * @param band Which band is to be filled with the specified value * @param value The value that the image is being filled with. */ public static void fillBand(InterleavedF64 input, int band , double value) { final int numBands = input.numBands; for (int y = 0; y < input.height; y++) { int index = input.getStartIndex() + y * input.getStride() + band; int end = index + input.width*numBands - band; for (; index < end; index += numBands ) { input.data[index] = value; } } }
public static void convert( InterleavedS64 from, InterleavedF64 to ) { if (from.isSubimage() || to.isSubimage()) { final int N = from.width * from.getNumBands(); for (int y = 0; y < from.height; y++) { int indexFrom = from.getIndex(0, y); int indexTo = to.getIndex(0, y); for (int x = 0; x < N; x++) { to.data[indexTo++] = ( double )( from.data[indexFrom++] ); } } } else { final int N = from.width * from.height * from.getNumBands(); for (int i = 0; i < N; i++) { to.data[i] = ( double )( from.data[i] ); } } }