private static void from_1BU8_to_PLU8(Planar<GrayU8> dst, byte[] srcData, int srcOffset, int srcStrideDiff) { byte dstData[] = dst.getBand(0).data; int indexSrc = srcOffset; for (int y = 0; y < dst.height; y++) { int indexDst = dst.startIndex + dst.stride * y; System.arraycopy(srcData, indexSrc, dstData, indexDst, dst.width); indexSrc += dst.width + srcStrideDiff; } }
@Override public float colorDistance(float[] color, int index) { final int numBands = input.getNumBands(); float total = 0; for( int i = 0; i < numBands; i++ ) { float diff = (input.getBand(i).data[index] & 0xFF) - color[i]; total += diff*diff; } return total; }
@Override public void addColor(float[] color, int index, float weight) { final int numBands = input.getNumBands(); for( int i = 0; i < numBands; i++ ) { color[i] += input.getBand(i).data[index]*weight; } }
@Override public void addColor(float[] color, int index, float weight) { final int numBands = input.getNumBands(); for( int i = 0; i < numBands; i++ ) { color[i] += (input.getBand(i).data[index] & 0xFF)*weight; } }
@Override public float colorDistance(float[] color, int index) { final int numBands = input.getNumBands(); float total = 0; for( int i = 0; i < numBands; i++ ) { float diff = input.getBand(i).data[index] - color[i]; total += diff*diff; } return total; }
@Override public void setColor(float[] color, int x, int y) { final int numBands = input.getNumBands(); for( int i = 0; i < numBands; i++ ) { color[i] = input.getBand(i).unsafe_get(x,y); } }
private void checkAround( int x , int y , Planar<GrayF32> input , FastQueue<Edge> edges ) { int indexSrc = input.startIndex + y*input.stride + x; int indexA = y*input.width + x; for( int i = 0; i < numBands; i++ ) { GrayF32 band = input.getBand(i); pixelColor[i] = band.data[indexSrc]; } check(x+1, y, pixelColor,indexA,input,edges); check(x ,y+1,pixelColor,indexA,input,edges); }
@Override public void process(Planar<GrayU8> input) { ConvertImage.average(input,gray); ImageStatistics.histogram(gray,0, histogram); EnhanceImageOps.equalize(histogram, transform); for( int i = 0; i < 3; i++ ) EnhanceImageOps.applyTransform(input.getBand(i), transform, enhanced.getBand(i)); renderOutput(enhanced); } }
@Override public void apply(Planar<Input> srcImg, Planar<Output> dstImg) { if( srcImg.getNumBands() != dstImg.getNumBands() ) throw new IllegalArgumentException("Number of bands must be the same. "+srcImg.getNumBands()+" vs "+dstImg.getNumBands()); int N = srcImg.getNumBands(); for( int i = 0; i < N; i++ ) { layerDistort.apply(srcImg.getBand(i),dstImg.getBand(i)); } }
@Override public void apply(Planar<Input> srcImg, Planar<Output> dstImg, int dstX0, int dstY0, int dstX1, int dstY1) { if( srcImg.getNumBands() != dstImg.getNumBands() ) throw new IllegalArgumentException("Number of bands must be the same. "+srcImg.getNumBands()+" vs "+dstImg.getNumBands()); int N = srcImg.getNumBands(); for( int i = 0; i < N; i++ ) { layerDistort.apply(srcImg.getBand(i),dstImg.getBand(i),dstX0, dstY0, dstX1, dstY1); } }
@Override public void initialize(int backgroundWidth, int backgroundHeight, Motion homeToWorld) { background.reshape(backgroundWidth,backgroundHeight); for (int i = 0; i < background.getNumBands(); i+=2) { GImageMiscOps.fill(background.getBand(i),0); GImageMiscOps.fill(background.getBand(i+1),-1); } this.homeToWorld.set(homeToWorld); this.homeToWorld.invert(worldToHome); this.backgroundWidth = backgroundWidth; this.backgroundHeight = backgroundHeight; }
@Override public void get_fast(float x, float y, float[] values) { final int N = image.getNumBands(); for( int i = 0; i < N; i++ ) { alg.setImage(image.getBand(i)); values[i] = alg.get_fast(x,y); } }
@Override public void setImage(Planar<T> image) { gray.reshape(image.width,image.height); grayII.reshape(image.width,image.height); bandII.reshape(image.width,image.height); GConvertImage.average(image, gray); GIntegralImageOps.transform(gray, grayII); for( int i = 0; i < image.getNumBands(); i++) GIntegralImageOps.transform(image.getBand(i), bandII.getBand(i)); alg.setImage(grayII,bandII); }