@Override public void getF(int index, float[] value) { value[0] = sb.getF(index); }
public static void checkBorderZero(ImageGray outputImage, int border) { GImageGray img = FactoryGImageGray.wrap(outputImage); for (int y = 0; y < img.getHeight(); y++) { if (y >= border && y < img.getHeight() - border) continue; for (int x = 0; x < img.getWidth(); x++) { if (x >= border && x < img.getWidth() - border) continue; if (img.get(x, y).intValue() != 0) throw new RuntimeException("The border is not zero: "+x+" "+y); } } }
@Override public <T extends ImageBase<T>> T getImage() { return (T)sb.getImage(); } }
/** * <p> * Return true if the coordinate is inside the image or false if not.<br> * 0 ≤ x ≤ width<br> * 0 ≤ y ≤ height * </p> * <p>Note: while the image is defined up to width and height, including coordinates up to that point contribute * nothing towards the line integral since they are infinitesimally small.</p> * * @param x x-coordinate in pixel coordinates * @param y y-coordinate in pixel coordinates * @return true if inside or false if outside */ public boolean isInside( double x, double y ) { return x >= 0 && y >= 0 && x <= image.getWidth() && y <= image.getHeight(); }
@Override public void segment(T frame, GrayU8 segmented) { if( background.width == 1 ) { ImageMiscOps.fill(segmented,unknownValue); return; } InputSanityCheck.checkSameShape(background,frame,segmented); inputWrapper.wrap(frame); float thresholdSq = threshold*threshold; int indexBG = 0; for (int y = 0; y < frame.height; y++) { int indexInput = frame.startIndex + y*frame.stride; int indexSegmented = segmented.startIndex + y*segmented.stride; int end = indexInput + frame.width; while( indexInput < end ) { float bg = background.data[indexBG]; float pixelFrame = inputWrapper.getF(indexInput); float diff = bg - pixelFrame; if (diff * diff <= thresholdSq) { segmented.data[indexSegmented] = 0; } else { segmented.data[indexSegmented] = 1; } indexInput++; indexSegmented++; indexBG++; } } }
/** * Sets the image spacial derivatives. These should be computed from an image at the appropriate scale * in scale-space. * * @param derivX x-derivative of input image * @param derivY y-derivative of input image */ public void setImageGradient(Deriv derivX , Deriv derivY ) { this.imageDerivX.wrap(derivX); this.imageDerivY.wrap(derivY); }
Deriv image = (Deriv)imageDerivX.getImage(); float spacialDX = imageDerivX.unsafe_getF(pixelX, pixelY); float spacialDY = imageDerivY.unsafe_getF(pixelX, pixelY);
@Override public Number get(int x, int y, int band) { return bandWrappers[band].get(x,y); }
@Override public void get(int x, int y, float[] value) { value[0]=sb.unsafe_getF(x,y); }
@Override public int getWidth() {return sb.getWidth();}
@Override public int getHeight() {return sb.getHeight();}
@Override public void set(int x, int y, float[] value) { sb.set(x,y,value[0]); }
public Class<D> getDerivType () { return (Class)(imageDerivX.getImageType()); } }
if (t > 1) t = 1; if( t > 0 ) sum += t * image.unsafe_getD(px, py); double deltaT = (sgnX+sgnY)/ (slopeX+slopeY); sum += actualDeltaT * image.unsafe_getD(px, py); if (t > 1) t = 1; if( t > 0 ) sum += t * image.unsafe_getD(px, py); y = y0 + sampleT*slopeY; sum += deltaT*image.unsafe_getD((int)x,(int)y); t = t + deltaT; x = x0 + t*slopeX;
@Override public void updateBackground( T frame) { if( background.width == 1 ) { background.reshape(frame.width, frame.height); GConvertImage.convert(frame, background); return; } else { InputSanityCheck.checkSameShape(background,frame); } inputWrapper.wrap(frame); float minusLearn = 1.0f - learnRate; int indexBG = 0; for (int y = 0; y < frame.height; y++) { int indexInput = frame.startIndex + y*frame.stride; int end = indexInput + frame.width; while( indexInput < end ) { float value = inputWrapper.getF(indexInput++); float bg = background.data[indexBG]; background.data[indexBG++] = minusLearn*bg + learnRate*value; } } }
@Override public Number get(int x, int y, int band) { if( band != 0 ) throw new IllegalArgumentException("Must be band 0"); return this.sb.get(x,y); }
@Override public void setF(int index, float[] value) { sb.set(index,value[0]); }