idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
27,400 | public static void trace ( GrayF32 featureIntensity , GrayF32 hessianXX , GrayF32 hessianYY ) { InputSanityCheck . checkSameShape ( featureIntensity , hessianXX , hessianYY ) ; ImplHessianBlobIntensity . trace ( featureIntensity , hessianXX , hessianYY ) ; } | Feature intensity using the trace of the Hessian matrix . This is also known as the Laplacian . | 80 | 22 |
27,401 | public void reshape ( int width , int height ) { if ( padded == null ) { binary . reshape ( width , height ) ; } else { binary . reshape ( width + 2 , height + 2 ) ; binary . subimage ( 1 , 1 , width + 1 , height + 1 , subimage ) ; } } | Reshapes data so that the un - padded image has the specified shape . | 69 | 16 |
27,402 | public boolean computeEdge ( Polygon2D_F64 polygon , boolean ccw ) { averageInside = 0 ; averageOutside = 0 ; double tangentSign = ccw ? 1 : - 1 ; int totalSides = 0 ; for ( int i = polygon . size ( ) - 1 , j = 0 ; j < polygon . size ( ) ; i = j , j ++ ) { Point2D_F64 a = polygon . get ( i ) ; Point2D_F64 b = polygon . get ( j ) ; double dx = b . x - a . x ; double dy = b . y - a . y ; double t = Math . sqrt ( dx * dx + dy * dy ) ; dx /= t ; dy /= t ; // see if the side is too small if ( t < 3 * cornerOffset ) { offsetA . set ( a ) ; offsetB . set ( b ) ; } else { offsetA . x = a . x + cornerOffset * dx ; offsetA . y = a . y + cornerOffset * dy ; offsetB . x = b . x - cornerOffset * dx ; offsetB . y = b . y - cornerOffset * dy ; } double tanX = - dy * tangentDistance * tangentSign ; double tanY = dx * tangentDistance * tangentSign ; scorer . computeAverageDerivative ( offsetA , offsetB , tanX , tanY ) ; if ( scorer . getSamplesInside ( ) > 0 ) { totalSides ++ ; averageInside += scorer . getAverageUp ( ) / tangentDistance ; averageOutside += scorer . getAverageDown ( ) / tangentDistance ; } } if ( totalSides > 0 ) { averageInside /= totalSides ; averageOutside /= totalSides ; } else { averageInside = averageOutside = 0 ; return false ; } return true ; } | Checks to see if its a valid polygon or a false positive by looking at edge intensity | 405 | 19 |
27,403 | public boolean checkIntensity ( boolean insideDark , double threshold ) { if ( insideDark ) return averageOutside - averageInside >= threshold ; else return averageInside - averageOutside >= threshold ; } | Checks the edge intensity against a threshold . | 39 | 9 |
27,404 | public void setCamera ( double skew , double cx , double cy , int width , int height ) { // Define normalization matrix // center points, remove skew, scale coordinates double d = Math . sqrt ( width * width + height * height ) ; V . zero ( ) ; V . set ( 0 , 0 , d / 2 ) ; V . set ( 0 , 1 , skew ) ; V . set ( 0 , 2 , cx ) ; V . set ( 1 , 1 , d / 2 ) ; V . set ( 1 , 2 , cy ) ; V . set ( 2 , 2 , 1 ) ; CommonOps_DDRM . invert ( V , Vinv ) ; } | Specifies known portions of camera intrinsic parameters | 146 | 8 |
27,405 | public void setSampling ( double min , double max , int total ) { this . sampleMin = min ; this . sampleMax = max ; this . numSamples = total ; this . scores = new double [ numSamples ] ; } | Specifies how focal lengths are sampled on a log scale . Remember 1 . 0 = nominal length | 51 | 19 |
27,406 | boolean computeRectifyH ( double f1 , double f2 , DMatrixRMaj P2 , DMatrixRMaj H ) { estimatePlaneInf . setCamera1 ( f1 , f1 , 0 , 0 , 0 ) ; estimatePlaneInf . setCamera2 ( f2 , f2 , 0 , 0 , 0 ) ; if ( ! estimatePlaneInf . estimatePlaneAtInfinity ( P2 , planeInf ) ) return false ; // TODO add a cost for distance from nominal and scale other cost by focal length fx for each view // RefineDualQuadraticConstraint refine = new RefineDualQuadraticConstraint(); // refine.setZeroSkew(true); // refine.setAspectRatio(true); // refine.setZeroPrinciplePoint(true); // refine.setKnownIntrinsic1(true); // refine.setFixedCamera(false); // // CameraPinhole intrinsic = new CameraPinhole(f1,f1,0,0,0,0,0); // if( !refine.refine(normalizedP.toList(),intrinsic,planeInf)) // return false; K1 . zero ( ) ; K1 . set ( 0 , 0 , f1 ) ; K1 . set ( 1 , 1 , f1 ) ; K1 . set ( 2 , 2 , 1 ) ; MultiViewOps . createProjectiveToMetric ( K1 , planeInf . x , planeInf . y , planeInf . z , 1 , H ) ; return true ; } | Given the focal lengths for the first two views compute homography H | 340 | 13 |
27,407 | protected static List < NodeInfo > findLine ( NodeInfo seed , NodeInfo next , int clusterSize , List < NodeInfo > line , boolean ccw ) { if ( next == null ) return null ; if ( line == null ) line = new ArrayList <> ( ) ; else line . clear ( ) ; next . marked = true ; double anglePrev = direction ( next , seed ) ; double prevDist = next . ellipse . center . distance ( seed . ellipse . center ) ; line . add ( seed ) ; line . add ( next ) ; NodeInfo previous = seed ; for ( int i = 0 ; i < clusterSize + 1 ; i ++ ) { // find the child of next which is within tolerance and closest to it double bestScore = Double . MAX_VALUE ; double bestDistance = Double . MAX_VALUE ; double bestAngle = Double . NaN ; double closestDistance = Double . MAX_VALUE ; NodeInfo best = null ; double previousLength = next . ellipse . center . distance ( previous . ellipse . center ) ; // System.out.println("---- line connecting "+i); for ( int j = 0 ; j < next . edges . size ( ) ; j ++ ) { double angle = next . edges . get ( j ) . angle ; NodeInfo c = next . edges . get ( j ) . target ; if ( c . marked ) continue ; double candidateLength = next . ellipse . center . distance ( c . ellipse . center ) ; double ratioLengths = previousLength / candidateLength ; double ratioSize = previous . ellipse . a / c . ellipse . a ; if ( ratioLengths > 1 ) { ratioLengths = 1.0 / ratioLengths ; ratioSize = 1.0 / ratioSize ; } if ( Math . abs ( ratioLengths - ratioSize ) > 0.4 ) continue ; double angleDist = ccw ? UtilAngle . distanceCCW ( anglePrev , angle ) : UtilAngle . distanceCW ( anglePrev , angle ) ; if ( angleDist <= Math . PI + MAX_LINE_ANGLE_CHANGE ) { double d = c . ellipse . center . distance ( next . ellipse . center ) ; double score = d / prevDist + angleDist ; if ( score < bestScore ) { // System.out.println(" ratios: "+ratioLengths+" "+ratioSize); bestDistance = d ; bestScore = score ; bestAngle = angle ; best = c ; } closestDistance = Math . min ( d , closestDistance ) ; } } if ( best == null || bestDistance > closestDistance * 2.0 ) { return line ; } else { best . marked = true ; prevDist = bestDistance ; line . add ( best ) ; anglePrev = UtilAngle . bound ( bestAngle + Math . PI ) ; previous = next ; next = best ; } } // if( verbose ) { // System.out.println("Stuck in a loop? Maximum line length exceeded"); // } return null ; } | Finds all the nodes which form an approximate line | 660 | 10 |
27,408 | protected static NodeInfo findClosestEdge ( NodeInfo n , Point2D_F64 p ) { double bestDistance = Double . MAX_VALUE ; NodeInfo best = null ; for ( int i = 0 ; i < n . edges . size ( ) ; i ++ ) { Edge e = n . edges . get ( i ) ; if ( e . target . marked ) continue ; double d = e . target . ellipse . center . distance2 ( p ) ; if ( d < bestDistance ) { bestDistance = d ; best = e . target ; } } return best ; } | Finds the node which is an edge of n that is closest to point p | 126 | 16 |
27,409 | boolean checkDuplicates ( List < List < NodeInfo > > grid ) { for ( int i = 0 ; i < listInfo . size ; i ++ ) { listInfo . get ( i ) . marked = false ; } for ( int i = 0 ; i < grid . size ( ) ; i ++ ) { List < NodeInfo > list = grid . get ( i ) ; for ( int j = 0 ; j < list . size ( ) ; j ++ ) { NodeInfo n = list . get ( j ) ; if ( n . marked ) return true ; n . marked = true ; } } return false ; } | Checks to see if any node is used more than once | 133 | 12 |
27,410 | void addEdgesToInfo ( List < Node > cluster ) { for ( int i = 0 ; i < cluster . size ( ) ; i ++ ) { Node n = cluster . get ( i ) ; NodeInfo infoA = listInfo . get ( i ) ; EllipseRotated_F64 a = infoA . ellipse ; // create the edges and order them based on their direction for ( int j = 0 ; j < n . connections . size ( ) ; j ++ ) { NodeInfo infoB = listInfo . get ( indexOf ( cluster , n . connections . get ( j ) ) ) ; EllipseRotated_F64 b = infoB . ellipse ; Edge edge = infoA . edges . grow ( ) ; edge . target = infoB ; edge . angle = Math . atan2 ( b . center . y - a . center . y , b . center . x - a . center . x ) ; } sorter . sort ( infoA . edges . data , infoA . edges . size ) ; } } | Adds edges to node info and computes their orientation | 225 | 10 |
27,411 | void pruneNearlyIdenticalAngles ( ) { for ( int i = 0 ; i < listInfo . size ( ) ; i ++ ) { NodeInfo infoN = listInfo . get ( i ) ; for ( int j = 0 ; j < infoN . edges . size ( ) ; ) { int k = ( j + 1 ) % infoN . edges . size ; double angularDiff = UtilAngle . dist ( infoN . edges . get ( j ) . angle , infoN . edges . get ( k ) . angle ) ; if ( angularDiff < UtilAngle . radian ( 5 ) ) { NodeInfo infoJ = infoN . edges . get ( j ) . target ; NodeInfo infoK = infoN . edges . get ( k ) . target ; double distJ = infoN . ellipse . center . distance ( infoJ . ellipse . center ) ; double distK = infoN . ellipse . center . distance ( infoK . ellipse . center ) ; if ( distJ < distK ) { infoN . edges . remove ( k ) ; } else { infoN . edges . remove ( j ) ; } } else { j ++ ; } } } } | If there is a nearly perfect line a node farther down the line can come before . This just selects the closest | 260 | 22 |
27,412 | void findLargestAnglesForAllNodes ( ) { for ( int i = 0 ; i < listInfo . size ( ) ; i ++ ) { NodeInfo info = listInfo . get ( i ) ; if ( info . edges . size < 2 ) continue ; for ( int k = 0 , j = info . edges . size - 1 ; k < info . edges . size ; j = k , k ++ ) { double angleA = info . edges . get ( j ) . angle ; double angleB = info . edges . get ( k ) . angle ; double distance = UtilAngle . distanceCCW ( angleA , angleB ) ; if ( distance > info . angleBetween ) { info . angleBetween = distance ; info . left = info . edges . get ( j ) . target ; info . right = info . edges . get ( k ) . target ; } } } } | Finds the two edges with the greatest angular distance between them . | 191 | 13 |
27,413 | boolean findContour ( boolean mustHaveInner ) { // find the node with the largest angleBetween NodeInfo seed = listInfo . get ( 0 ) ; for ( int i = 1 ; i < listInfo . size ( ) ; i ++ ) { NodeInfo info = listInfo . get ( i ) ; if ( info . angleBetween > seed . angleBetween ) { seed = info ; } } // trace around the contour contour . reset ( ) ; contour . add ( seed ) ; seed . contour = true ; NodeInfo prev = seed ; NodeInfo current = seed . right ; while ( current != null && current != seed && contour . size ( ) < listInfo . size ( ) ) { if ( prev != current . left ) return false ; contour . add ( current ) ; current . contour = true ; prev = current ; current = current . right ; } // fail if it is too small or was cycling return ! ( contour . size < 4 || ( mustHaveInner && contour . size >= listInfo . size ( ) ) ) ; } | Finds nodes in the outside of the grid . First the node in the grid with the largest angleBetween is selected as a seed . It is assumed at this node must be on the contour . Then the graph is traversed in CCW direction until a loop is formed . | 230 | 56 |
27,414 | public static int indexOf ( List < Node > list , int value ) { for ( int i = 0 ; i < list . size ( ) ; i ++ ) { if ( list . get ( i ) . which == value ) return i ; } return - 1 ; } | Finds the node with the index of value | 57 | 9 |
27,415 | NodeInfo selectSeedCorner ( ) { NodeInfo best = null ; double bestAngle = 0 ; for ( int i = 0 ; i < contour . size ; i ++ ) { NodeInfo info = contour . get ( i ) ; if ( info . angleBetween > bestAngle ) { bestAngle = info . angleBetween ; best = info ; } } best . marked = true ; return best ; } | Pick the node in the contour with the largest angle . Distortion tends to make the acute angle smaller . Without distortion it will be 270 degrees . | 90 | 30 |
27,416 | public static void depthTo3D ( CameraPinholeBrown param , GrayU16 depth , FastQueue < Point3D_F64 > cloud ) { cloud . reset ( ) ; Point2Transform2_F64 p2n = LensDistortionFactory . narrow ( param ) . undistort_F64 ( true , false ) ; Point2D_F64 n = new Point2D_F64 ( ) ; for ( int y = 0 ; y < depth . height ; y ++ ) { int index = depth . startIndex + y * depth . stride ; for ( int x = 0 ; x < depth . width ; x ++ ) { int mm = depth . data [ index ++ ] & 0xFFFF ; // skip pixels with no depth information if ( mm == 0 ) continue ; // this could all be precomputed to speed it up p2n . compute ( x , y , n ) ; Point3D_F64 p = cloud . grow ( ) ; p . z = mm ; p . x = n . x * p . z ; p . y = n . y * p . z ; } } } | Creates a point cloud from a depth image . | 239 | 10 |
27,417 | public static void depthTo3D ( CameraPinholeBrown param , Planar < GrayU8 > rgb , GrayU16 depth , FastQueue < Point3D_F64 > cloud , FastQueueArray_I32 cloudColor ) { cloud . reset ( ) ; cloudColor . reset ( ) ; RemoveBrownPtoN_F64 p2n = new RemoveBrownPtoN_F64 ( ) ; p2n . setK ( param . fx , param . fy , param . skew , param . cx , param . cy ) . setDistortion ( param . radial , param . t1 , param . t2 ) ; Point2D_F64 n = new Point2D_F64 ( ) ; GrayU8 colorR = rgb . getBand ( 0 ) ; GrayU8 colorG = rgb . getBand ( 1 ) ; GrayU8 colorB = rgb . getBand ( 2 ) ; for ( int y = 0 ; y < depth . height ; y ++ ) { int index = depth . startIndex + y * depth . stride ; for ( int x = 0 ; x < depth . width ; x ++ ) { int mm = depth . data [ index ++ ] & 0xFFFF ; // skip pixels with no depth information if ( mm == 0 ) continue ; // this could all be precomputed to speed it up p2n . compute ( x , y , n ) ; Point3D_F64 p = cloud . grow ( ) ; p . z = mm ; p . x = n . x * p . z ; p . y = n . y * p . z ; int color [ ] = cloudColor . grow ( ) ; color [ 0 ] = colorR . unsafe_get ( x , y ) ; color [ 1 ] = colorG . unsafe_get ( x , y ) ; color [ 2 ] = colorB . unsafe_get ( x , y ) ; } } } | Creates a point cloud from a depth image and saves the color information . The depth and color images are assumed to be aligned . | 409 | 26 |
27,418 | public boolean prune ( List < Point2D_I32 > contour , GrowQueue_I32 input , GrowQueue_I32 output ) { this . contour = contour ; output . setTo ( input ) ; removeDuplicates ( output ) ; // can't prune a corner and it will still be a polygon if ( output . size ( ) <= 3 ) return false ; computeSegmentEnergy ( output ) ; double total = 0 ; for ( int i = 0 ; i < output . size ( ) ; i ++ ) { total += energySegment [ i ] ; } FitLinesToContour fit = new FitLinesToContour ( ) ; fit . setContour ( contour ) ; boolean modified = false ; while ( output . size ( ) > 3 ) { double bestEnergy = total ; boolean betterFound = false ; bestCorners . reset ( ) ; for ( int i = 0 ; i < output . size ( ) ; i ++ ) { // add all but the one which was removed workCorners1 . reset ( ) ; for ( int j = 0 ; j < output . size ( ) ; j ++ ) { if ( i != j ) { workCorners1 . add ( output . get ( j ) ) ; } } // just in case it created a duplicate removeDuplicates ( workCorners1 ) ; if ( workCorners1 . size ( ) > 3 ) { // when looking at these anchors remember that they are relative to the new list without // the removed corner and that the two adjacent corners need to be optimized int anchor0 = CircularIndex . addOffset ( i , - 2 , workCorners1 . size ( ) ) ; int anchor1 = CircularIndex . addOffset ( i , 1 , workCorners1 . size ( ) ) ; // optimize the two adjacent corners to the removed one if ( fit . fitAnchored ( anchor0 , anchor1 , workCorners1 , workCorners2 ) ) { // TODO this isn't taking advantage of previously computed line segment energy is it? // maybe a small speed up can be had by doing that double score = 0 ; for ( int j = 0 , k = workCorners2 . size ( ) - 1 ; j < workCorners2 . size ( ) ; k = j , j ++ ) { score += computeSegmentEnergy ( workCorners2 , k , j ) ; } if ( score < bestEnergy ) { betterFound = true ; bestEnergy = score ; bestCorners . reset ( ) ; bestCorners . addAll ( workCorners2 ) ; } } } } if ( betterFound ) { modified = true ; total = bestEnergy ; output . setTo ( bestCorners ) ; } else { break ; } } return modified ; } | Given a contour and initial set of corners compute a new set of corner indexes | 591 | 16 |
27,419 | void removeDuplicates ( GrowQueue_I32 corners ) { // remove duplicates for ( int i = 0 ; i < corners . size ( ) ; i ++ ) { Point2D_I32 a = contour . get ( corners . get ( i ) ) ; // start from the top so that removing a corner doesn't mess with the for loop for ( int j = corners . size ( ) - 1 ; j > i ; j -- ) { Point2D_I32 b = contour . get ( corners . get ( j ) ) ; if ( a . x == b . x && a . y == b . y ) { // this is still ok if j == 0 because it wrapped around. 'i' will now be > size corners . remove ( j ) ; } } } } | Look for two corners which point to the same point and removes one of them from the corner list | 169 | 19 |
27,420 | void computeSegmentEnergy ( GrowQueue_I32 corners ) { if ( energySegment . length < corners . size ( ) ) { energySegment = new double [ corners . size ( ) ] ; } for ( int i = 0 , j = corners . size ( ) - 1 ; i < corners . size ( ) ; j = i , i ++ ) { energySegment [ j ] = computeSegmentEnergy ( corners , j , i ) ; } } | Computes the energy of each segment individually | 98 | 8 |
27,421 | protected double energyRemoveCorner ( int removed , GrowQueue_I32 corners ) { double total = 0 ; int cornerA = CircularIndex . addOffset ( removed , - 1 , corners . size ( ) ) ; int cornerB = CircularIndex . addOffset ( removed , 1 , corners . size ( ) ) ; total += computeSegmentEnergy ( corners , cornerA , cornerB ) ; if ( cornerA > cornerB ) { for ( int i = cornerB ; i < cornerA ; i ++ ) total += energySegment [ i ] ; } else { for ( int i = 0 ; i < cornerA ; i ++ ) { total += energySegment [ i ] ; } for ( int i = cornerB ; i < corners . size ( ) ; i ++ ) { total += energySegment [ i ] ; } } return total ; } | Returns the total energy after removing a corner | 182 | 8 |
27,422 | protected double computeSegmentEnergy ( GrowQueue_I32 corners , int cornerA , int cornerB ) { int indexA = corners . get ( cornerA ) ; int indexB = corners . get ( cornerB ) ; if ( indexA == indexB ) { return 100000.0 ; } Point2D_I32 a = contour . get ( indexA ) ; Point2D_I32 b = contour . get ( indexB ) ; line . p . x = a . x ; line . p . y = a . y ; line . slope . set ( b . x - a . x , b . y - a . y ) ; double total = 0 ; int length = circularDistance ( indexA , indexB ) ; for ( int k = 1 ; k < length ; k ++ ) { Point2D_I32 c = getContour ( indexA + 1 + k ) ; point . set ( c . x , c . y ) ; total += Distance2D_F64 . distanceSq ( line , point ) ; } return ( total + splitPenalty ) / a . distance2 ( b ) ; } | Computes the energy for a segment defined by the two corner indexes | 243 | 13 |
27,423 | public void process ( T image , GrayS32 pixelToRegion , GrowQueue_I32 regionMemberCount , FastQueue < float [ ] > regionColor ) { stopRequested = false ; // iterate until no more regions need to be merged together while ( ! stopRequested ) { // Update the color of each region regionColor . resize ( regionMemberCount . size ) ; computeColor . process ( image , pixelToRegion , regionMemberCount , regionColor ) ; initializeMerge ( regionMemberCount . size ) ; // Create a list of regions which are to be pruned if ( ! setupPruneList ( regionMemberCount ) ) break ; // Scan the image and create a list of regions which the pruned regions connect to findAdjacentRegions ( pixelToRegion ) ; // Select the closest match to merge into for ( int i = 0 ; i < pruneGraph . size ; i ++ ) { selectMerge ( i , regionColor ) ; } // Do the usual merge stuff performMerge ( pixelToRegion , regionMemberCount ) ; } } | Merges together smaller regions . Segmented image region member count and region color are all updated . | 224 | 20 |
27,424 | protected boolean setupPruneList ( GrowQueue_I32 regionMemberCount ) { segmentPruneFlag . resize ( regionMemberCount . size ) ; pruneGraph . reset ( ) ; segmentToPruneID . resize ( regionMemberCount . size ) ; for ( int i = 0 ; i < regionMemberCount . size ; i ++ ) { if ( regionMemberCount . get ( i ) < minimumSize ) { segmentToPruneID . set ( i , pruneGraph . size ( ) ) ; Node n = pruneGraph . grow ( ) ; n . init ( i ) ; segmentPruneFlag . set ( i , true ) ; } else { segmentPruneFlag . set ( i , false ) ; } } return pruneGraph . size ( ) != 0 ; } | Identifies which regions are to be pruned based on their member counts . Then sets up data structures for graph and converting segment ID to prune ID . | 166 | 31 |
27,425 | protected void findAdjacentRegions ( GrayS32 pixelToRegion ) { // -------- Do the inner pixels first if ( connect . length == 4 ) adjacentInner4 ( pixelToRegion ) ; else if ( connect . length == 8 ) { adjacentInner8 ( pixelToRegion ) ; } adjacentBorder ( pixelToRegion ) ; } | Go through each pixel in the image and examine its neighbors according to a 4 - connect rule . If one of the pixels is in a region that is to be pruned mark them as neighbors . The image is traversed such that the number of comparisons is minimized . | 72 | 53 |
27,426 | protected void selectMerge ( int pruneId , FastQueue < float [ ] > regionColor ) { // Grab information on the region which is being pruned Node n = pruneGraph . get ( pruneId ) ; float [ ] targetColor = regionColor . get ( n . segment ) ; // segment ID and distance away from the most similar neighbor int bestId = - 1 ; float bestDistance = Float . MAX_VALUE ; // Examine all the segments it is connected to to see which one it is most similar too for ( int i = 0 ; i < n . edges . size ; i ++ ) { int segment = n . edges . get ( i ) ; float [ ] neighborColor = regionColor . get ( segment ) ; float d = SegmentMeanShiftSearch . distanceSq ( targetColor , neighborColor ) ; if ( d < bestDistance ) { bestDistance = d ; bestId = segment ; } } if ( bestId == - 1 ) throw new RuntimeException ( "No neighbors? Something went really wrong." ) ; markMerge ( n . segment , bestId ) ; } | Examine edges for the specified node and select node which it is the best match for it to merge with | 233 | 21 |
27,427 | private void declareDerivativeImages ( ImageGradient < T , D > gradient , ImageHessian < D > hessian , Class < D > derivType ) { if ( gradient != null || hessian != null ) { derivX = GeneralizedImageOps . createSingleBand ( derivType , 1 , 1 ) ; derivY = GeneralizedImageOps . createSingleBand ( derivType , 1 , 1 ) ; } if ( hessian != null ) { derivXX = GeneralizedImageOps . createSingleBand ( derivType , 1 , 1 ) ; derivYY = GeneralizedImageOps . createSingleBand ( derivType , 1 , 1 ) ; derivXY = GeneralizedImageOps . createSingleBand ( derivType , 1 , 1 ) ; } } | Declare storage for image derivatives as needed | 162 | 8 |
27,428 | public void detect ( T input , QueueCorner exclude ) { initializeDerivatives ( input ) ; if ( detector . getRequiresGradient ( ) || detector . getRequiresHessian ( ) ) gradient . process ( input , derivX , derivY ) ; if ( detector . getRequiresHessian ( ) ) hessian . process ( derivX , derivY , derivXX , derivYY , derivXY ) ; detector . setExcludeMaximum ( exclude ) ; detector . process ( input , derivX , derivY , derivXX , derivYY , derivXY ) ; } | Detect features inside the image . Excluding points in the exclude list . | 123 | 14 |
27,429 | private void initializeDerivatives ( T input ) { // reshape derivatives if the input image has changed size if ( detector . getRequiresGradient ( ) || detector . getRequiresHessian ( ) ) { derivX . reshape ( input . width , input . height ) ; derivY . reshape ( input . width , input . height ) ; } if ( detector . getRequiresHessian ( ) ) { derivXX . reshape ( input . width , input . height ) ; derivYY . reshape ( input . width , input . height ) ; derivXY . reshape ( input . width , input . height ) ; } } | Reshape derivative images to match the input image | 135 | 10 |
27,430 | public boolean checkFlip ( SquareGrid grid ) { if ( grid . columns == 1 || grid . rows == 1 ) return false ; Point2D_F64 a = grid . get ( 0 , 0 ) . center ; Point2D_F64 b = grid . get ( 0 , grid . columns - 1 ) . center ; Point2D_F64 c = grid . get ( grid . rows - 1 , 0 ) . center ; double x0 = b . x - a . x ; double y0 = b . y - a . y ; double x1 = c . x - a . x ; double y1 = c . y - a . y ; double z = x0 * y1 - y0 * x1 ; return z < 0 ; } | Checks to see if it needs to be flipped . Flipping is required if X and Y axis in 2D grid are not CCW . | 162 | 29 |
27,431 | protected void orderNodeGrid ( SquareGrid grid , int row , int col ) { SquareNode node = grid . get ( row , col ) ; if ( grid . rows == 1 && grid . columns == 1 ) { for ( int i = 0 ; i < 4 ; i ++ ) { ordered [ i ] = node . square . get ( i ) ; } } else if ( grid . columns == 1 ) { if ( row == grid . rows - 1 ) { orderNode ( node , grid . get ( row - 1 , col ) , false ) ; rotateTwiceOrdered ( ) ; } else { orderNode ( node , grid . get ( row + 1 , col ) , false ) ; } } else { if ( col == grid . columns - 1 ) { orderNode ( node , grid . get ( row , col - 1 ) , true ) ; rotateTwiceOrdered ( ) ; } else { orderNode ( node , grid . get ( row , col + 1 ) , true ) ; } } } | Given the grid coordinate order the corners for the node at that location . Takes in handles situations where there are no neighbors . | 213 | 24 |
27,432 | private void rotateTwiceOrdered ( ) { Point2D_F64 a = ordered [ 0 ] ; Point2D_F64 b = ordered [ 1 ] ; Point2D_F64 c = ordered [ 2 ] ; Point2D_F64 d = ordered [ 3 ] ; ordered [ 0 ] = c ; ordered [ 1 ] = d ; ordered [ 2 ] = a ; ordered [ 3 ] = b ; } | Reorders the list by the equivalent of two rotations | 91 | 11 |
27,433 | protected void orderNode ( SquareNode target , SquareNode node , boolean pointingX ) { int index0 = findIntersection ( target , node ) ; int index1 = ( index0 + 1 ) % 4 ; int index2 = ( index0 + 2 ) % 4 ; int index3 = ( index0 + 3 ) % 4 ; if ( index0 < 0 ) throw new RuntimeException ( "Couldn't find intersection. Probable bug" ) ; lineCenters . a = target . center ; lineCenters . b = node . center ; UtilLine2D_F64 . convert ( lineCenters , general ) ; Polygon2D_F64 poly = target . square ; if ( pointingX ) { if ( sign ( general , poly . get ( index0 ) ) > 0 ) { ordered [ 1 ] = poly . get ( index1 ) ; ordered [ 2 ] = poly . get ( index0 ) ; } else { ordered [ 1 ] = poly . get ( index0 ) ; ordered [ 2 ] = poly . get ( index1 ) ; } if ( sign ( general , poly . get ( index2 ) ) > 0 ) { ordered [ 3 ] = poly . get ( index2 ) ; ordered [ 0 ] = poly . get ( index3 ) ; } else { ordered [ 3 ] = poly . get ( index3 ) ; ordered [ 0 ] = poly . get ( index2 ) ; } } else { if ( sign ( general , poly . get ( index0 ) ) > 0 ) { ordered [ 2 ] = poly . get ( index1 ) ; ordered [ 3 ] = poly . get ( index0 ) ; } else { ordered [ 2 ] = poly . get ( index0 ) ; ordered [ 3 ] = poly . get ( index1 ) ; } if ( sign ( general , poly . get ( index2 ) ) > 0 ) { ordered [ 0 ] = poly . get ( index2 ) ; ordered [ 1 ] = poly . get ( index3 ) ; } else { ordered [ 0 ] = poly . get ( index3 ) ; ordered [ 1 ] = poly . get ( index2 ) ; } } } | Fills the ordered list with the corners in target node in canonical order . | 453 | 15 |
27,434 | protected int findIntersection ( SquareNode target , SquareNode node ) { lineCenters . a = target . center ; lineCenters . b = node . center ; for ( int i = 0 ; i < 4 ; i ++ ) { int j = ( i + 1 ) % 4 ; lineSide . a = target . square . get ( i ) ; lineSide . b = target . square . get ( j ) ; if ( Intersection2D_F64 . intersection ( lineCenters , lineSide , dummy ) != null ) { return i ; } } return - 1 ; } | Finds the side which intersects the line segment from the center of target to center of node | 124 | 19 |
27,435 | public boolean orderSquareCorners ( SquareGrid grid ) { // the first pass interleaves every other row for ( int row = 0 ; row < grid . rows ; row ++ ) { for ( int col = 0 ; col < grid . columns ; col ++ ) { orderNodeGrid ( grid , row , col ) ; Polygon2D_F64 square = grid . get ( row , col ) . square ; for ( int i = 0 ; i < 4 ; i ++ ) { square . vertexes . data [ i ] = ordered [ i ] ; } } } return true ; } | Adjust the corners in the square s polygon so that they are aligned along the grids overall length | 124 | 19 |
27,436 | private static List < Match > findMatches ( GrayF32 image , GrayF32 template , GrayF32 mask , int expectedMatches ) { // create template matcher. TemplateMatching < GrayF32 > matcher = FactoryTemplateMatching . createMatcher ( TemplateScoreType . SUM_DIFF_SQ , GrayF32 . class ) ; // Find the points which match the template the best matcher . setImage ( image ) ; matcher . setTemplate ( template , mask , expectedMatches ) ; matcher . process ( ) ; return matcher . getResults ( ) . toList ( ) ; } | Demonstrates how to search for matches of a template inside an image | 132 | 14 |
27,437 | public static void showMatchIntensity ( GrayF32 image , GrayF32 template , GrayF32 mask ) { // create algorithm for computing intensity image TemplateMatchingIntensity < GrayF32 > matchIntensity = FactoryTemplateMatching . createIntensity ( TemplateScoreType . SUM_DIFF_SQ , GrayF32 . class ) ; // apply the template to the image matchIntensity . setInputImage ( image ) ; matchIntensity . process ( template , mask ) ; // get the results GrayF32 intensity = matchIntensity . getIntensity ( ) ; // adjust the intensity image so that white indicates a good match and black a poor match // the scale is kept linear to highlight how ambiguous the solution is float min = ImageStatistics . min ( intensity ) ; float max = ImageStatistics . max ( intensity ) ; float range = max - min ; PixelMath . plus ( intensity , - min , intensity ) ; PixelMath . divide ( intensity , range , intensity ) ; PixelMath . multiply ( intensity , 255.0f , intensity ) ; BufferedImage output = new BufferedImage ( image . width , image . height , BufferedImage . TYPE_INT_BGR ) ; VisualizeImageData . grayMagnitude ( intensity , output , - 1 ) ; ShowImages . showWindow ( output , "Match Intensity" , true ) ; } | Computes the template match intensity image and displays the results . Brighter intensity indicates a better match to the template . | 285 | 23 |
27,438 | private static void drawRectangles ( Graphics2D g2 , GrayF32 image , GrayF32 template , GrayF32 mask , int expectedMatches ) { List < Match > found = findMatches ( image , template , mask , expectedMatches ) ; int r = 2 ; int w = template . width + 2 * r ; int h = template . height + 2 * r ; for ( Match m : found ) { System . out . println ( "Match " + m . x + " " + m . y + " score " + m . score ) ; // this demonstrates how to filter out false positives // the meaning of score will depend on the template technique // if( m.score < -1000 ) // This line is commented out for demonstration purposes // continue; // the return point is the template's top left corner int x0 = m . x - r ; int y0 = m . y - r ; int x1 = x0 + w ; int y1 = y0 + h ; g2 . drawLine ( x0 , y0 , x1 , y0 ) ; g2 . drawLine ( x1 , y0 , x1 , y1 ) ; g2 . drawLine ( x1 , y1 , x0 , y1 ) ; g2 . drawLine ( x0 , y1 , x0 , y0 ) ; } } | Helper function will is finds matches and displays the results as colored rectangles | 289 | 14 |
27,439 | @ Override public void getCenter ( int which , Point2D_F64 location ) { Quadrilateral_F64 q = alg . getFound ( ) . get ( which ) . distortedPixels ; // compute intersection in undistorted pixels so that the intersection is the true // geometric center of the square. Since distorted pixels are being used this will only be approximate UtilLine2D_F64 . convert ( q . a , q . c , line02 ) ; UtilLine2D_F64 . convert ( q . b , q . d , line13 ) ; Intersection2D_F64 . intersection ( line02 , line13 , location ) ; } | Return the intersection of two lines defined by opposing corners . This should also be the geometric center | 144 | 18 |
27,440 | public < T extends SquareNode > T destination ( SquareNode src ) { if ( a == src ) return ( T ) b ; else if ( b == src ) return ( T ) a ; else throw new IllegalArgumentException ( "BUG! src is not a or b" ) ; } | Returns the destination node . | 61 | 5 |
27,441 | public static String inlierPercent ( VisualOdometry alg ) { if ( ! ( alg instanceof AccessPointTracks3D ) ) return "" ; AccessPointTracks3D access = ( AccessPointTracks3D ) alg ; int count = 0 ; int N = access . getAllTracks ( ) . size ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( access . isInlier ( i ) ) count ++ ; } return String . format ( "%%%5.3f" , 100.0 * count / N ) ; } | If the algorithm implements AccessPointTracks3D then count the number of inlier features and return a string . | 128 | 23 |
27,442 | public static void fitBinaryImage ( GrayF32 input ) { GrayU8 binary = new GrayU8 ( input . width , input . height ) ; BufferedImage polygon = new BufferedImage ( input . width , input . height , BufferedImage . TYPE_INT_RGB ) ; // the mean pixel value is often a reasonable threshold when creating a binary image double mean = ImageStatistics . mean ( input ) ; // create a binary image by thresholding ThresholdImageOps . threshold ( input , binary , ( float ) mean , true ) ; // reduce noise with some filtering GrayU8 filtered = BinaryImageOps . erode8 ( binary , 1 , null ) ; filtered = BinaryImageOps . dilate8 ( filtered , 1 , null ) ; // Find internal and external contour around each shape List < Contour > contours = BinaryImageOps . contour ( filtered , ConnectRule . EIGHT , null ) ; // Fit a polygon to each shape and draw the results Graphics2D g2 = polygon . createGraphics ( ) ; g2 . setStroke ( new BasicStroke ( 2 ) ) ; for ( Contour c : contours ) { // Fit the polygon to the found external contour. Note loop = true List < PointIndex_I32 > vertexes = ShapeFittingOps . fitPolygon ( c . external , true , minSide , cornerPenalty ) ; g2 . setColor ( Color . RED ) ; VisualizeShapes . drawPolygon ( vertexes , true , g2 ) ; // handle internal contours now g2 . setColor ( Color . BLUE ) ; for ( List < Point2D_I32 > internal : c . internal ) { vertexes = ShapeFittingOps . fitPolygon ( internal , true , minSide , cornerPenalty ) ; VisualizeShapes . drawPolygon ( vertexes , true , g2 ) ; } } gui . addImage ( polygon , "Binary Blob Contours" ) ; } | Fits polygons to found contours around binary blobs . | 427 | 13 |
27,443 | public static void fitCannyEdges ( GrayF32 input ) { BufferedImage displayImage = new BufferedImage ( input . width , input . height , BufferedImage . TYPE_INT_RGB ) ; // Finds edges inside the image CannyEdge < GrayF32 , GrayF32 > canny = FactoryEdgeDetectors . canny ( 2 , true , true , GrayF32 . class , GrayF32 . class ) ; canny . process ( input , 0.1f , 0.3f , null ) ; List < EdgeContour > contours = canny . getContours ( ) ; Graphics2D g2 = displayImage . createGraphics ( ) ; g2 . setStroke ( new BasicStroke ( 2 ) ) ; // used to select colors for each line Random rand = new Random ( 234 ) ; for ( EdgeContour e : contours ) { g2 . setColor ( new Color ( rand . nextInt ( ) ) ) ; for ( EdgeSegment s : e . segments ) { // fit line segments to the point sequence. Note that loop is false List < PointIndex_I32 > vertexes = ShapeFittingOps . fitPolygon ( s . points , false , minSide , cornerPenalty ) ; VisualizeShapes . drawPolygon ( vertexes , false , g2 ) ; } } gui . addImage ( displayImage , "Canny Trace" ) ; } | Fits a sequence of line - segments into a sequence of points found using the Canny edge detector . In this case the points are not connected in a loop . The canny detector produces a more complex tree and the fitted points can be a bit noisy compared to the others . | 306 | 56 |
27,444 | public static void fitCannyBinary ( GrayF32 input ) { BufferedImage displayImage = new BufferedImage ( input . width , input . height , BufferedImage . TYPE_INT_RGB ) ; GrayU8 binary = new GrayU8 ( input . width , input . height ) ; // Finds edges inside the image CannyEdge < GrayF32 , GrayF32 > canny = FactoryEdgeDetectors . canny ( 2 , false , true , GrayF32 . class , GrayF32 . class ) ; canny . process ( input , 0.1f , 0.3f , binary ) ; // Only external contours are relevant List < Contour > contours = BinaryImageOps . contourExternal ( binary , ConnectRule . EIGHT ) ; Graphics2D g2 = displayImage . createGraphics ( ) ; g2 . setStroke ( new BasicStroke ( 2 ) ) ; // used to select colors for each line Random rand = new Random ( 234 ) ; for ( Contour c : contours ) { List < PointIndex_I32 > vertexes = ShapeFittingOps . fitPolygon ( c . external , true , minSide , cornerPenalty ) ; g2 . setColor ( new Color ( rand . nextInt ( ) ) ) ; VisualizeShapes . drawPolygon ( vertexes , true , g2 ) ; } gui . addImage ( displayImage , "Canny Contour" ) ; } | Detects contours inside the binary image generated by canny . Only the external contour is relevant . Often easier to deal with than working with Canny edges directly . | 312 | 34 |
27,445 | protected Confusion evaluate ( Map < String , List < String > > set ) { ClassificationHistogram histogram = new ClassificationHistogram ( scenes . size ( ) ) ; int total = 0 ; for ( int i = 0 ; i < scenes . size ( ) ; i ++ ) { total += set . get ( scenes . get ( i ) ) . size ( ) ; } System . out . println ( "total images " + total ) ; for ( int i = 0 ; i < scenes . size ( ) ; i ++ ) { String scene = scenes . get ( i ) ; List < String > images = set . get ( scene ) ; System . out . println ( " " + scene + " " + images . size ( ) ) ; for ( String image : images ) { int predicted = classify ( image ) ; histogram . increment ( i , predicted ) ; } } return histogram . createConfusion ( ) ; } | Given a set of images with known classification predict which scene each one belongs in and compute a confusion matrix for the results . | 194 | 24 |
27,446 | public static Map < String , List < String > > findImages ( File rootDir ) { File files [ ] = rootDir . listFiles ( ) ; if ( files == null ) return null ; List < File > imageDirectories = new ArrayList <> ( ) ; for ( File f : files ) { if ( f . isDirectory ( ) ) { imageDirectories . add ( f ) ; } } Map < String , List < String > > out = new HashMap <> ( ) ; for ( File d : imageDirectories ) { List < String > images = new ArrayList <> ( ) ; files = d . listFiles ( ) ; if ( files == null ) throw new RuntimeException ( "Should be a directory!" ) ; for ( File f : files ) { if ( f . isHidden ( ) || f . isDirectory ( ) || f . getName ( ) . endsWith ( ".txt" ) ) { continue ; } images . add ( f . getPath ( ) ) ; } String key = d . getName ( ) . toLowerCase ( ) ; out . put ( key , images ) ; } return out ; } | Loads the paths to image files contained in subdirectories of the root directory . Each sub directory is assumed to be a different category of images . | 243 | 30 |
27,447 | public synchronized void setImages ( BufferedImage leftImage , BufferedImage rightImage ) { this . leftImage = leftImage ; this . rightImage = rightImage ; setPreferredSize ( leftImage . getWidth ( ) , leftImage . getHeight ( ) , rightImage . getWidth ( ) , rightImage . getHeight ( ) ) ; } | Sets the internal images . Not thread safe . | 74 | 10 |
27,448 | private void computeScales ( ) { int width = getWidth ( ) ; int height = getHeight ( ) ; width = ( width - borderSize ) / 2 ; // compute the scale factor for each image scaleLeft = scaleRight = 1 ; if ( leftImage . getWidth ( ) > width || leftImage . getHeight ( ) > height ) { double scaleX = ( double ) width / ( double ) leftImage . getWidth ( ) ; double scaleY = ( double ) height / ( double ) leftImage . getHeight ( ) ; scaleLeft = Math . min ( scaleX , scaleY ) ; } if ( rightImage . getWidth ( ) > width || rightImage . getHeight ( ) > height ) { double scaleX = ( double ) width / ( double ) rightImage . getWidth ( ) ; double scaleY = ( double ) height / ( double ) rightImage . getHeight ( ) ; scaleRight = Math . min ( scaleX , scaleY ) ; } } | Compute individually how each image will be scaled | 208 | 9 |
27,449 | public static void normalize ( GrayF32 image , float mean , float stdev ) { for ( int y = 0 ; y < image . height ; y ++ ) { int index = image . startIndex + y * image . stride ; int end = index + image . width ; while ( index < end ) { image . data [ index ] = ( image . data [ index ] - mean ) / stdev ; index ++ ; } } } | Normalizes a gray scale image by first subtracting the mean then dividing by stdev . | 93 | 18 |
27,450 | public static Kernel1D_F32 create1D_F32 ( double [ ] kernel ) { Kernel1D_F32 k = new Kernel1D_F32 ( kernel . length , kernel . length / 2 ) ; for ( int i = 0 ; i < kernel . length ; i ++ ) { k . data [ i ] = ( float ) kernel [ i ] ; } return k ; } | Converts the double array into a 1D float kernel | 85 | 11 |
27,451 | public static void imageToTensor ( Planar < GrayF32 > input , Tensor_F32 output , int miniBatch ) { if ( input . isSubimage ( ) ) throw new RuntimeException ( "Subimages not accepted" ) ; if ( output . getDimension ( ) != 4 ) throw new IllegalArgumentException ( "Output should be 4-DOF. batch + spatial (channel,height,width)" ) ; if ( output . length ( 1 ) != input . getNumBands ( ) ) throw new IllegalArgumentException ( "Number of bands don't match" ) ; if ( output . length ( 2 ) != input . getHeight ( ) ) throw new IllegalArgumentException ( "Spatial height doesn't match" ) ; if ( output . length ( 3 ) != input . getWidth ( ) ) throw new IllegalArgumentException ( "Spatial width doesn't match" ) ; for ( int i = 0 ; i < input . getNumBands ( ) ; i ++ ) { GrayF32 band = input . getBand ( i ) ; int indexOut = output . idx ( miniBatch , i , 0 , 0 ) ; int length = input . width * input . height ; System . arraycopy ( band . data , 0 , output . d , indexOut , length ) ; } } | Converts an image into a spatial tensor | 283 | 9 |
27,452 | public void process ( GrayU8 binary , int adjustX , int adjustY ) { // Initialize data structures this . adjustX = adjustX ; this . adjustY = adjustY ; storagePoints . reset ( ) ; ImageMiscOps . fillBorder ( binary , 0 , 1 ) ; tracer . setInputs ( binary ) ; final byte binaryData [ ] = binary . data ; // Scan through the image one row at a time looking for pixels with 1 for ( int y = 1 ; y < binary . height - 1 ; y ++ ) { int x = 1 ; int indexBinary = binary . startIndex + y * binary . stride + 1 ; int end = indexBinary + binary . width - 2 ; while ( true ) { int delta = findNotZero ( binaryData , indexBinary , end ) - indexBinary ; indexBinary += delta ; if ( indexBinary == end ) break ; x += delta ; // If this pixel has NOT already been labeled then trace until it runs into a labeled pixel or it // completes the trace. If a labeled pixel is not encountered then it must be an external contour if ( binaryData [ indexBinary ] == 1 ) { if ( tracer . trace ( x , y , true ) ) { int N = storagePoints . sizeOfTail ( ) ; if ( N < minContourLength || N >= maxContourLength ) storagePoints . removeTail ( ) ; } else { // it was really an internal contour storagePoints . removeTail ( ) ; } } // It's now inside a ones blob. Move forward until it hits a 0 pixel delta = findZero ( binaryData , indexBinary , end ) - indexBinary ; indexBinary += delta ; if ( indexBinary == end ) break ; x += delta ; // If this pixel has NOT already been labeled trace until it completes a loop or it encounters a // labeled pixel. This is always an internal contour if ( binaryData [ indexBinary - 1 ] == 1 ) { tracer . trace ( x - 1 , y , false ) ; storagePoints . removeTail ( ) ; } else { // Can't be sure if it's entering a hole or leaving the blob. This marker will let the // tracer know it just traced an internal contour and not an external contour binaryData [ indexBinary - 1 ] = - 2 ; } } } } | Detects contours inside the binary image . | 508 | 9 |
27,453 | static int findNotZero ( byte [ ] data , int index , int end ) { while ( index < end && data [ index ] == 0 ) { index ++ ; } return index ; } | Searches for a value in the array which is not zero . | 40 | 14 |
27,454 | static int findZero ( byte [ ] data , int index , int end ) { while ( index < end && data [ index ] != 0 ) { index ++ ; } return index ; } | Searches for a value in the array which is zero . | 39 | 13 |
27,455 | public void addPatternImage ( T pattern , double threshold , double lengthSide ) { GrayU8 binary = new GrayU8 ( pattern . width , pattern . height ) ; GThresholdImageOps . threshold ( pattern , binary , threshold , false ) ; alg . addPattern ( binary , lengthSide ) ; } | Add a new pattern to be detected . This function takes in a raw gray scale image and thresholds it . | 66 | 21 |
27,456 | private void requestCameraPermission ( ) { int permissionCheck = ContextCompat . checkSelfPermission ( this , Manifest . permission . CAMERA ) ; if ( permissionCheck != android . content . pm . PackageManager . PERMISSION_GRANTED ) { ActivityCompat . requestPermissions ( this , new String [ ] { Manifest . permission . CAMERA } , 0 ) ; // a dialog should open and this dialog will resume when a decision has been made } } | Newer versions of Android require explicit permission from the user | 97 | 11 |
27,457 | public static < T extends ImageGray < T > > T bitmapToGray ( Bitmap input , T output , Class < T > imageType , byte [ ] storage ) { if ( imageType == GrayF32 . class ) return ( T ) bitmapToGray ( input , ( GrayF32 ) output , storage ) ; else if ( imageType == GrayU8 . class ) return ( T ) bitmapToGray ( input , ( GrayU8 ) output , storage ) ; else throw new IllegalArgumentException ( "Unsupported BoofCV Image Type" ) ; } | Converts Bitmap image into a single band image of arbitrary type . | 122 | 14 |
27,458 | public static GrayU8 bitmapToGray ( Bitmap input , GrayU8 output , byte [ ] storage ) { if ( output == null ) { output = new GrayU8 ( input . getWidth ( ) , input . getHeight ( ) ) ; } else { output . reshape ( input . getWidth ( ) , input . getHeight ( ) ) ; } if ( storage == null ) storage = declareStorage ( input , null ) ; input . copyPixelsToBuffer ( ByteBuffer . wrap ( storage ) ) ; ImplConvertBitmap . arrayToGray ( storage , input . getConfig ( ) , output ) ; return output ; } | Converts Bitmap image into GrayU8 . | 137 | 10 |
27,459 | public static < T extends ImageGray < T > > Planar < T > bitmapToPlanar ( Bitmap input , Planar < T > output , Class < T > type , byte [ ] storage ) { if ( output == null ) { output = new Planar <> ( type , input . getWidth ( ) , input . getHeight ( ) , 3 ) ; } else { int numBands = Math . min ( 4 , Math . max ( 3 , output . getNumBands ( ) ) ) ; output . reshape ( input . getWidth ( ) , input . getHeight ( ) , numBands ) ; } if ( storage == null ) storage = declareStorage ( input , null ) ; input . copyPixelsToBuffer ( ByteBuffer . wrap ( storage ) ) ; if ( type == GrayU8 . class ) ImplConvertBitmap . arrayToPlanar_U8 ( storage , input . getConfig ( ) , ( Planar ) output ) ; else if ( type == GrayF32 . class ) ImplConvertBitmap . arrayToPlanar_F32 ( storage , input . getConfig ( ) , ( Planar ) output ) ; else throw new IllegalArgumentException ( "Unsupported BoofCV Type" ) ; return output ; } | Converts Bitmap image into Planar image of the appropriate type . | 271 | 14 |
27,460 | public static void boofToBitmap ( ImageBase input , Bitmap output , byte [ ] storage ) { if ( BOverrideConvertAndroid . invokeBoofToBitmap ( ColorFormat . RGB , input , output , storage ) ) return ; if ( input instanceof Planar ) { planarToBitmap ( ( Planar ) input , output , storage ) ; } else if ( input instanceof ImageGray ) { grayToBitmap ( ( ImageGray ) input , output , storage ) ; } else if ( input instanceof ImageInterleaved ) { interleavedToBitmap ( ( ImageInterleaved ) input , output , storage ) ; } else { throw new IllegalArgumentException ( "Unsupported input image type" ) ; } } | Converts many BoofCV image types into a Bitmap . | 159 | 13 |
27,461 | public static < T extends ImageGray < T > > void planarToBitmap ( Planar < T > input , Bitmap output , byte [ ] storage ) { if ( output . getWidth ( ) != input . getWidth ( ) || output . getHeight ( ) != input . getHeight ( ) ) { throw new IllegalArgumentException ( "Image shapes are not the same" ) ; } if ( storage == null ) storage = declareStorage ( output , null ) ; if ( input . getBandType ( ) == GrayU8 . class ) ImplConvertBitmap . planarToArray_U8 ( ( Planar ) input , storage , output . getConfig ( ) ) ; else if ( input . getBandType ( ) == GrayF32 . class ) ImplConvertBitmap . planarToArray_F32 ( ( Planar ) input , storage , output . getConfig ( ) ) ; else throw new IllegalArgumentException ( "Unsupported BoofCV Type" ) ; output . copyPixelsFromBuffer ( ByteBuffer . wrap ( storage ) ) ; } | Converts Planar image into Bitmap . | 229 | 9 |
27,462 | public static Bitmap grayToBitmap ( GrayU8 input , Bitmap . Config config ) { Bitmap output = Bitmap . createBitmap ( input . width , input . height , config ) ; grayToBitmap ( input , output , null ) ; return output ; } | Converts GrayU8 into a new Bitmap . | 59 | 11 |
27,463 | public void process ( FastQueue < AssociatedIndex > matches , int numSource , int numDestination ) { if ( checkSource ) { if ( checkDestination ) { processSource ( matches , numSource , firstPass ) ; processDestination ( firstPass , numDestination , pruned ) ; } else { processSource ( matches , numSource , pruned ) ; } } else if ( checkDestination ) { processDestination ( matches , numDestination , pruned ) ; } else { // well this was pointless, just return the input set pruned = matches ; } } | Given a set of matches enforce the uniqueness rules it was configured to . | 122 | 14 |
27,464 | private void processSource ( FastQueue < AssociatedIndex > matches , int numSource , FastQueue < AssociatedIndex > output ) { //set up data structures scores . resize ( numSource ) ; solutions . resize ( numSource ) ; for ( int i = 0 ; i < numSource ; i ++ ) { solutions . data [ i ] = - 1 ; } // select best matches for ( int i = 0 ; i < matches . size ( ) ; i ++ ) { AssociatedIndex a = matches . get ( i ) ; int found = solutions . data [ a . src ] ; if ( found != - 1 ) { if ( found == - 2 ) { // the best solution is invalid because two or more had the same score, see if this is better double bestScore = scores . data [ a . src ] ; int result = type . compareTo ( bestScore , a . fitScore ) ; if ( result < 0 ) { // found a better one, use this now solutions . data [ a . src ] = i ; scores . data [ a . src ] = a . fitScore ; } } else { // see if this new score is better than the current best AssociatedIndex currentBest = matches . get ( found ) ; int result = type . compareTo ( currentBest . fitScore , a . fitScore ) ; if ( result < 0 ) { // found a better one, use this now solutions . data [ a . src ] = i ; scores . data [ a . src ] = a . fitScore ; } else if ( result == 0 ) { // two solutions have the same score solutions . data [ a . src ] = - 2 ; } } } else { // no previous match found solutions . data [ a . src ] = i ; scores . data [ a . src ] = a . fitScore ; } } output . reset ( ) ; for ( int i = 0 ; i < numSource ; i ++ ) { int index = solutions . data [ i ] ; if ( index >= 0 ) { output . add ( matches . get ( index ) ) ; } } } | Selects a subset of matches that have at most one association for each source feature . | 435 | 17 |
27,465 | private void processDestination ( FastQueue < AssociatedIndex > matches , int numDestination , FastQueue < AssociatedIndex > output ) { //set up data structures scores . resize ( numDestination ) ; solutions . resize ( numDestination ) ; for ( int i = 0 ; i < numDestination ; i ++ ) { solutions . data [ i ] = - 1 ; } // select best matches for ( int i = 0 ; i < matches . size ( ) ; i ++ ) { AssociatedIndex a = matches . get ( i ) ; int found = solutions . data [ a . dst ] ; if ( found != - 1 ) { if ( found == - 2 ) { // the best solution is invalid because two or more had the same score, see if this is better double bestScore = scores . data [ a . dst ] ; int result = type . compareTo ( bestScore , a . fitScore ) ; if ( result < 0 ) { // found a better one, use this now solutions . data [ a . dst ] = i ; scores . data [ a . dst ] = a . fitScore ; } } else { // see if this new score is better than the current best AssociatedIndex currentBest = matches . get ( found ) ; int result = type . compareTo ( currentBest . fitScore , a . fitScore ) ; if ( result < 0 ) { // found a better one, use this now solutions . data [ a . dst ] = i ; scores . data [ a . dst ] = a . fitScore ; } else if ( result == 0 ) { // two solutions have the same score solutions . data [ a . dst ] = - 2 ; } } } else { // no previous match found solutions . data [ a . dst ] = i ; scores . data [ a . dst ] = i ; } } output . reset ( ) ; for ( int i = 0 ; i < numDestination ; i ++ ) { int index = solutions . data [ i ] ; if ( index >= 0 ) { output . add ( matches . get ( index ) ) ; } } } | Selects a subset of matches that have at most one association for each destination feature . | 438 | 17 |
27,466 | private int applyFog ( int rgb , float fraction ) { // avoid floating point math int adjustment = ( int ) ( 1000 * fraction ) ; int r = ( rgb >> 16 ) & 0xFF ; int g = ( rgb >> 8 ) & 0xFF ; int b = rgb & 0xFF ; r = ( r * adjustment + ( ( backgroundColor >> 16 ) & 0xFF ) * ( 1000 - adjustment ) ) / 1000 ; g = ( g * adjustment + ( ( backgroundColor >> 8 ) & 0xFF ) * ( 1000 - adjustment ) ) / 1000 ; b = ( b * adjustment + ( backgroundColor & 0xFF ) * ( 1000 - adjustment ) ) / 1000 ; return ( r << 16 ) | ( g << 8 ) | b ; } | Fades color into background as a function of distance | 164 | 10 |
27,467 | private void renderDot ( int cx , int cy , float Z , int rgb ) { for ( int i = - dotRadius ; i <= dotRadius ; i ++ ) { int y = cy + i ; if ( y < 0 || y >= imageRgb . height ) continue ; for ( int j = - dotRadius ; j <= dotRadius ; j ++ ) { int x = cx + j ; if ( x < 0 || x >= imageRgb . width ) continue ; int pixelIndex = imageDepth . getIndex ( x , y ) ; float depth = imageDepth . data [ pixelIndex ] ; if ( depth > Z ) { imageDepth . data [ pixelIndex ] = Z ; imageRgb . data [ pixelIndex ] = rgb ; } } } } | Renders a dot as a square sprite with the specified color | 166 | 12 |
27,468 | protected void imageToOutput ( double x , double y , Point2D_F64 pt ) { pt . x = x / scale - tranX / scale ; pt . y = y / scale - tranY / scale ; } | Converts a coordinate from pixel to the output image coordinates | 50 | 11 |
27,469 | protected void outputToImage ( double x , double y , Point2D_F64 pt ) { pt . x = x * scale + tranX ; pt . y = y * scale + tranY ; } | Converts a coordinate from output image coordinates to input image | 46 | 11 |
27,470 | public static void RGB_to_PLU8 ( Picture input , Planar < GrayU8 > output ) { if ( input . getColor ( ) != ColorSpace . RGB ) throw new RuntimeException ( "Unexpected input color space!" ) ; if ( output . getNumBands ( ) != 3 ) throw new RuntimeException ( "Unexpected number of bands in output image!" ) ; output . reshape ( input . getWidth ( ) , input . getHeight ( ) ) ; int dataIn [ ] = input . getData ( ) [ 0 ] ; GrayU8 out0 = output . getBand ( 0 ) ; GrayU8 out1 = output . getBand ( 1 ) ; GrayU8 out2 = output . getBand ( 2 ) ; int indexIn = 0 ; int indexOut = 0 ; for ( int i = 0 ; i < output . height ; i ++ ) { for ( int j = 0 ; j < output . width ; j ++ , indexOut ++ ) { int r = dataIn [ indexIn ++ ] ; int g = dataIn [ indexIn ++ ] ; int b = dataIn [ indexIn ++ ] ; out2 . data [ indexOut ] = ( byte ) r ; out1 . data [ indexOut ] = ( byte ) g ; out0 . data [ indexOut ] = ( byte ) b ; } } } | Converts a picture in JCodec RGB into RGB BoofCV | 288 | 14 |
27,471 | static void backsubstitution0134 ( DMatrixRMaj P_plus , DMatrixRMaj P , DMatrixRMaj X , double H [ ] ) { final int N = P . numRows ; DMatrixRMaj tmp = new DMatrixRMaj ( N * 2 , 1 ) ; double H6 = H [ 6 ] ; double H7 = H [ 7 ] ; double H8 = H [ 8 ] ; for ( int i = 0 , index = 0 ; i < N ; i ++ ) { double x = - X . data [ index ] , y = - X . data [ index + 1 ] ; double sum = P . data [ index ++ ] * H6 + P . data [ index ++ ] * H7 + H8 ; tmp . data [ i ] = x * sum ; tmp . data [ i + N ] = y * sum ; } double h0 = 0 , h1 = 0 , h3 = 0 , h4 = 0 ; for ( int i = 0 ; i < N ; i ++ ) { double P_pls_0 = P_plus . data [ i ] ; double P_pls_1 = P_plus . data [ i + N ] ; double tmp_i = tmp . data [ i ] ; double tmp_j = tmp . data [ i + N ] ; h0 += P_pls_0 * tmp_i ; h1 += P_pls_1 * tmp_i ; h3 += P_pls_0 * tmp_j ; h4 += P_pls_1 * tmp_j ; } H [ 0 ] = - h0 ; H [ 1 ] = - h1 ; H [ 3 ] = - h3 ; H [ 4 ] = - h4 ; } | Backsubstitution for solving for 0 1 and 3 4 using solution for 6 7 8 | 383 | 19 |
27,472 | void constructA678 ( ) { final int N = X1 . numRows ; // Pseudo-inverse of hat(p) computePseudo ( X1 , P_plus ) ; DMatrixRMaj PPpXP = new DMatrixRMaj ( 1 , 1 ) ; DMatrixRMaj PPpYP = new DMatrixRMaj ( 1 , 1 ) ; computePPXP ( X1 , P_plus , X2 , 0 , PPpXP ) ; computePPXP ( X1 , P_plus , X2 , 1 , PPpYP ) ; DMatrixRMaj PPpX = new DMatrixRMaj ( 1 , 1 ) ; DMatrixRMaj PPpY = new DMatrixRMaj ( 1 , 1 ) ; computePPpX ( X1 , P_plus , X2 , 0 , PPpX ) ; computePPpX ( X1 , P_plus , X2 , 1 , PPpY ) ; //============ Equations 20 computeEq20 ( X2 , X1 , XP_bar ) ; //============ Equation 21 A . reshape ( N * 2 , 3 ) ; double XP_bar_x = XP_bar [ 0 ] ; double XP_bar_y = XP_bar [ 1 ] ; double YP_bar_x = XP_bar [ 2 ] ; double YP_bar_y = XP_bar [ 3 ] ; // Compute the top half of A for ( int i = 0 , index = 0 , indexA = 0 ; i < N ; i ++ , index += 2 ) { double x = - X2 . data [ i * 2 ] ; // X' double P_hat_x = X1 . data [ index ] ; // hat{P}[0] double P_hat_y = X1 . data [ index + 1 ] ; // hat{P}[1] // x'*hat{p} - bar{X*P} - PPpXP A . data [ indexA ++ ] = x * P_hat_x - XP_bar_x - PPpXP . data [ index ] ; A . data [ indexA ++ ] = x * P_hat_y - XP_bar_y - PPpXP . data [ index + 1 ] ; // X'*1 - PPx1 A . data [ indexA ++ ] = x - PPpX . data [ i ] ; } // Compute the bottom half of A for ( int i = 0 , index = 0 , indexA = N * 3 ; i < N ; i ++ , index += 2 ) { double x = - X2 . data [ i * 2 + 1 ] ; double P_hat_x = X1 . data [ index ] ; double P_hat_y = X1 . data [ index + 1 ] ; // x'*hat{p} - bar{X*P} - PPpXP A . data [ indexA ++ ] = x * P_hat_x - YP_bar_x - PPpYP . data [ index ] ; A . data [ indexA ++ ] = x * P_hat_y - YP_bar_y - PPpYP . data [ index + 1 ] ; // X'*1 - PPx1 A . data [ indexA ++ ] = x - PPpY . data [ i ] ; } } | Constructs equation for elements 6 to 8 in H | 728 | 10 |
27,473 | public void sanityCheck ( ) { for ( View v : nodes ) { for ( Motion m : v . connections ) { if ( m . viewDst != v && m . viewSrc != v ) throw new RuntimeException ( "Not member of connection" ) ; } } for ( Motion m : edges ) { if ( m . viewDst != m . destination ( m . viewSrc ) ) throw new RuntimeException ( "Unexpected result" ) ; } } | Performs simple checks to see if the data structure is avlid | 99 | 14 |
27,474 | public boolean process ( FastQueue < AssociatedPair > pairs , Rectangle2D_F64 targetRectangle ) { // estimate how the rectangle has changed and update it if ( ! estimateMotion . process ( pairs . toList ( ) ) ) return false ; ScaleTranslate2D motion = estimateMotion . getModelParameters ( ) ; adjustRectangle ( targetRectangle , motion ) ; if ( targetRectangle . p0 . x < 0 || targetRectangle . p0 . y < 0 ) return false ; if ( targetRectangle . p1 . x >= imageWidth || targetRectangle . p1 . y >= imageHeight ) return false ; return true ; } | Adjusts target rectangle using track information | 141 | 7 |
27,475 | protected void adjustRectangle ( Rectangle2D_F64 rect , ScaleTranslate2D motion ) { rect . p0 . x = rect . p0 . x * motion . scale + motion . transX ; rect . p0 . y = rect . p0 . y * motion . scale + motion . transY ; rect . p1 . x = rect . p1 . x * motion . scale + motion . transX ; rect . p1 . y = rect . p1 . y * motion . scale + motion . transY ; } | Estimate motion of points inside the rectangle and updates the rectangle using the found motion . | 116 | 17 |
27,476 | public void associate ( BufferedImage imageA , BufferedImage imageB ) { T inputA = ConvertBufferedImage . convertFromSingle ( imageA , null , imageType ) ; T inputB = ConvertBufferedImage . convertFromSingle ( imageB , null , imageType ) ; // stores the location of detected interest points pointsA = new ArrayList <> ( ) ; pointsB = new ArrayList <> ( ) ; // stores the description of detected interest points FastQueue < TD > descA = UtilFeature . createQueue ( detDesc , 100 ) ; FastQueue < TD > descB = UtilFeature . createQueue ( detDesc , 100 ) ; // describe each image using interest points describeImage ( inputA , pointsA , descA ) ; describeImage ( inputB , pointsB , descB ) ; // Associate features between the two images associate . setSource ( descA ) ; associate . setDestination ( descB ) ; associate . associate ( ) ; // display the results AssociationPanel panel = new AssociationPanel ( 20 ) ; panel . setAssociation ( pointsA , pointsB , associate . getMatches ( ) ) ; panel . setImages ( imageA , imageB ) ; ShowImages . showWindow ( panel , "Associated Features" , true ) ; } | Detect and associate point features in the two images . Display the results . | 271 | 14 |
27,477 | public static < T extends ImageGray < T > > WaveletDenoiseFilter < T > waveletVisu ( Class < T > imageType , int numLevels , double minPixelValue , double maxPixelValue ) { ImageDataType info = ImageDataType . classToType ( imageType ) ; WaveletTransform descTran = createDefaultShrinkTransform ( info , numLevels , minPixelValue , maxPixelValue ) ; DenoiseWavelet denoiser = FactoryDenoiseWaveletAlg . visu ( imageType ) ; return new WaveletDenoiseFilter <> ( descTran , denoiser ) ; } | Denoises an image using VISU Shrink wavelet denoiser . | 136 | 17 |
27,478 | public static < T extends ImageGray < T > > WaveletDenoiseFilter < T > waveletBayes ( Class < T > imageType , int numLevels , double minPixelValue , double maxPixelValue ) { ImageDataType info = ImageDataType . classToType ( imageType ) ; WaveletTransform descTran = createDefaultShrinkTransform ( info , numLevels , minPixelValue , maxPixelValue ) ; DenoiseWavelet denoiser = FactoryDenoiseWaveletAlg . bayes ( null , imageType ) ; return new WaveletDenoiseFilter <> ( descTran , denoiser ) ; } | Denoises an image using BayesShrink wavelet denoiser . | 138 | 17 |
27,479 | private static WaveletTransform createDefaultShrinkTransform ( ImageDataType imageType , int numLevels , double minPixelValue , double maxPixelValue ) { WaveletTransform descTran ; if ( ! imageType . isInteger ( ) ) { WaveletDescription < WlCoef_F32 > waveletDesc_F32 = FactoryWaveletDaub . daubJ_F32 ( 4 ) ; descTran = FactoryWaveletTransform . create_F32 ( waveletDesc_F32 , numLevels , ( float ) minPixelValue , ( float ) maxPixelValue ) ; } else { WaveletDescription < WlCoef_I32 > waveletDesc_I32 = FactoryWaveletDaub . biorthogonal_I32 ( 5 , BorderType . REFLECT ) ; descTran = FactoryWaveletTransform . create_I ( waveletDesc_I32 , numLevels , ( int ) minPixelValue , ( int ) maxPixelValue , ImageType . getImageClass ( ImageType . Family . GRAY , imageType ) ) ; } return descTran ; } | Default wavelet transform used for denoising images . | 240 | 11 |
27,480 | public static int minusPOffset ( int index , int offset , int size ) { index -= offset ; if ( index < 0 ) { return size + index ; } else { return index ; } } | Subtracts a positive offset to index in a circular buffer . | 41 | 14 |
27,481 | public static int distanceP ( int index0 , int index1 , int size ) { int difference = index1 - index0 ; if ( difference < 0 ) { difference = size + difference ; } return difference ; } | Returns how many elements away in the positive direction you need to travel to get from index0 to index1 . | 45 | 22 |
27,482 | public static int subtract ( int index0 , int index1 , int size ) { int distance = distanceP ( index0 , index1 , size ) ; if ( distance >= size / 2 + size % 2 ) { return distance - size ; } else { return distance ; } } | Subtracts index1 from index0 . positive number if its closer in the positive direction or negative if closer in the negative direction . if equal distance then it will return a negative number . | 58 | 39 |
27,483 | protected static void removeChildInsidePanel ( JComponent root , JComponent target ) { int N = root . getComponentCount ( ) ; for ( int i = 0 ; i < N ; i ++ ) { try { JPanel p = ( JPanel ) root . getComponent ( i ) ; Component [ ] children = p . getComponents ( ) ; for ( int j = 0 ; j < children . length ; j ++ ) { if ( children [ j ] == target ) { root . remove ( i ) ; return ; } } } catch ( ClassCastException ignore ) { } } } | Searches inside the children of root for a component that s a JPanel . Then inside the JPanel it looks for the target . If the target is inside the JPanel the JPanel is removed from root . | 124 | 44 |
27,484 | protected static void removeChildAndPrevious ( JComponent root , JComponent target ) { int N = root . getComponentCount ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( root . getComponent ( i ) == target ) { root . remove ( i ) ; root . remove ( i - 1 ) ; return ; } } throw new RuntimeException ( "Can't find component" ) ; } | Searches inside the children of root for target . If found it is removed and the previous component . | 90 | 21 |
27,485 | public static float distanceSq ( float [ ] a , float [ ] b ) { float ret = 0 ; for ( int i = 0 ; i < a . length ; i ++ ) { float d = a [ i ] - b [ i ] ; ret += d * d ; } return ret ; } | Returns the Euclidean distance squared between the two vectors | 64 | 11 |
27,486 | protected float weight ( float distance ) { float findex = distance * 100f ; int index = ( int ) findex ; if ( index >= 99 ) return weightTable [ 99 ] ; float sample0 = weightTable [ index ] ; float sample1 = weightTable [ index + 1 ] ; float w = findex - index ; return sample0 * ( 1f - w ) + sample1 * w ; } | Returns the weight given the normalized distance . Instead of computing the kernel distance every time a lookup table with linear interpolation is used . The distance has a domain from 0 to 1 inclusive | 86 | 36 |
27,487 | @ Override public void process ( ) { processed = true ; for ( int i = 0 ; i < histogram . length ; i ++ ) { histogram [ i ] /= total ; } } | No more features are being added . Normalized the computed histogram . | 42 | 14 |
27,488 | public void transform ( GrayU8 binary ) { ImageMiscOps . fill ( transform , 0 ) ; originX = binary . width / 2 ; originY = binary . height / 2 ; r_max = Math . sqrt ( originX * originX + originY * originY ) ; for ( int y = 0 ; y < binary . height ; y ++ ) { int start = binary . startIndex + y * binary . stride ; int stop = start + binary . width ; for ( int index = start ; index < stop ; index ++ ) { if ( binary . data [ index ] != 0 ) { parameterize ( index - start , y ) ; } } } } | Computes the Hough transform of the image . | 143 | 10 |
27,489 | public void lineToCoordinate ( LineParametric2D_F32 line , Point2D_F64 coordinate ) { line = line . copy ( ) ; line . p . x -= originX ; line . p . y -= originY ; LinePolar2D_F32 polar = new LinePolar2D_F32 ( ) ; UtilLine2D_F32 . convert ( line , polar ) ; if ( polar . angle < 0 ) { polar . distance = - polar . distance ; polar . angle = UtilAngle . toHalfCircle ( polar . angle ) ; } int w2 = transform . width / 2 ; coordinate . x = ( int ) Math . floor ( polar . distance * w2 / r_max ) + w2 ; coordinate . y = polar . angle * transform . height / Math . PI ; } | Compute the parameterized coordinate for the line | 181 | 9 |
27,490 | public void parameterize ( int x , int y ) { // put the point in a new coordinate system centered at the image's origin x -= originX ; y -= originY ; int w2 = transform . width / 2 ; // The line's slope is encoded using the tangent angle. Those bins are along the image's y-axis for ( int i = 0 ; i < transform . height ; i ++ ) { // distance of closest point on line from a line defined by the point (x,y) and // the tangent theta=PI*i/height double p = x * tableTrig . c [ i ] + y * tableTrig . s [ i ] ; int col = ( int ) Math . floor ( p * w2 / r_max ) + w2 ; int index = transform . startIndex + i * transform . stride + col ; transform . data [ index ] ++ ; } } | Converts the pixel coordinate into a line in parameter space | 193 | 11 |
27,491 | public void set ( Vector3D_F64 l1 , Vector3D_F64 l2 ) { this . l1 . set ( l1 ) ; this . l2 . set ( l2 ) ; } | Sets the value of p1 and p2 to be equal to the values of the passed in objects | 46 | 21 |
27,492 | public void setClassificationData ( List < HistogramScene > memory , int numScenes ) { nn . setPoints ( memory , false ) ; scenes = new double [ numScenes ] ; } | Provides a set of labeled word histograms to use to classify a new image | 43 | 16 |
27,493 | public int classify ( T image ) { if ( numNeighbors == 0 ) throw new IllegalArgumentException ( "Must specify number of neighbors!" ) ; // compute all the features inside the image describe . process ( image ) ; // find which word the feature matches and construct a frequency histogram featureToHistogram . reset ( ) ; List < Desc > imageFeatures = describe . getDescriptions ( ) ; for ( int i = 0 ; i < imageFeatures . size ( ) ; i ++ ) { Desc d = imageFeatures . get ( i ) ; featureToHistogram . addFeature ( d ) ; } featureToHistogram . process ( ) ; temp . histogram = featureToHistogram . getHistogram ( ) ; // Find the N most similar image histograms resultsNN . reset ( ) ; search . findNearest ( temp , - 1 , numNeighbors , resultsNN ) ; // Find the most common scene among those neighbors Arrays . fill ( scenes , 0 ) ; for ( int i = 0 ; i < resultsNN . size ; i ++ ) { NnData < HistogramScene > data = resultsNN . get ( i ) ; HistogramScene n = data . point ; // scenes[n.type]++; scenes [ n . type ] += 1.0 / ( data . distance + 0.005 ) ; // todo // scenes[n.type] += 1.0/(Math.sqrt(data.distance)+0.005); // todo } // pick the scene with the highest frequency int bestIndex = 0 ; double bestCount = 0 ; for ( int i = 0 ; i < scenes . length ; i ++ ) { if ( scenes [ i ] > bestCount ) { bestCount = scenes [ i ] ; bestIndex = i ; } } return bestIndex ; } | Finds the scene which most resembles the provided image | 381 | 10 |
27,494 | public void unusual ( ) { // Note that the first level does not have to be one pyramid = FactoryPyramid . discreteGaussian ( new int [ ] { 2 , 6 } , - 1 , 2 , true , ImageType . single ( imageType ) ) ; // Other kernels can also be used besides Gaussian Kernel1D kernel ; if ( GeneralizedImageOps . isFloatingPoint ( imageType ) ) { kernel = FactoryKernel . table1D_F32 ( 2 , true ) ; } else { kernel = FactoryKernel . table1D_I32 ( 2 ) ; } } | Creates a more unusual pyramid and updater . | 126 | 10 |
27,495 | public void process ( BufferedImage image ) { T input = ConvertBufferedImage . convertFromSingle ( image , null , imageType ) ; pyramid . process ( input ) ; DiscretePyramidPanel gui = new DiscretePyramidPanel ( ) ; gui . setPyramid ( pyramid ) ; gui . render ( ) ; ShowImages . showWindow ( gui , "Image Pyramid" ) ; // To get an image at any of the scales simply call this get function T imageAtScale = pyramid . getLayer ( 1 ) ; ShowImages . showWindow ( ConvertBufferedImage . convertTo ( imageAtScale , null , true ) , "Image at layer 1" ) ; } | Updates and displays the pyramid . | 142 | 7 |
27,496 | public static < T extends ImageGray < T > > ImageFunctionSparse < T > createLaplacian ( Class < T > imageType , ImageBorder < T > border ) { if ( border == null ) { border = FactoryImageBorder . single ( imageType , BorderType . EXTENDED ) ; } if ( GeneralizedImageOps . isFloatingPoint ( imageType ) ) { ImageConvolveSparse < GrayF32 , Kernel2D_F32 > r = FactoryConvolveSparse . convolve2D ( GrayF32 . class , DerivativeLaplacian . kernel_F32 ) ; r . setImageBorder ( ( ImageBorder_F32 ) border ) ; return ( ImageFunctionSparse < T > ) r ; } else { ImageConvolveSparse r = FactoryConvolveSparse . convolve2D ( GrayI . class , DerivativeLaplacian . kernel_I32 ) ; r . setImageBorder ( border ) ; return ( ImageFunctionSparse < T > ) r ; } } | Creates a sparse Laplacian filter . | 227 | 10 |
27,497 | public static < T extends ImageGray < T > , G extends GradientValue > SparseImageGradient < T , G > createSobel ( Class < T > imageType , ImageBorder < T > border ) { if ( imageType == GrayF32 . class ) { return ( SparseImageGradient ) new GradientSparseSobel_F32 ( ( ImageBorder_F32 ) border ) ; } else if ( imageType == GrayU8 . class ) { return ( SparseImageGradient ) new GradientSparseSobel_U8 ( ( ImageBorder_S32 ) border ) ; } else { throw new IllegalArgumentException ( "Unsupported image type " + imageType . getSimpleName ( ) ) ; } } | Creates a sparse sobel gradient operator . | 162 | 9 |
27,498 | public static < T extends ImageGray < T > , G extends GradientValue > SparseImageGradient < T , G > createPrewitt ( Class < T > imageType , ImageBorder < T > border ) { if ( imageType == GrayF32 . class ) { return ( SparseImageGradient ) new GradientSparsePrewitt_F32 ( ( ImageBorder_F32 ) border ) ; } else if ( imageType == GrayU8 . class ) { return ( SparseImageGradient ) new GradientSparsePrewitt_U8 ( ( ImageBorder_S32 ) border ) ; } else { throw new IllegalArgumentException ( "Unsupported image type " + imageType . getSimpleName ( ) ) ; } } | Creates a sparse prewitt gradient operator . | 162 | 10 |
27,499 | public static < T extends ImageGray < T > , G extends GradientValue > SparseImageGradient < T , G > createThree ( Class < T > imageType , ImageBorder < T > border ) { if ( imageType == GrayF32 . class ) { return ( SparseImageGradient ) new GradientSparseThree_F32 ( ( ImageBorder_F32 ) border ) ; } else if ( imageType == GrayU8 . class ) { return ( SparseImageGradient ) new GradientSparseThree_U8 ( ( ImageBorder_S32 ) border ) ; } else { throw new IllegalArgumentException ( "Unsupported image type " + imageType . getSimpleName ( ) ) ; } } | Creates a sparse three gradient operator . | 156 | 8 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.