/** * Specify the data range * * @param minValue Minimum allowed value. (inclusive) * @param maxValue Maximum allowed value. (inclusive) */ public void setRange( int minValue , int maxValue ) { this.maxValue = maxValue; this.minValue = minValue; histogram.resize(maxValue-minValue+1); histIndexes.resize(maxValue-minValue+1); }
/** * Specify the data range * * @param minValue Minimum allowed value. (inclusive) * @param maxValue Maximum allowed value. (inclusive) */ public void setRange( int minValue , int maxValue ) { this.maxValue = maxValue; this.minValue = minValue; histogram.resize(maxValue-minValue+1); histIndexes.resize(maxValue-minValue+1); }
/** * prepares all data structures */ protected void initalize(T input) { this.input = input; pixels.resize(input.width * input.height); initialSegments.reshape(input.width, input.height); // number of usable pixels that cluster centers can be placed in int numberOfUsable = (input.width-2*BORDER)*(input.height-2*BORDER); gridInterval = (int)Math.sqrt( numberOfUsable/(double)numberOfRegions); if( gridInterval <= 0 ) throw new IllegalArgumentException("Too many regions for an image of this size"); // See equation (1) adjustSpacial = m/gridInterval; }
/** * Specify the data range * * @param minValue Minimum allowed value. (inclusive) * @param maxValue Maximum allowed value. (inclusive) */ public void setRange( float minValue , float maxValue ) { this.maxValue = maxValue; this.minValue = minValue; divisor = 1.00001*(maxValue-minValue)/numBins; histIndexes.resize(numBins); if( histObjs.length < numBins ) { histObjs = new FastQueue[ numBins ]; for (int i = 0; i < numBins; i++) { histObjs[i] = new FastQueue<SortableParameter_F32>(SortableParameter_F32.class,true); } } }
/** * Precomputes likelihood for all the mixtures */ public void precomputeAll() { precomputes.resize(mixtures.size()); for (int i = 0; i < precomputes.size; i++) { precomputes.get(i).setGaussian(mixtures.get(i)); } }
/** * Specify the data range * * @param minValue Minimum allowed value. (inclusive) * @param maxValue Maximum allowed value. (inclusive) */ public void setRange( double minValue , double maxValue ) { this.maxValue = maxValue; this.minValue = minValue; divisor = 1.00001*(maxValue-minValue)/numBins; histIndexes.resize(numBins); if( histObjs.length < numBins ) { histObjs = new FastQueue[ numBins ]; for (int i = 0; i < numBins; i++) { histObjs[i] = new FastQueue<SortableParameter_F64>(SortableParameter_F64.class,true); } } }
/** * Specify the data range * * @param minValue Minimum allowed value. (inclusive) * @param maxValue Maximum allowed value. (inclusive) */ public void setRange( double minValue , double maxValue ) { this.maxValue = maxValue; this.minValue = minValue; divisor = 1.00001*(maxValue-minValue)/numBins; histIndexes.resize(numBins); if( histObjs.length < numBins ) { histObjs = new FastQueue[ numBins ]; for (int i = 0; i < numBins; i++) { histObjs[i] = new FastQueue<SortableParameter_F64>(SortableParameter_F64.class,true); } } }
/** * Precomputes likelihood for all the mixtures */ public void precomputeAll() { precomputes.resize(mixtures.size()); for (int i = 0; i < precomputes.size; i++) { precomputes.get(i).setGaussian(mixtures.get(i)); } }
/** * Specify the data range * * @param minValue Minimum allowed value. (inclusive) * @param maxValue Maximum allowed value. (inclusive) */ public void setRange( float minValue , float maxValue ) { this.maxValue = maxValue; this.minValue = minValue; divisor = 1.00001*(maxValue-minValue)/numBins; histIndexes.resize(numBins); if( histObjs.length < numBins ) { histObjs = new FastQueue[ numBins ]; for (int i = 0; i < numBins; i++) { histObjs[i] = new FastQueue<SortableParameter_F32>(SortableParameter_F32.class,true); } } }
/** * Specifies the input image size and the size of the grid it will use to approximate the idea solution. All * control points are discarded * * @param width Image width * @param height Image height * @param gridRows grid rows * @param gridCols grid columns */ public void configure( int width , int height , int gridRows , int gridCols ) { // need to maintain the same ratio of pixels in the grid as in the regular image for similarity and rigid // to work correctly int s = Math.max(width,height); scaleX = s/(float)(gridCols-1); scaleY = s/(float)(gridRows-1); if( gridRows > gridCols ) { scaleY /= (gridCols-1)/ (float) (gridRows-1); } else { scaleX /= (gridRows-1)/ (float) (gridCols-1); } this.gridRows = gridRows; this.gridCols = gridCols; grid.resize(gridCols*gridRows); reset(); }
/** * Update each track's location only and not its description. Update the active list too */ protected void updateTrackLocation( SetTrackInfo<Desc> info, FastQueue<AssociatedIndex> matches) { info.matches.resize(matches.size); for (int i = 0; i < matches.size; i++) { info.matches.get(i).set(matches.get(i)); } tracksActive.clear(); for( int i = 0; i < info.matches.size; i++ ) { AssociatedIndex indexes = info.matches.data[i]; PointTrack track = info.tracks.get(indexes.src); Point2D_F64 loc = info.locDst.data[indexes.dst]; track.set(loc.x, loc.y); tracksActive.add(track); } }
/** * Recycles and initializes all internal data structures */ private void init(List<EllipseRotated_F64> ellipses) { searchPoints.resize(ellipses.size()); nodes.resize(ellipses.size()); clusters.reset(); for (int i = 0; i < ellipses.size(); i++) { EllipseRotated_F64 e = ellipses.get(i); double[] p = searchPoints.get(i); p[0] = e.center.x; p[1] = e.center.y; Node n = nodes.get(i); n.connections.reset(); n.which = i; n.cluster = -1; } search.setPoints(searchPoints.toList(),nodes.toList()); }
void init(Grid grid) { tangents.resize(totalEllipses(grid.rows,grid.columns)); for (int i = 0; i < tangents.size(); i++) { tangents.get(i).reset(); } }
@Override public boolean process(List<Point2D3D> points, Se3_F64 estimatedModel) { pairs.resize(points.size()); for (int i = 0; i < pairs.size; i++) { AssociatedPair pair = pairs.get(i); Point2D3D p = points.get(i); if( p.location.z != 0 ) { throw new IllegalArgumentException("All points must lie on the x-y plane. If data is planar rotate it first"); } pair.p1.set(p.location.x,p.location.y); pair.p2.set(p.observation); } if( !alg.process(pairs.toList())) return false; estimatedModel.set(alg.getWorldToCamera0()); return true; }
@Override protected void fitShape(List<Point2D_I32> contour) { if( !alg.process(contour) ) return; PolylineSplitMerge.CandidatePolyline best = alg.getBestPolyline(); Polygon2D_I32 poly = workPoly.grow(); poly.vertexes.resize(best.splits.size); for (int i = 0; i < best.splits.size; i++) { Point2D_I32 p = contour.get(best.splits.get(i)); poly.get(i).set(p); } }
/** * Precompute the portion of the equation which only concerns the undistorted location of each point on the * grid even the current undistorted location of each control point. */ public void fixateUndistorted() { if( controls.size() < 2 ) throw new RuntimeException("Not enough control points specified. Found "+controls.size()); for (int row = 0; row < gridRows; row++) { for (int col = 0; col < gridCols; col++) { Cache cache = getGrid(row,col); cache.weights.resize(controls.size); cache.A.resize(controls.size); cache.A_s.resize(controls.size()); float v_x = col; float v_y = row; computeWeights(cache, v_x, v_y); computeAverageP(cache); model.computeCache(cache, v_x, v_y); } } }
private void performSegmentation() { long before = System.currentTimeMillis(); alg.segment(color, pixelToRegion); long after = System.currentTimeMillis(); System.out.println("Total time "+(after-before)); int numSegments = alg.getTotalSuperpixels(); // Computes the mean color inside each region ImageType<T> type = color.getImageType(); ComputeRegionMeanColor<T> colorize = FactorySegmentationAlg.regionMeanColor(type); FastQueue<float[]> segmentColor = new ColorQueue_F32(type.getNumBands()); segmentColor.resize(numSegments); GrowQueue_I32 regionMemberCount = new GrowQueue_I32(); regionMemberCount.resize(numSegments); ImageSegmentationOps.countRegionPixels(pixelToRegion, numSegments, regionMemberCount.data); colorize.process(color,pixelToRegion,regionMemberCount,segmentColor); VisualizeRegions.regionsColor(pixelToRegion,segmentColor,outColor); VisualizeRegions.regions(pixelToRegion,segmentColor.size(),outSegments); // Make edges appear black ConvertBufferedImage.convertTo(color,outBorder,true); VisualizeRegions.regionBorders(pixelToRegion,0x000000,outBorder); }
protected void performTracking( SetTrackInfo<Desc> info ) { // create source list putIntoSrcList(info); // associate features together associate.setSource(info.locSrc, info.featSrc); associate.setDestination(info.locDst, info.featDst); associate.associate(); // used in spawn tracks. if null then no tracking data is assumed FastQueue<AssociatedIndex> matches = associate.getMatches(); // create a copy since the data will be recycled if there are multiple sets of points info.matches.resize(matches.size); for (int i = 0; i < matches.size; i++) { info.matches.get(i).set(matches.get(i)); } // Update the track state using association information updateTrackState(info); }
@Override public void segment(T input, GrayS32 output) { InputSanityCheck.checkSameShape(input,output); converted.reshape(input.width,input.height); GConvertImage.convert(input,converted); // segment the image alg.process(converted); alg.removeWatersheds(); numRegions = alg.getTotalRegions(); GrayS32 pixelToRegion = alg.getOutput(); // Merge small regions together if( pruneSmall != null ) { regionMemberCount.resize(numRegions); regionColor.resize(numRegions); ImageSegmentationOps.countRegionPixels(pixelToRegion,numRegions,regionMemberCount.data); pruneSmall.process(converted,pixelToRegion,regionMemberCount,regionColor); numRegions = regionMemberCount.size(); } output.setTo(pixelToRegion); }
@Test public void updateClusterCenters() { StandardKMeans_F64 alg = new StandardKMeans_F64(100,100,1,new InitializeStandard_F64()); alg.init(4,123); alg.clusters.resize(3); alg.workClusters.resize(3); alg.memberCount.resize(3); double orig[][] = new double[3][4]; orig[0] = new double[]{10,20,30,20}; orig[1] = new double[]{20,10,30,40}; orig[2] = new double[]{3,9,1,12}; alg.workClusters.data[0] = orig[0].clone(); alg.workClusters.data[1] = orig[1].clone(); alg.workClusters.data[2] = orig[2].clone(); alg.memberCount.data[0] = 10; alg.memberCount.data[1] = 1; alg.memberCount.data[2] = 3; // previous clusters will be near zero alg.updateClusterCenters(); for (int i = 0; i < 4; i++) { assertEquals(alg.clusters.data[0][i],orig[0][i]/10); assertEquals(alg.clusters.data[1][i],orig[1][i]/1); assertEquals(alg.clusters.data[2][i],orig[2][i]/3); } }