code
stringlengths
73
34.1k
label
stringclasses
1 value
public static Kernel2D_F64 gaussianWidth( double sigma , int width ) { if( sigma <= 0 ) sigma = sigmaForRadius(width/2,0); else if( width <= 0 ) throw new IllegalArgumentException("Must specify the width since it doesn't know if it should be even or odd"); if( width % 2 == 0 ) { int r = width/2-1; K...
java
public boolean process(List<AssociatedTriple> associated , int width , int height ) { init(width, height); // Fit a trifocal tensor to the input observations if (!robustFitTrifocal(associated) ) return false; // estimate the scene's structure if( !estimateProjectiveScene()) return false; if( !proje...
java
private boolean robustFitTrifocal(List<AssociatedTriple> associated) { // Fit a trifocal tensor to the observations robustly ransac.process(associated); inliers = ransac.getMatchSet(); TrifocalTensor model = ransac.getModelParameters(); if( verbose != null ) verbose.println("Remaining after RANSAC "+inlie...
java
private void pruneOutliers(BundleAdjustment<SceneStructureMetric> bundleAdjustment) { // see if it's configured to not prune if( pruneFraction == 1.0 ) return; PruneStructureFromSceneMetric pruner = new PruneStructureFromSceneMetric(structure,observations); pruner.pruneObservationsByErrorRank(pruneFraction);...
java
private boolean estimateProjectiveScene() { List<AssociatedTriple> inliers = ransac.getMatchSet(); TrifocalTensor model = ransac.getModelParameters(); MultiViewOps.extractCameraMatrices(model,P2,P3); // Most of the time this makes little difference, but in some edges cases this enables it to // converge cor...
java
private void setupMetricBundleAdjustment(List<AssociatedTriple> inliers) { // Construct bundle adjustment data structure structure = new SceneStructureMetric(false); observations = new SceneObservations(3); structure.initialize(3,3,inliers.size()); for (int i = 0; i < listPinhole.size(); i++) { CameraPinh...
java
private boolean checkBehindCamera(SceneStructureMetric structure ) { int totalBehind = 0; Point3D_F64 X = new Point3D_F64(); for (int i = 0; i < structure.points.length; i++) { structure.points[i].get(X); if( X.z < 0 ) totalBehind++; } if( verbose != null ) { verbose.println("points behind "+to...
java
private static void flipAround(SceneStructureMetric structure, SceneObservations observations) { // The first view will be identity for (int i = 1; i < structure.views.length; i++) { Se3_F64 w2v = structure.views[i].worldToView; w2v.set(w2v.invert(null)); } triangulatePoints(structure,observations); }
java
public void setImage( II grayII , Planar<II> colorII ) { InputSanityCheck.checkSameShape(grayII,colorII); if( colorII.getNumBands() != numBands ) throw new IllegalArgumentException("Expected planar images to have " +numBands+" not "+colorII.getNumBands()); this.grayII = grayII; this.colorII = colorII; ...
java
public static void hsvToRgb( double h , double s , double v , double []rgb ) { if( s == 0 ) { rgb[0] = v; rgb[1] = v; rgb[2] = v; return; } h /= d60_F64; int h_int = (int)h; double remainder = h - h_int; double p = v * ( 1 - s ); double q = v * ( 1 - s * remainder ); double t = v * ( 1 - s *...
java
public void configure( CameraPinholeBrown intrinsic , Se3_F64 planeToCamera , double centerX, double centerY, double cellSize , int overheadWidth , int overheadHeight ) { this.overheadWidth = overheadWidth; this.overheadHeight = overheadHeight; Point2Transform2_F64 normToPixel = LensD...
java
public boolean detect( T input ) { detections.reset(); detector.process(input); FastQueue<FoundFiducial> found = detector.getFound(); for (int i = 0; i < found.size(); i++) { FoundFiducial fid = found.get(i); int gridIndex = isExpected(fid.id); if( gridIndex >= 0 ) { Detection d = lookupDetect...
java
private int isExpected( long found ) { int bestHamming = 2; int bestNumber = -1; for (int i = 0; i < numbers.length; i++) { int hamming = DescriptorDistance.hamming((int)found^(int)numbers[i]); if( hamming < bestHamming ) { bestHamming = hamming; bestNumber = i; } } return bestNumber; }
java
private Detection lookupDetection( long found , int gridIndex) { for (int i = 0; i < detections.size(); i++) { Detection d = detections.get(i); if( d.id == found ) { return d; } } Detection d = detections.grow(); d.reset(); d.id = found; d.gridIndex = gridIndex; return d; }
java
public void process(GrayU8 binary , GrayS32 labeled ) { // initialize data structures labeled.reshape(binary.width,binary.height); // ensure that the image border pixels are filled with zero by enlarging the image if( border.width != binary.width+2 || border.height != binary.height+2) { border.reshape(bina...
java
private int scanForOne(byte[] data , int index , int end ) { while (index < end && data[index] != 1) { index++; } return index; }
java
public static <T extends ImageGray<T>> QrCodePreciseDetector<T> qrcode(ConfigQrCode config, Class<T> imageType) { if( config == null ) config = new ConfigQrCode(); config.checkValidity(); InputToBinary<T> inputToBinary = FactoryThresholdBinary.threshold(config.threshold,imageType); DetectPolygonBinaryGra...
java
public void initialize( T image , int x0 , int y0 , int x1 , int y1 ) { if( imagePyramid == null || imagePyramid.getInputWidth() != image.width || imagePyramid.getInputHeight() != image.height ) { int minSize = (config.trackerFeatureRadius*2+1)*5; int scales[] = selectPyramidScale(image.width,image.height,...
java
private void createCascadeRegion( int imageWidth , int imageHeight ) { cascadeRegions.reset(); int rectWidth = (int)(targetRegion.getWidth()+0.5); int rectHeight = (int)(targetRegion.getHeight()+0.5); for( int scaleInt = -config.scaleSpread; scaleInt <= config.scaleSpread; scaleInt++ ) { // try several sc...
java
public boolean track( T image ) { boolean success = true; valid = false; imagePyramid.process(image); template.setImage(image); variance.setImage(image); fern.setImage(image); if( reacquiring ) { // It can reinitialize if there is a single detection detection.detectionCascade(cascadeRegions); ...
java
protected boolean hypothesisFusion( boolean trackingWorked , boolean detectionWorked ) { valid = false; boolean uniqueDetection = detectionWorked && !detection.isAmbiguous(); TldRegion detectedRegion = detection.getBest(); double confidenceTarget; if( trackingWorked ) { // get the scores from tracking...
java
public static int[] selectPyramidScale( int imageWidth , int imageHeight, int minSize ) { int w = Math.max(imageWidth,imageHeight); int maxScale = w/minSize; int n = 1; int scale = 1; while( scale*2 < maxScale ) { n++; scale *= 2; } int ret[] = new int[n]; scale = 1; for( int i = 0; i < n; i++...
java
public void imageToGrid( Point2D_F64 pixel , Point2D_F64 grid ) { transformGrid.imageToGrid(pixel.x, pixel.y, grid); }
java
public int readBit( int row , int col ) { // todo use adjustments from near by alignment patterns float center = 0.5f; // if( pixel.x < -0.5 || pixel.y < -0.5 || pixel.x > imageWidth || pixel.y > imageHeight ) // return -1; transformGrid.gridToImage(row+center-0.2f, col+center, pixel); float pixel01 = int...
java
public static Webcam openDefault( int desiredWidth , int desiredHeight) { Webcam webcam = Webcam.getDefault(); // Webcam doesn't list all available resolutions. Just pass in a custom // resolution and hope it works adjustResolution(webcam,desiredWidth,desiredHeight); webcam.open(); return webcam; }
java
public void process(List<EllipseInfo> ellipses , List<List<Node>> output ) { init(ellipses); connect(ellipses); output.clear(); for (int i = 0; i < clusters.size(); i++) { List<Node> c = clusters.get(i); // remove noise removeSingleConnections(c); if( c.size() >= minimumClusterSize) { outpu...
java
static void removeSingleConnections( List<Node> cluster ) { List<Node> open = new ArrayList<>(); List<Node> future = new ArrayList<>(); open.addAll(cluster); while( !open.isEmpty() ) { for (int i = open.size()-1; i >= 0; i--) { Node n = open.get(i); if( n.connections.size == 1 ) { // clear it...
java
void init(List<EllipseInfo> ellipses) { nodes.resize(ellipses.size()); clusters.reset(); for (int i = 0; i < ellipses.size(); i++) { Node n = nodes.get(i); n.connections.reset(); n.which = i; n.cluster = -1; } nn.setPoints(ellipses,true); }
java
void joinClusters( int mouth , int food ) { List<Node> listMouth = clusters.get(mouth); List<Node> listFood = clusters.get(food); // put all members of food into mouth for (int i = 0; i < listFood.size(); i++) { listMouth.add( listFood.get(i) ); listFood.get(i).cluster = mouth; } // zero food membe...
java
@Override public void set(int x, int y, int value) { if (!isInBounds(x, y)) throw new ImageAccessException("Requested pixel is out of bounds: "+x+" "+y); data[getIndex(x, y)] = (byte) value; }
java
public static void process(GrayU8 orig, GrayS16 derivX, GrayS16 derivY) { final byte[] data = orig.data; final short[] imgX = derivX.data; final short[] imgY = derivY.data; final int width = orig.getWidth(); final int height = orig.getHeight() - 1; //CONCURRENT_BELOW BoofConcurrency.lo...
java
public static void process_sub(GrayU8 orig, GrayS16 derivX, GrayS16 derivY) { final byte[] data = orig.data; final short[] imgX = derivX.data; final short[] imgY = derivY.data; final int width = orig.getWidth(); final int height = orig.getHeight() - 1; final int strideSrc = orig.getSt...
java
public void setScaleFactors( double ...scaleFactors ) { // see if the scale factors have not changed if( scale != null && scale.length == scaleFactors.length ) { boolean theSame = true; for( int i = 0; i < scale.length; i++ ) { if( scale[i] != scaleFactors[i] ) { theSame = false; break; } ...
java
public static double variance(int[] histogram, double mean , int N ) { return variance(histogram, mean, count(histogram,N), N); }
java
public static double variance(int[] histogram, double mean, int counts , int N) { double sum = 0.0; for(int i=0;i<N;i++) { double d = i - mean; sum += (d*d) * histogram[i]; } return sum / counts; }
java
public static int count(int[] histogram, int N) { int counts = 0; for(int i=0;i<N;i++) { counts += histogram[i]; } return counts; }
java
public static void maxf(Planar<GrayF32> inX , Planar<GrayF32> inY , GrayF32 outX , GrayF32 outY ) { // input and output should be the same shape InputSanityCheck.checkSameShape(inX,inY); InputSanityCheck.reshapeOneIn(inX,outX,outY); // make sure that the pixel index is the same InputSanityCheck.checkIndexin...
java
public static void histogram() { BufferedImage buffered = UtilImageIO.loadImage(UtilIO.pathExample(imagePath)); GrayU8 gray = ConvertBufferedImage.convertFrom(buffered,(GrayU8)null); GrayU8 adjusted = gray.createSameShape(); int histogram[] = new int[256]; int transform[] = new int[256]; ListDisplayPanel ...
java
public static void sharpen() { BufferedImage buffered = UtilImageIO.loadImage(UtilIO.pathExample(imagePath)); GrayU8 gray = ConvertBufferedImage.convertFrom(buffered,(GrayU8)null); GrayU8 adjusted = gray.createSameShape(); ListDisplayPanel panel = new ListDisplayPanel(); EnhanceImageOps.sharpen4(gray, adju...
java
public boolean process( T image ) { tracker.process(image); tick++; inlierTracks.clear(); if( first ) { addNewTracks(); first = false; } else { if( !estimateMotion() ) { return false; } dropUnusedTracks(); int N = motionEstimator.getMatchSet().size(); if( thresholdAdd <= 0 || N < ...
java
private void addNewTracks() { // System.out.println("----------- Adding new tracks ---------------"); tracker.spawnTracks(); List<PointTrack> spawned = tracker.getNewTracks(null); // estimate 3D coordinate using stereo vision for( PointTrack t : spawned ) { Point2D3DTrack p = t.getCookie(); if( p == nu...
java
private boolean estimateMotion() { List<PointTrack> active = tracker.getActiveTracks(null); List<Point2D3D> obs = new ArrayList<>(); for( PointTrack t : active ) { Point2D3D p = t.getCookie(); pixelToNorm.compute( t.x , t.y , p.observation ); obs.add( p ); } // estimate the motion up to a scale fac...
java
double scoreForTriangulation( Motion motion ) { DMatrixRMaj H = new DMatrixRMaj(3,3); View viewA = motion.viewSrc; View viewB = motion.viewDst; // Compute initial estimate for H pairs.reset(); for (int i = 0; i < motion.associated.size(); i++) { AssociatedIndex ai = motion.associated.get(i); pairs.g...
java
public void configure(LensDistortionNarrowFOV distortion , Se3_F64 worldToCamera ) { this.worldToCamera = worldToCamera; normToPixel = distortion.distort_F64(false,true); }
java
public boolean transform( Point3D_F64 worldPt , Point2D_F64 pixelPt ) { SePointOps_F64.transform(worldToCamera,worldPt,cameraPt); // can't see the point if( cameraPt.z <= 0 ) return false; normToPixel.compute(cameraPt.x/cameraPt.z, cameraPt.y/cameraPt.z, pixelPt); return true; }
java
public Point2D_F64 transform( Point3D_F64 worldPt ) { Point2D_F64 out = new Point2D_F64(); if( transform(worldPt,out)) return out; else return null; }
java
protected void splitPixels(int indexStart, int length) { // too short to split if( length < minimumSideLengthPixel) return; // end points of the line int indexEnd = (indexStart+length)%N; int splitOffset = selectSplitOffset(indexStart,length); if( splitOffset >= 0 ) { // System.out.println(" splitt...
java
protected boolean mergeSegments() { // See if merging will cause a degenerate case if( splits.size() <= 3 ) return false; boolean change = false; work.reset(); for( int i = 0; i < splits.size; i++ ) { int start = splits.data[i]; int end = splits.data[(i+2)%splits.size]; if( selectSplitOffset(s...
java
protected boolean splitSegments() { boolean change = false; work.reset(); for( int i = 0; i < splits.size-1; i++ ) { change |= checkSplit(change, i,i+1); } change |= checkSplit(change, splits.size - 1, 0); // swap the two lists GrowQueue_I32 tmp = work; work = splits; splits = tmp; return cha...
java
protected int circularDistance( int start , int end ) { if( end >= start ) return end-start; else return N-start+end; }
java
public static void horizontal( GrayF32 src , GrayF32 dst ) { if( src.width < dst.width ) throw new IllegalArgumentException("src width must be >= dst width"); if( src.height != dst.height ) throw new IllegalArgumentException("src height must equal dst height"); float scale = src.width/(float)dst.width; ...
java
public static void vertical( GrayF32 src , GrayF32 dst ) { if( src.height < dst.height ) throw new IllegalArgumentException("src height must be >= dst height"); if( src.width != dst.width ) throw new IllegalArgumentException("src width must equal dst width"); float scale = src.height/(float)dst.height; ...
java
protected void drawFeatures( float scale , int offsetX , int offsetY , FastQueue<Point2D_F64> all, FastQueue<Point2D_F64> inliers, Homography2D_F64 currToGlobal, Graphics2D g2 ) { Point2D_F64 distPt = new Point2D_F64(); for( int i = 0; i < all.size; i++ ) { HomographyPointOps_F64.tr...
java
public void update( ImageGray image ) { if( approximateHistogram ) { for (int i = 0; i < bins.length; i++) bins[i] = 0; if (image instanceof GrayF32) update((GrayF32) image); else if (GrayI.class.isAssignableFrom(image.getClass())) update((GrayI) image); else throw new IllegalArgumentExce...
java
public void addImage( BufferedImage image , String name) { addImage(image, name, ScaleOptions.DOWN); }
java
public synchronized void addItem( final JComponent panel , final String name ) { Dimension panelD = panel.getPreferredSize(); final boolean sizeChanged = bodyWidth != panelD.width || bodyHeight != panelD.height; // make the preferred size large enough to hold all the images bodyWidth = (int)Math.max(bodyWidt...
java
public static RectangleLength2D_F64 centerBoxInside(int srcWidth, int srcHeight, PixelTransform<Point2D_F64> transform , Point2D_F64 work ) { List<Point2D_F64> points = computeBoundingPoints(srcWidth, srcHeight, transform, work); Point2D_F64 center = new Point2D_F64(); UtilPoint2D_F6...
java
public static void roundInside( RectangleLength2D_F64 bound ) { double x0 = Math.ceil(bound.x0); double y0 = Math.ceil(bound.y0); double x1 = Math.floor(bound.x0+bound.width); double y1 = Math.floor(bound.y0+bound.height); bound.x0 = x0; bound.y0 = y0; bound.width = x1-x0; bound.height = y1-y0; }
java
public boolean isInBounds( int c_x , int c_y ) { return BoofMiscOps.checkInside(image, c_x, c_y, radiusWidth, radiusHeight); }
java
private GrowQueue_I32 findCommonTracks( SeedInfo target ) { // if true then it is visible in all tracks boolean visibleAll[] = new boolean[target.seed.totalFeatures]; Arrays.fill(visibleAll,true); // used to keep track of which features are visible in the current motion boolean visibleMotion[] = new boolean[t...
java
private SeedInfo score( View target ) { SeedInfo output = new SeedInfo(); output.seed = target; scoresMotions.reset(); // score all edges for (int i = 0; i < target.connections.size; i++) { PairwiseImageGraph2.Motion m = target.connections.get(i); if( !m.is3D ) continue; scoresMotions.grow().se...
java
public static double score( PairwiseImageGraph2.Motion m ) { // countF and countF will be <= totalFeatures // Prefer a scene more features from a fundamental matrix than a homography. // This can be sign that the scene has a rich 3D structure and is poorly represented by // a plane or rotational motion doubl...
java
public void process( D derivX , D derivY , GrayU8 binaryEdges ) { InputSanityCheck.checkSameShape(derivX,derivY,binaryEdges); int w = derivX.width-regionSize+1; int h = derivY.height-regionSize+1; foundLines.reshape(derivX.width / regionSize, derivX.height / regionSize); foundLines.reset(); // avoid par...
java
private void findLinesInRegion( List<LineSegment2D_F32> gridLines ) { List<Edgel> list = edgels.copyIntoList(null); int iterations = 0; // exit if not enough points or max iterations exceeded while( iterations++ < maxDetectLines) { if( !robustMatcher.process(list) ) break; // remove the found edge...
java
private LineSegment2D_F32 convertToLineSegment(List<Edgel> matchSet, LinePolar2D_F32 model) { float minT = Float.MAX_VALUE; float maxT = -Float.MAX_VALUE; LineParametric2D_F32 line = UtilLine2D_F32.convert(model,(LineParametric2D_F32)null); Point2D_F32 p = new Point2D_F32(); for( Edgel e : matchSet ) { p...
java
public TldFernFeature lookupFern( int value ) { TldFernFeature found = table[value]; if( found == null ) { found = createFern(); found.init(value); table[value] = found; } return found; }
java
public double lookupPosterior( int value ) { TldFernFeature found = table[value]; if( found == null ) { return 0; } return found.posterior; }
java
void handleAdd() { BoofSwingUtil.checkGuiThread(); java.util.List<File> paths = browser.getSelectedFiles(); for (int i = 0; i < paths.size(); i++) { File f = paths.get(i); // if it's a directory add all the files in the directory if( f.isDirectory() ) { ...
java
void handleOK() { String[] selected = this.selected.paths.toArray(new String[0]); listener.selectedImages(selected); }
java
void showPreview( String path ) { synchronized (lockPreview) { if( path == null ) { pendingPreview = null; } else if( previewThread == null ) { pendingPreview = path; previewThread = new PreviewThread(); previewThread.start(...
java
public static List<Point2D_F64> createLayout(int numRows, int numCols, double squareWidth, double spaceWidth) { List<Point2D_F64> all = new ArrayList<>(); double width = (numCols*squareWidth + (numCols-1)*spaceWidth); double height = (numRows*squareWidth + (numRows-1)*spaceWidth); double startX = -width/2; ...
java
public void process(FastQueue<PositionPatternNode> pps , T gray ) { gridReader.setImage(gray); storageQR.reset(); successes.clear(); failures.clear(); for (int i = 0; i < pps.size; i++) { PositionPatternNode ppn = pps.get(i); for (int j = 3,k=0; k < 4; j=k,k++) { if( ppn.edges[j] != null && ppn.ed...
java
static void computeBoundingBox(QrCode qr ) { qr.bounds.get(0).set(qr.ppCorner.get(0)); qr.bounds.get(1).set(qr.ppRight.get(1)); Intersection2D_F64.intersection( qr.ppRight.get(1),qr.ppRight.get(2), qr.ppDown.get(3),qr.ppDown.get(2),qr.bounds.get(2)); qr.bounds.get(3).set(qr.ppDown.get(3)); }
java
private boolean extractFormatInfo(QrCode qr) { for (int i = 0; i < 2; i++) { // probably a better way to do this would be to go with the region that has the smallest // hamming distance if (i == 0) readFormatRegion0(qr); else readFormatRegion1(qr); int bitField = this.bits.read(0,15,false); ...
java
private boolean readFormatRegion0(QrCode qr) { // set the coordinate system to the closest pp to reduce position errors gridReader.setSquare(qr.ppCorner,(float)qr.threshCorner); bits.resize(15); bits.zero(); for (int i = 0; i < 6; i++) { read(i,i,8); } read(6,7,8); read(7,8,8); read(8,8,7); fo...
java
private boolean readFormatRegion1(QrCode qr) { // if( qr.ppRight.get(0).distance(988.8,268.3) < 30 ) // System.out.println("tjere"); // System.out.println(qr.ppRight.get(0)); // set the coordinate system to the closest pp to reduce position errors gridReader.setSquare(qr.ppRight,(float)qr.threshRight); bits...
java
private boolean readRawData( QrCode qr) { QrCode.VersionInfo info = QrCode.VERSION_INFO[qr.version]; qr.rawbits = new byte[info.codewords]; // predeclare memory bits.resize(info.codewords*8); // read bits from memory List<Point2D_I32> locationBits = QrCode.LOCATION_BITS[qr.version]; // end at bits.siz...
java
private void read(int bit , int row , int col ) { int value = gridReader.readBit(row,col); if( value == -1 ) { // The requested region is outside the image. A partial QR code can be read so let's just // assign it a value of zero and let error correction handle this value = 0; } bits.set(bit,value); }
java
boolean extractVersionInfo(QrCode qr) { int version = estimateVersionBySize(qr); // For version 7 and beyond use the version which has been encoded into the qr code if( version >= QrCode.VERSION_ENCODED_AT) { readVersionRegion0(qr); int version0 = decodeVersion(); readVersionRegion1(qr); int version1...
java
int decodeVersion() { int bitField = this.bits.read(0,18,false); int message; // see if there's any errors if (QrCodePolynomialMath.checkVersionBits(bitField)) { message = bitField >> 12; } else { message = QrCodePolynomialMath.correctVersionBits(bitField); } // sanity check results if( message > ...
java
int estimateVersionBySize( QrCode qr ) { // Just need the homography for this corner square square gridReader.setMarkerUnknownVersion(qr,0); // Compute location of position patterns relative to corner PP gridReader.imageToGrid(qr.ppRight.get(0),grid); // see if pp is miss aligned. Probably not a flat surfac...
java
private boolean readVersionRegion0(QrCode qr) { // set the coordinate system to the closest pp to reduce position errors gridReader.setSquare(qr.ppRight, (float) qr.threshRight); bits.resize(18); bits.zero(); for (int i = 0; i < 18; i++) { int row = i/3; int col = i%3; read(i,row,col-4); } // Sys...
java
private boolean readVersionRegion1(QrCode qr) { // set the coordinate system to the closest pp to reduce position errors gridReader.setSquare(qr.ppDown, (float) qr.threshDown); bits.resize(18); bits.zero(); for (int i = 0; i < 18; i++) { int row = i%3; int col = i/3; read(i,row-4,col); } // Syst...
java
public static void hessianBorder(GrayF32 integral, int skip , int size , GrayF32 intensity) { final int w = intensity.width; final int h = intensity.height; // get convolution kernels for the second order derivatives IntegralKernel kerXX = DerivativeIntegralImage.kernelDerivXX(size,null); Integral...
java
public static GrayU8 logicAnd(GrayU8 inputA , GrayU8 inputB , GrayU8 output ) { InputSanityCheck.checkSameShape(inputA,inputB); output = InputSanityCheck.checkDeclare(inputA, output); if( BoofConcurrency.USE_CONCURRENT ) { ImplBinaryImageOps_MT.logicAnd(inputA, inputB, output); } else { ImplBinaryImageO...
java
public static GrayU8 invert(GrayU8 input , GrayU8 output) { output = InputSanityCheck.checkDeclare(input, output); if( BoofConcurrency.USE_CONCURRENT ) { ImplBinaryImageOps_MT.invert(input, output); } else { ImplBinaryImageOps.invert(input, output); } return output; }
java
public static GrayU8 thin(GrayU8 input , int maxIterations, GrayU8 output ) { output = InputSanityCheck.checkDeclare(input, output); output.setTo(input); BinaryThinning thinning = new BinaryThinning(); thinning.apply(output,maxIterations); return output; }
java
public static List<Contour> contourExternal(GrayU8 input, ConnectRule rule ) { BinaryContourFinder alg = FactoryBinaryContourFinder.linearExternal(); alg.setConnectRule(rule); alg.process(input); return convertContours(alg); }
java
public static void relabel(GrayS32 input , int labels[] ) { if( BoofConcurrency.USE_CONCURRENT ) { ImplBinaryImageOps_MT.relabel(input, labels); } else { ImplBinaryImageOps.relabel(input, labels); } }
java
public static GrayU8 labelToBinary(GrayS32 labelImage , GrayU8 binaryImage ) { binaryImage = InputSanityCheck.checkDeclare(labelImage, binaryImage, GrayU8.class); if( BoofConcurrency.USE_CONCURRENT ) { ImplBinaryImageOps_MT.labelToBinary(labelImage, binaryImage); } else { ImplBinaryImageOps.labelToBinary(l...
java
public static List<List<Point2D_I32>> labelToClusters( GrayS32 labelImage , int numLabels , FastQueue<Point2D_I32> queue ) { List<List<Point2D_I32>> ret = new ArrayList<>(); for( int i = 0; i < numLabels+1; i++ ) { ret.add( new ArrayList<Point2D_I32>() ); } if( queue == nul...
java
public static void clusterToBinary( List<List<Point2D_I32>> clusters , GrayU8 binary ) { ImageMiscOps.fill(binary, 0); for( List<Point2D_I32> l : clusters ) { for( Point2D_I32 p : l ) { binary.set(p.x,p.y,1); } } }
java
public static int[] selectRandomColors( int numBlobs , Random rand ) { int colors[] = new int[ numBlobs+1 ]; colors[0] = 0; // black int B = 100; for( int i = 1; i < colors.length; i++ ) { int c; while( true ) { c = rand.nextInt(0xFFFFFF); // make sure its not too dark and can't be distriquished...
java
public static void bufferDepthToU16( ByteBuffer input , GrayU16 output ) { int indexIn = 0; for( int y = 0; y < output.height; y++ ) { int indexOut = output.startIndex + y*output.stride; for( int x = 0; x < output.width; x++ , indexOut++ ) { output.data[indexOut] = (short)((input.get(indexIn++) & 0xFF) | ...
java
public static void bufferRgbToMsU8( byte []input , Planar<GrayU8> output ) { GrayU8 band0 = output.getBand(0); GrayU8 band1 = output.getBand(1); GrayU8 band2 = output.getBand(2); int indexIn = 0; for( int y = 0; y < output.height; y++ ) { int indexOut = output.startIndex + y*output.stride; for( int x =...
java
public void computeECC( GrowQueue_I8 input , GrowQueue_I8 output ) { int N = generator.size-1; input.extend(input.size+N); Arrays.fill(input.data,input.size-N,input.size,(byte)0); math.polyDivide(input,generator,tmp0,output); input.size -= N; }
java
public boolean correct(GrowQueue_I8 input , GrowQueue_I8 ecc ) { computeSyndromes(input,ecc,syndromes); findErrorLocatorPolynomialBM(syndromes,errorLocatorPoly); if( !findErrorLocations_BruteForce(errorLocatorPoly,input.size+ecc.size,errorLocations)) return false; correctErrors(input,input.size+ecc.size,sy...
java
void findErrorLocatorPolynomial( int messageLength , GrowQueue_I32 errorLocations , GrowQueue_I8 errorLocator ) { tmp1.resize(2); tmp1.data[1] = 1; errorLocator.resize(1); errorLocator.data[0] = 1; for (int i = 0; i < errorLocations.size; i++) { // Convert from positions in the message to coefficient degre...
java
public boolean findErrorLocations_BruteForce(GrowQueue_I8 errorLocator , int messageLength , GrowQueue_I32 locations ) { locations.resize(0); for (int i = 0; i < messageLength; i++) { if( math.polyEval_S(errorLocator,math.power(2,i)) == 0 ) { locations.add(messageLength-i-1); } ...
java
void correctErrors( GrowQueue_I8 message , int length_msg_ecc, GrowQueue_I8 syndromes, GrowQueue_I8 errorLocator , GrowQueue_I32 errorLocations) { GrowQueue_I8 err_eval = new GrowQueue_I8(); // TODO avoid new findErrorEvaluator(syndromes,errorLocator,err_eval); // Compute error positions...
java