idx int64 0 41.2k | question stringlengths 74 4.04k | target stringlengths 7 750 |
|---|---|---|
27,100 | public static int downSampleSize ( int length , int squareWidth ) { int ret = length / squareWidth ; if ( length % squareWidth != 0 ) ret ++ ; return ret ; } | Computes the length of a down sampled image based on the original length and the square width |
27,101 | public static void reshapeDown ( ImageBase image , int inputWidth , int inputHeight , int squareWidth ) { int w = downSampleSize ( inputWidth , squareWidth ) ; int h = downSampleSize ( inputHeight , squareWidth ) ; image . reshape ( w , h ) ; } | Reshapes an image so that it is the correct size to store the down sampled image |
27,102 | public static < T extends ImageGray < T > > void down ( Planar < T > input , int sampleWidth , Planar < T > output ) { for ( int band = 0 ; band < input . getNumBands ( ) ; band ++ ) { down ( input . getBand ( band ) , sampleWidth , output . getBand ( band ) ) ; } } | Down samples a planar image . Type checking is done at runtime . |
27,103 | public void setCamera1 ( double fx , double fy , double skew , double cx , double cy ) { PerspectiveOps . pinholeToMatrix ( fx , fy , skew , cx , cy , K1 ) ; } | Specifies known intrinsic parameters for view 1 |
27,104 | public void setCamera2 ( double fx , double fy , double skew , double cx , double cy ) { PerspectiveOps . pinholeToMatrix ( fx , fy , skew , cx , cy , K2 ) ; PerspectiveOps . invertPinhole ( K2 , K2_inv ) ; } | Specifies known intrinsic parameters for view 2 |
27,105 | public boolean estimatePlaneAtInfinity ( DMatrixRMaj P2 , Vector3D_F64 v ) { PerspectiveOps . projectionSplit ( P2 , Q2 , q2 ) ; CommonOps_DDF3 . mult ( K2_inv , q2 , t2 ) ; CommonOps_DDF3 . mult ( K2_inv , Q2 , tmpA ) ; CommonOps_DDF3 . mult ( tmpA , K1 , tmpB ) ; computeRotation ( t2 , RR ) ; CommonOps_DDF3 . mult ( RR , tmpB , W ) ; w2 . set ( W . a21 , W . a22 , W . a23 ) ; w3 . set ( W . a31 , W . a32 , W . a33 ) ; double n3 = w3 . norm ( ) ; v . cross ( w2 , w3 ) ; v . divideIP ( n3 ) ; v . x -= W . a11 ; v . y -= W . a12 ; v . z -= W . a13 ; v . divideIP ( t2 . a1 ) ; return ! ( UtilEjml . isUncountable ( v . x ) || UtilEjml . isUncountable ( v . y ) || UtilEjml . isUncountable ( v . z ) ) ; } | Computes the plane at infinity |
27,106 | public void process ( SimpleImageSequence < T > sequence ) { T frame = sequence . next ( ) ; gui . setPreferredSize ( new Dimension ( frame . getWidth ( ) , frame . getHeight ( ) ) ) ; ShowImages . showWindow ( gui , "KTL Tracker" , true ) ; while ( sequence . hasNext ( ) ) { frame = sequence . next ( ) ; tracker . process ( frame ) ; if ( tracker . getActiveTracks ( null ) . size ( ) < 130 ) tracker . spawnTracks ( ) ; updateGUI ( sequence ) ; BoofMiscOps . pause ( pause ) ; } } | Processes the sequence of images and displays the tracked features in a window |
27,107 | private void updateGUI ( SimpleImageSequence < T > sequence ) { BufferedImage orig = sequence . getGuiImage ( ) ; Graphics2D g2 = orig . createGraphics ( ) ; for ( PointTrack p : tracker . getActiveTracks ( null ) ) { int red = ( int ) ( 2.5 * ( p . featureId % 100 ) ) ; int green = ( int ) ( ( 255.0 / 150.0 ) * ( p . featureId % 150 ) ) ; int blue = ( int ) ( p . featureId % 255 ) ; VisualizeFeatures . drawPoint ( g2 , ( int ) p . x , ( int ) p . y , new Color ( red , green , blue ) ) ; } for ( PointTrack p : tracker . getNewTracks ( null ) ) { VisualizeFeatures . drawPoint ( g2 , ( int ) p . x , ( int ) p . y , Color . green ) ; } gui . setImage ( orig ) ; gui . repaint ( ) ; } | Draw tracked features in blue or red if they were just spawned . |
27,108 | public void createSURF ( ) { ConfigFastHessian configDetector = new ConfigFastHessian ( ) ; configDetector . maxFeaturesPerScale = 250 ; configDetector . extractRadius = 3 ; configDetector . initialSampleSize = 2 ; tracker = FactoryPointTracker . dda_FH_SURF_Fast ( configDetector , null , null , imageType ) ; } | Creates a SURF feature tracker . |
27,109 | public void configure ( int width , int height , float vfov ) { declareVectors ( width , height ) ; float r = ( float ) Math . tan ( vfov / 2.0f ) ; for ( int pixelY = 0 ; pixelY < height ; pixelY ++ ) { float z = 2 * r * pixelY / ( height - 1 ) - r ; for ( int pixelX = 0 ; pixelX < width ; pixelX ++ ) { float theta = GrlConstants . F_PI2 * pixelX / width - GrlConstants . F_PI ; float x = ( float ) Math . cos ( theta ) ; float y = ( float ) Math . sin ( theta ) ; vectors [ pixelY * width + pixelX ] . set ( x , y , z ) ; } } } | Configures the rendered cylinder |
27,110 | public boolean process ( T image ) { configureContourDetector ( image ) ; binary . reshape ( image . width , image . height ) ; inputToBinary . process ( image , binary ) ; detectorSquare . process ( image , binary ) ; detectorSquare . refineAll ( ) ; detectorSquare . getPolygons ( found , null ) ; clusters = s2c . process ( found ) ; c2g . process ( clusters ) ; List < SquareGrid > grids = c2g . getGrids ( ) ; SquareGrid match = null ; double matchSize = 0 ; for ( SquareGrid g : grids ) { if ( g . columns != numCols || g . rows != numRows ) { if ( g . columns == numRows && g . rows == numCols ) { tools . transpose ( g ) ; } else { continue ; } } double size = tools . computeSize ( g ) ; if ( size > matchSize ) { matchSize = size ; match = g ; } } if ( match != null ) { if ( tools . checkFlip ( match ) ) { tools . flipRows ( match ) ; } tools . putIntoCanonical ( match ) ; if ( ! tools . orderSquareCorners ( match ) ) return false ; extractCalibrationPoints ( match ) ; return true ; } return false ; } | Process the image and detect the calibration target |
27,111 | void extractCalibrationPoints ( SquareGrid grid ) { calibrationPoints . clear ( ) ; for ( int row = 0 ; row < grid . rows ; row ++ ) { row0 . clear ( ) ; row1 . clear ( ) ; for ( int col = 0 ; col < grid . columns ; col ++ ) { Polygon2D_F64 square = grid . get ( row , col ) . square ; row0 . add ( square . get ( 0 ) ) ; row0 . add ( square . get ( 1 ) ) ; row1 . add ( square . get ( 3 ) ) ; row1 . add ( square . get ( 2 ) ) ; } calibrationPoints . addAll ( row0 ) ; calibrationPoints . addAll ( row1 ) ; } } | Extracts the calibration points from the corners of a fully ordered grid |
27,112 | public static < T extends ImageGray < T > > SparseScaleGradient < T , ? > createGradient ( boolean useHaar , Class < T > imageType ) { if ( useHaar ) return FactorySparseIntegralFilters . haar ( imageType ) ; else return FactorySparseIntegralFilters . gradient ( imageType ) ; } | Creates a class for computing the image gradient from an integral image in a sparse fashion . All these kernels assume that the kernel is entirely contained inside the image! |
27,113 | public static < T extends ImageGray < T > > boolean isInside ( T ii , double X , double Y , int radiusRegions , int kernelSize , double scale , double c , double s ) { int c_x = ( int ) Math . round ( X ) ; int c_y = ( int ) Math . round ( Y ) ; kernelSize = ( int ) Math . ceil ( kernelSize * scale ) ; int kernelRadius = kernelSize / 2 + ( kernelSize % 2 ) ; int radius = ( int ) Math . ceil ( radiusRegions * scale ) ; int kernelPaddingMinus = radius + kernelRadius + 1 ; int kernelPaddingPlus = radius + kernelRadius ; if ( c != 0 || s != 0 ) { double xx = Math . abs ( c * kernelPaddingMinus - s * kernelPaddingMinus ) ; double yy = Math . abs ( s * kernelPaddingMinus + c * kernelPaddingMinus ) ; double delta = xx > yy ? xx - kernelPaddingMinus : yy - kernelPaddingMinus ; kernelPaddingMinus += ( int ) Math . ceil ( delta ) ; kernelPaddingPlus += ( int ) Math . ceil ( delta ) ; } int x0 = c_x - kernelPaddingMinus ; if ( x0 < 0 ) return false ; int x1 = c_x + kernelPaddingPlus ; if ( x1 >= ii . width ) return false ; int y0 = c_y - kernelPaddingMinus ; if ( y0 < 0 ) return false ; int y1 = c_y + kernelPaddingPlus ; if ( y1 >= ii . height ) return false ; return true ; } | Checks to see if the region is contained inside the image . This includes convolution kernel . Take in account the orientation of the region . |
27,114 | public static double rotatedWidth ( double width , double c , double s ) { return Math . abs ( c ) * width + Math . abs ( s ) * width ; } | Computes the width of a square containment region that contains a rotated rectangle . |
27,115 | public void assignIDsToRigidPoints ( ) { if ( lookupRigid != null ) return ; lookupRigid = new int [ getTotalRigidPoints ( ) ] ; int pointID = 0 ; for ( int i = 0 ; i < rigids . length ; i ++ ) { Rigid r = rigids [ i ] ; r . indexFirst = pointID ; for ( int j = 0 ; j < r . points . length ; j ++ , pointID ++ ) { lookupRigid [ pointID ] = i ; } } } | Assigns an ID to all rigid points . This function does not need to be called by the user as it will be called by the residual function if needed |
27,116 | public void setCamera ( int which , boolean fixed , BundleAdjustmentCamera model ) { cameras [ which ] . known = fixed ; cameras [ which ] . model = model ; } | Specifies the camera model being used . |
27,117 | public void setRigid ( int which , boolean fixed , Se3_F64 worldToObject , int totalPoints ) { Rigid r = rigids [ which ] = new Rigid ( ) ; r . known = fixed ; r . objectToWorld . set ( worldToObject ) ; r . points = new Point [ totalPoints ] ; for ( int i = 0 ; i < totalPoints ; i ++ ) { r . points [ i ] = new Point ( pointSize ) ; } } | Declares the data structure for a rigid object . Location of points are set by accessing the object directly . Rigid objects are useful in known scenes with calibration targets . |
27,118 | public void connectViewToCamera ( int viewIndex , int cameraIndex ) { if ( views [ viewIndex ] . camera != - 1 ) throw new RuntimeException ( "View has already been assigned a camera" ) ; views [ viewIndex ] . camera = cameraIndex ; } | Specifies that the view uses the specified camera |
27,119 | public int getUnknownCameraCount ( ) { int total = 0 ; for ( int i = 0 ; i < cameras . length ; i ++ ) { if ( ! cameras [ i ] . known ) { total ++ ; } } return total ; } | Returns the number of cameras with parameters that are not fixed |
27,120 | public int getTotalRigidPoints ( ) { if ( rigids == null ) return 0 ; int total = 0 ; for ( int i = 0 ; i < rigids . length ; i ++ ) { total += rigids [ i ] . points . length ; } return total ; } | Returns total number of points associated with rigid objects . |
27,121 | public static < T extends KernelBase > T random ( Class < ? > type , int radius , int min , int max , Random rand ) { int width = radius * 2 + 1 ; return random ( type , width , radius , min , max , rand ) ; } | Creates a random kernel of the specified type where each element is drawn from an uniform distribution . |
27,122 | public void detect ( II integral ) { if ( intensity == null ) { intensity = new GrayF32 [ 3 ] ; for ( int i = 0 ; i < intensity . length ; i ++ ) { intensity [ i ] = new GrayF32 ( integral . width , integral . height ) ; } } foundPoints . reset ( ) ; int skip = initialSampleRate ; int sizeStep = scaleStepSize ; int octaveSize = initialSize ; for ( int octave = 0 ; octave < numberOfOctaves ; octave ++ ) { for ( int i = 0 ; i < sizes . length ; i ++ ) { sizes [ i ] = octaveSize + i * sizeStep ; } int maxSize = sizes [ sizes . length - 1 ] ; if ( maxSize > integral . width || maxSize > integral . height ) break ; detectOctave ( integral , skip , sizes ) ; skip += skip ; octaveSize += sizeStep ; sizeStep += sizeStep ; } } | Detect interest points inside of the image . |
27,123 | protected void detectOctave ( II integral , int skip , int ... featureSize ) { int w = integral . width / skip ; int h = integral . height / skip ; for ( int i = 0 ; i < intensity . length ; i ++ ) { intensity [ i ] . reshape ( w , h ) ; } for ( int i = 0 ; i < featureSize . length ; i ++ ) { GIntegralImageFeatureIntensity . hessian ( integral , skip , featureSize [ i ] , intensity [ spaceIndex ] ) ; spaceIndex ++ ; if ( spaceIndex >= 3 ) spaceIndex = 0 ; if ( i >= 2 ) { findLocalScaleSpaceMax ( featureSize , i - 1 , skip ) ; } } } | Computes feature intensities for all the specified feature sizes and finds features inside of the middle feature sizes . |
27,124 | protected static boolean checkMax ( ImageBorder_F32 inten , float bestScore , int c_x , int c_y ) { for ( int y = c_y - 1 ; y <= c_y + 1 ; y ++ ) { for ( int x = c_x - 1 ; x <= c_x + 1 ; x ++ ) { if ( inten . get ( x , y ) >= bestScore ) { return false ; } } } return true ; } | Sees if the best score in the current layer is greater than all the scores in a 3x3 neighborhood in another layer . |
27,125 | public void process ( T gray , GrayU8 binary ) { configureContourDetector ( gray ) ; recycleData ( ) ; positionPatterns . reset ( ) ; interpolate . setImage ( gray ) ; squareDetector . process ( gray , binary ) ; long time0 = System . nanoTime ( ) ; squaresToPositionList ( ) ; long time1 = System . nanoTime ( ) ; createPositionPatternGraph ( ) ; double milli = ( time1 - time0 ) * 1e-6 ; milliGraph . update ( milli ) ; if ( profiler ) { DetectPolygonFromContour < T > detectorPoly = squareDetector . getDetector ( ) ; System . out . printf ( " contour %5.1f shapes %5.1f adjust_bias %5.2f PosPat %6.2f" , detectorPoly . getMilliContour ( ) , detectorPoly . getMilliShapes ( ) , squareDetector . getMilliAdjustBias ( ) , milliGraph . getAverage ( ) ) ; } } | Detects position patterns inside the image and forms a graph . |
27,126 | private void createPositionPatternGraph ( ) { nn . setPoints ( ( List ) positionPatterns . toList ( ) , false ) ; for ( int i = 0 ; i < positionPatterns . size ( ) ; i ++ ) { PositionPatternNode f = positionPatterns . get ( i ) ; double maximumQrCodeWidth = f . largestSide * ( 17 + 4 * maxVersionQR - 7.0 ) / 7.0 ; double searchRadius = 1.2 * maximumQrCodeWidth ; searchRadius *= searchRadius ; search . findNearest ( f , searchRadius , Integer . MAX_VALUE , searchResults ) ; if ( searchResults . size > 1 ) { for ( int j = 0 ; j < searchResults . size ; j ++ ) { NnData < SquareNode > r = searchResults . get ( j ) ; if ( r . point == f ) continue ; considerConnect ( f , r . point ) ; } } } } | Connects together position patterns . For each square finds all of its neighbors based on center distance . Then considers them for connections |
27,127 | void considerConnect ( SquareNode node0 , SquareNode node1 ) { lineA . a = node0 . center ; lineA . b = node1 . center ; int intersection0 = graph . findSideIntersect ( node0 , lineA , intersection , lineB ) ; connectLine . a . set ( intersection ) ; int intersection1 = graph . findSideIntersect ( node1 , lineA , intersection , lineB ) ; connectLine . b . set ( intersection ) ; if ( intersection1 < 0 || intersection0 < 0 ) { return ; } double side0 = node0 . sideLengths [ intersection0 ] ; double side1 = node1 . sideLengths [ intersection1 ] ; double sideLoc0 = connectLine . a . distance ( node0 . square . get ( intersection0 ) ) / side0 ; double sideLoc1 = connectLine . b . distance ( node1 . square . get ( intersection1 ) ) / side1 ; if ( Math . abs ( sideLoc0 - 0.5 ) > 0.35 || Math . abs ( sideLoc1 - 0.5 ) > 0.35 ) return ; if ( Math . abs ( side0 - side1 ) / Math . max ( side0 , side1 ) > 0.25 ) { return ; } if ( ! graph . almostParallel ( node0 , intersection0 , node1 , intersection1 ) ) { return ; } double ratio = Math . max ( node0 . smallestSide / node1 . largestSide , node1 . smallestSide / node0 . largestSide ) ; if ( ratio > 1.3 ) return ; double angle = graph . acuteAngle ( node0 , intersection0 , node1 , intersection1 ) ; double score = lineA . getLength ( ) * ( 1.0 + angle / 0.1 ) ; graph . checkConnect ( node0 , intersection0 , node1 , intersection1 , score ) ; } | Connects the candidate node to node n if they meet several criteria . See code for details . |
27,128 | boolean checkPositionPatternAppearance ( Polygon2D_F64 square , float grayThreshold ) { return ( checkLine ( square , grayThreshold , 0 ) || checkLine ( square , grayThreshold , 1 ) ) ; } | Determines if the found polygon looks like a position pattern . A horizontal and vertical line are sampled . At each sample point it is marked if it is above or below the binary threshold for this square . Location of sample points is found by removing perspective distortion . |
27,129 | static boolean positionSquareIntensityCheck ( float values [ ] , float threshold ) { if ( values [ 0 ] > threshold || values [ 1 ] < threshold ) return false ; if ( values [ 2 ] > threshold || values [ 3 ] > threshold || values [ 4 ] > threshold ) return false ; if ( values [ 5 ] < threshold || values [ 6 ] > threshold ) return false ; return true ; } | Checks to see if the array of sampled intensity values follows the expected pattern for a position pattern . X . XXX . X where x = black and . = white . |
27,130 | public void process ( DMatrixRMaj K1 , Se3_F64 worldToCamera1 , DMatrixRMaj K2 , Se3_F64 worldToCamera2 ) { SimpleMatrix sK1 = SimpleMatrix . wrap ( K1 ) ; SimpleMatrix sK2 = SimpleMatrix . wrap ( K2 ) ; SimpleMatrix R1 = SimpleMatrix . wrap ( worldToCamera1 . getR ( ) ) ; SimpleMatrix R2 = SimpleMatrix . wrap ( worldToCamera2 . getR ( ) ) ; SimpleMatrix T1 = new SimpleMatrix ( 3 , 1 , true , new double [ ] { worldToCamera1 . getT ( ) . x , worldToCamera1 . getT ( ) . y , worldToCamera1 . getT ( ) . z } ) ; SimpleMatrix T2 = new SimpleMatrix ( 3 , 1 , true , new double [ ] { worldToCamera2 . getT ( ) . x , worldToCamera2 . getT ( ) . y , worldToCamera2 . getT ( ) . z } ) ; SimpleMatrix KR1 = sK1 . mult ( R1 ) ; SimpleMatrix KR2 = sK2 . mult ( R2 ) ; SimpleMatrix c1 = R1 . transpose ( ) . mult ( T1 . scale ( - 1 ) ) ; SimpleMatrix c2 = R2 . transpose ( ) . mult ( T2 . scale ( - 1 ) ) ; selectAxises ( R1 , R2 , c1 , c2 ) ; SimpleMatrix RR = new SimpleMatrix ( 3 , 3 , true , new double [ ] { v1 . x , v1 . y , v1 . z , v2 . x , v2 . y , v2 . z , v3 . x , v3 . y , v3 . z } ) ; K = sK1 . plus ( sK2 ) . scale ( 0.5 ) ; K . set ( 0 , 1 , 0 ) ; SimpleMatrix KRR = K . mult ( RR ) ; rect1 . set ( KRR . mult ( KR1 . invert ( ) ) . getDDRM ( ) ) ; rect2 . set ( KRR . mult ( KR2 . invert ( ) ) . getDDRM ( ) ) ; rectifiedR = RR . getDDRM ( ) ; } | Computes rectification transforms for both cameras and optionally a single calibration matrix . |
27,131 | private void selectAxises ( SimpleMatrix R1 , SimpleMatrix R2 , SimpleMatrix c1 , SimpleMatrix c2 ) { v1 . set ( c2 . get ( 0 ) - c1 . get ( 0 ) , c2 . get ( 1 ) - c1 . get ( 1 ) , c2 . get ( 2 ) - c1 . get ( 2 ) ) ; v1 . normalize ( ) ; Vector3D_F64 oldZ = new Vector3D_F64 ( R1 . get ( 2 , 0 ) + R2 . get ( 2 , 0 ) , R1 . get ( 2 , 1 ) + R2 . get ( 2 , 1 ) , R1 . get ( 2 , 2 ) + R2 . get ( 2 , 2 ) ) ; GeometryMath_F64 . cross ( oldZ , v1 , v2 ) ; v2 . normalize ( ) ; GeometryMath_F64 . cross ( v1 , v2 , v3 ) ; v3 . normalize ( ) ; } | Selects axises of new coordinate system |
27,132 | public boolean process ( PairLineNorm line0 , PairLineNorm line1 ) { double a0 = GeometryMath_F64 . dot ( e2 , line0 . l2 ) ; double a1 = GeometryMath_F64 . dot ( e2 , line1 . l2 ) ; GeometryMath_F64 . multTran ( A , line0 . l2 , Al0 ) ; GeometryMath_F64 . multTran ( A , line1 . l2 , Al1 ) ; planeA . set ( line0 . l1 . x , line0 . l1 . y , line0 . l1 . z , 0 ) ; planeB . set ( Al0 . x , Al0 . y , Al0 . z , a0 ) ; if ( ! Intersection3D_F64 . intersect ( planeA , planeB , intersect0 ) ) return false ; intersect0 . slope . normalize ( ) ; planeA . set ( line1 . l1 . x , line1 . l1 . y , line1 . l1 . z , 0 ) ; planeB . set ( Al1 . x , Al1 . y , Al1 . z , a1 ) ; if ( ! Intersection3D_F64 . intersect ( planeA , planeB , intersect1 ) ) return false ; intersect1 . slope . normalize ( ) ; from0to1 . x = intersect1 . p . x - intersect0 . p . x ; from0to1 . y = intersect1 . p . y - intersect0 . p . y ; from0to1 . z = intersect1 . p . z - intersect0 . p . z ; GeometryMath_F64 . cross ( intersect0 . slope , from0to1 , pi . n ) ; pi . p . set ( intersect0 . p ) ; UtilPlane3D_F64 . convert ( pi , pi_gen ) ; v . set ( pi_gen . A / pi_gen . D , pi_gen . B / pi_gen . D , pi_gen . C / pi_gen . D ) ; GeometryMath_F64 . outerProd ( e2 , v , av ) ; CommonOps_DDRM . subtract ( A , av , H ) ; adjust . adjust ( H , line0 ) ; return true ; } | Computes the homography based on two unique lines on the plane |
27,133 | protected int extractNumeral ( ) { int val = 0 ; final int topLeft = getTotalGridElements ( ) - gridWidth ; int shift = 0 ; for ( int i = 1 ; i < gridWidth - 1 ; i ++ ) { final int idx = topLeft + i ; val |= classified [ idx ] << shift ; shift ++ ; } for ( int ii = 1 ; ii < gridWidth - 1 ; ii ++ ) { for ( int i = 0 ; i < gridWidth ; i ++ ) { final int idx = getTotalGridElements ( ) - ( gridWidth * ( ii + 1 ) ) + i ; val |= classified [ idx ] << shift ; shift ++ ; } } for ( int i = 1 ; i < gridWidth - 1 ; i ++ ) { val |= classified [ i ] << shift ; shift ++ ; } return val ; } | Extract the numerical value it encodes |
27,134 | private boolean rotateUntilInLowerCorner ( Result result ) { final int topLeft = getTotalGridElements ( ) - gridWidth ; final int topRight = getTotalGridElements ( ) - 1 ; final int bottomLeft = 0 ; final int bottomRight = gridWidth - 1 ; if ( classified [ bottomLeft ] + classified [ bottomRight ] + classified [ topRight ] + classified [ topLeft ] != 1 ) return true ; result . rotation = 0 ; while ( classified [ topLeft ] != 1 ) { result . rotation ++ ; rotateClockWise ( ) ; } return false ; } | Rotate the pattern until the black corner is in the lower right . Sanity check to make sure there is only one black corner |
27,135 | protected boolean thresholdBinaryNumber ( ) { int lower = ( int ) ( N * ( ambiguityThreshold / 2.0 ) ) ; int upper = ( int ) ( N * ( 1 - ambiguityThreshold / 2.0 ) ) ; final int totalElements = getTotalGridElements ( ) ; for ( int i = 0 ; i < totalElements ; i ++ ) { if ( counts [ i ] < lower ) { classified [ i ] = 0 ; } else if ( counts [ i ] > upper ) { classified [ i ] = 1 ; } else { return true ; } } return false ; } | Sees how many pixels were positive and negative in each square region . Then decides if they should be 0 or 1 or unknown |
27,136 | protected void findBitCounts ( GrayF32 gray , double threshold ) { ThresholdImageOps . threshold ( gray , binaryInner , ( float ) threshold , true ) ; Arrays . fill ( counts , 0 ) ; for ( int row = 0 ; row < gridWidth ; row ++ ) { int y0 = row * binaryInner . width / gridWidth + 2 ; int y1 = ( row + 1 ) * binaryInner . width / gridWidth - 2 ; for ( int col = 0 ; col < gridWidth ; col ++ ) { int x0 = col * binaryInner . width / gridWidth + 2 ; int x1 = ( col + 1 ) * binaryInner . width / gridWidth - 2 ; int total = 0 ; for ( int i = y0 ; i < y1 ; i ++ ) { int index = i * binaryInner . width + x0 ; for ( int j = x0 ; j < x1 ; j ++ ) { total += binaryInner . data [ index ++ ] ; } } counts [ row * gridWidth + col ] = total ; } } } | Converts the gray scale image into a binary number . Skip the outer 1 pixel of each inner square . These tend to be incorrectly classified due to distortion . |
27,137 | public void printClassified ( ) { System . out . println ( ) ; System . out . println ( " " ) ; for ( int row = 0 ; row < gridWidth ; row ++ ) { System . out . print ( " " ) ; for ( int col = 0 ; col < gridWidth ; col ++ ) { System . out . print ( classified [ row * gridWidth + col ] == 1 ? " " : "X" ) ; } System . out . print ( " " ) ; System . out . println ( ) ; } System . out . println ( " " ) ; } | This is only works well as a visual representation if the output font is mono spaced . |
27,138 | private void initializeStructure ( List < AssociatedTriple > listObs , DMatrixRMaj P2 , DMatrixRMaj P3 ) { List < DMatrixRMaj > cameraMatrices = new ArrayList < > ( ) ; cameraMatrices . add ( P1 ) ; cameraMatrices . add ( P2 ) ; cameraMatrices . add ( P3 ) ; List < Point2D_F64 > triangObs = new ArrayList < > ( ) ; triangObs . add ( null ) ; triangObs . add ( null ) ; triangObs . add ( null ) ; structure = new SceneStructureProjective ( true ) ; structure . initialize ( 3 , listObs . size ( ) ) ; observations = new SceneObservations ( 3 ) ; structure . setView ( 0 , true , P1 , 0 , 0 ) ; structure . setView ( 1 , false , P2 , 0 , 0 ) ; structure . setView ( 2 , false , P3 , 0 , 0 ) ; boolean needsPruning = false ; Point4D_F64 X = new Point4D_F64 ( ) ; for ( int i = 0 ; i < listObs . size ( ) ; i ++ ) { AssociatedTriple t = listObs . get ( i ) ; triangObs . set ( 0 , t . p1 ) ; triangObs . set ( 1 , t . p2 ) ; triangObs . set ( 2 , t . p3 ) ; if ( triangulator . triangulate ( triangObs , cameraMatrices , X ) ) { observations . getView ( 0 ) . add ( i , ( float ) t . p1 . x , ( float ) t . p1 . y ) ; observations . getView ( 1 ) . add ( i , ( float ) t . p2 . x , ( float ) t . p2 . y ) ; observations . getView ( 2 ) . add ( i , ( float ) t . p3 . x , ( float ) t . p3 . y ) ; structure . points [ i ] . set ( X . x , X . y , X . z , X . w ) ; } else { needsPruning = true ; } } if ( needsPruning ) { PruneStructureFromSceneProjective pruner = new PruneStructureFromSceneProjective ( structure , observations ) ; pruner . prunePoints ( 1 ) ; } } | Sets up data structures for SBA |
27,139 | private boolean backwardsValidation ( int indexSrc , int bestIndex ) { double bestScoreV = maxError ; int bestIndexV = - 1 ; D d_forward = descDst . get ( bestIndex ) ; setActiveSource ( locationDst . get ( bestIndex ) ) ; for ( int j = 0 ; j < locationSrc . size ( ) ; j ++ ) { double distance = computeDistanceToSource ( locationSrc . get ( j ) ) ; if ( distance > maxDistance ) continue ; D d_v = descSrc . get ( j ) ; double score = scoreAssociation . score ( d_forward , d_v ) ; if ( score < bestScoreV ) { bestScoreV = score ; bestIndexV = j ; } } return bestIndexV == indexSrc ; } | Finds the best match for an index in destination and sees if it matches the source index |
27,140 | public static void multiply ( GrayU8 input , double value , GrayU8 output ) { output . reshape ( input . width , input . height ) ; int columns = input . width ; if ( BoofConcurrency . USE_CONCURRENT ) { ImplPixelMath_MT . multiplyU_A ( input . data , input . startIndex , input . stride , value , output . data , output . startIndex , output . stride , input . height , columns ) ; } else { ImplPixelMath . multiplyU_A ( input . data , input . startIndex , input . stride , value , output . data , output . startIndex , output . stride , input . height , columns ) ; } } | Multiply each element by a scalar value . Both input and output images can be the same instance . |
27,141 | public static void divide ( GrayU8 input , double denominator , GrayU8 output ) { output . reshape ( input . width , input . height ) ; int columns = input . width ; if ( BoofConcurrency . USE_CONCURRENT ) { ImplPixelMath_MT . divideU_A ( input . data , input . startIndex , input . stride , denominator , output . data , output . startIndex , output . stride , input . height , columns ) ; } else { ImplPixelMath . divideU_A ( input . data , input . startIndex , input . stride , denominator , output . data , output . startIndex , output . stride , input . height , columns ) ; } } | Divide each element by a scalar value . Both input and output images can be the same instance . |
27,142 | public boolean performTracking ( PyramidKltFeature feature ) { KltTrackFault result = tracker . track ( feature ) ; if ( result != KltTrackFault . SUCCESS ) { return false ; } else { tracker . setDescription ( feature ) ; return true ; } } | Updates the track using the latest inputs . If tracking fails then the feature description in each layer is unchanged and its global position . |
27,143 | public static void showDialog ( BufferedImage img ) { ImageIcon icon = new ImageIcon ( ) ; icon . setImage ( img ) ; JOptionPane . showMessageDialog ( null , icon ) ; } | Creates a dialog window showing the specified image . The function will not exit until the user clicks ok |
27,144 | public static ImageGridPanel showGrid ( int numColumns , String title , BufferedImage ... images ) { JFrame frame = new JFrame ( title ) ; int numRows = images . length / numColumns + images . length % numColumns ; ImageGridPanel panel = new ImageGridPanel ( numRows , numColumns , images ) ; frame . add ( panel , BorderLayout . CENTER ) ; frame . pack ( ) ; frame . setVisible ( true ) ; return panel ; } | Shows a set of images in a grid pattern . |
27,145 | public static JFrame setupWindow ( final JComponent component , String title , final boolean closeOnExit ) { BoofSwingUtil . checkGuiThread ( ) ; final JFrame frame = new JFrame ( title ) ; frame . add ( component , BorderLayout . CENTER ) ; frame . pack ( ) ; frame . setLocationRelativeTo ( null ) ; if ( closeOnExit ) frame . setDefaultCloseOperation ( JFrame . EXIT_ON_CLOSE ) ; return frame ; } | Sets up the window but doesn t show it . Must be called in a GUI thread |
27,146 | public static void applyBoxFilter ( GrayF32 input ) { GrayF32 boxImage = new GrayF32 ( input . width , input . height ) ; InterleavedF32 boxTransform = new InterleavedF32 ( input . width , input . height , 2 ) ; InterleavedF32 transform = new InterleavedF32 ( input . width , input . height , 2 ) ; GrayF32 blurredImage = new GrayF32 ( input . width , input . height ) ; GrayF32 spatialBlur = new GrayF32 ( input . width , input . height ) ; DiscreteFourierTransform < GrayF32 , InterleavedF32 > dft = DiscreteFourierTransformOps . createTransformF32 ( ) ; PixelMath . divide ( input , 255.0f , input ) ; dft . forward ( input , transform ) ; for ( int y = 0 ; y < 15 ; y ++ ) { int yy = y - 7 < 0 ? boxImage . height + ( y - 7 ) : y - 7 ; for ( int x = 0 ; x < 15 ; x ++ ) { int xx = x - 7 < 0 ? boxImage . width + ( x - 7 ) : x - 7 ; boxImage . set ( xx , yy , 1.0f / ( 15 * 15 ) ) ; } } dft . forward ( boxImage , boxTransform ) ; displayTransform ( transform , "Input Image" ) ; displayTransform ( boxTransform , "Box Filter" ) ; DiscreteFourierTransformOps . multiplyComplex ( transform , boxTransform , transform ) ; dft . inverse ( transform , blurredImage ) ; PixelMath . multiply ( blurredImage , 255.0f , blurredImage ) ; PixelMath . multiply ( input , 255.0f , input ) ; BlurImageOps . mean ( input , spatialBlur , 7 , null , null ) ; BufferedImage originOut = ConvertBufferedImage . convertTo ( input , null ) ; BufferedImage spacialOut = ConvertBufferedImage . convertTo ( spatialBlur , null ) ; BufferedImage blurredOut = ConvertBufferedImage . convertTo ( blurredImage , null ) ; ListDisplayPanel listPanel = new ListDisplayPanel ( ) ; listPanel . addImage ( originOut , "Original Image" ) ; listPanel . addImage ( spacialOut , "Spacial Domain Box" ) ; listPanel . addImage ( blurredOut , "Frequency Domain Box" ) ; ShowImages . showWindow ( listPanel , "Box Blur in Spacial and Frequency Domain of Input Image" ) ; } | Demonstration of how to apply a box filter in the frequency domain and compares the results to a box filter which has been applied in the spatial domain |
27,147 | public static void displayTransform ( InterleavedF32 transform , String name ) { GrayF32 magnitude = new GrayF32 ( transform . width , transform . height ) ; GrayF32 phase = new GrayF32 ( transform . width , transform . height ) ; transform = transform . clone ( ) ; DiscreteFourierTransformOps . shiftZeroFrequency ( transform , true ) ; DiscreteFourierTransformOps . magnitude ( transform , magnitude ) ; DiscreteFourierTransformOps . phase ( transform , phase ) ; PixelMath . log ( magnitude , magnitude ) ; BufferedImage visualMag = VisualizeImageData . grayMagnitude ( magnitude , null , - 1 ) ; BufferedImage visualPhase = VisualizeImageData . colorizeSign ( phase , null , Math . PI ) ; ImageGridPanel dual = new ImageGridPanel ( 1 , 2 , visualMag , visualPhase ) ; ShowImages . showWindow ( dual , "Magnitude and Phase of " + name ) ; } | Display the fourier transform s magnitude and phase . |
27,148 | public static DMatrixRMaj robustFundamental ( List < AssociatedPair > matches , List < AssociatedPair > inliers , double inlierThreshold ) { ConfigRansac configRansac = new ConfigRansac ( ) ; configRansac . inlierThreshold = inlierThreshold ; configRansac . maxIterations = 1000 ; ConfigFundamental configFundamental = new ConfigFundamental ( ) ; configFundamental . which = EnumFundamental . LINEAR_7 ; configFundamental . numResolve = 2 ; configFundamental . errorModel = ConfigFundamental . ErrorModel . GEOMETRIC ; ModelMatcher < DMatrixRMaj , AssociatedPair > ransac = FactoryMultiViewRobust . fundamentalRansac ( configFundamental , configRansac ) ; if ( ! ransac . process ( matches ) ) throw new IllegalArgumentException ( "Failed" ) ; inliers . addAll ( ransac . getMatchSet ( ) ) ; DMatrixRMaj F = new DMatrixRMaj ( 3 , 3 ) ; ModelFitter < DMatrixRMaj , AssociatedPair > refine = FactoryMultiView . fundamentalRefine ( 1e-8 , 400 , EpipolarError . SAMPSON ) ; if ( ! refine . fitModel ( inliers , ransac . getModelParameters ( ) , F ) ) throw new IllegalArgumentException ( "Failed" ) ; return F ; } | Given a set of noisy observations compute the Fundamental matrix while removing the noise . |
27,149 | public static DMatrixRMaj simpleFundamental ( List < AssociatedPair > matches ) { Estimate1ofEpipolar estimateF = FactoryMultiView . fundamental_1 ( EnumFundamental . LINEAR_8 , 0 ) ; DMatrixRMaj F = new DMatrixRMaj ( 3 , 3 ) ; if ( ! estimateF . process ( matches , F ) ) throw new IllegalArgumentException ( "Failed" ) ; return F ; } | If the set of associated features are known to be correct then the fundamental matrix can be computed directly with a lot less code . The down side is that this technique is very sensitive to noise . |
27,150 | public boolean applyErrorCorrection ( QrCode qr ) { QrCode . VersionInfo info = QrCode . VERSION_INFO [ qr . version ] ; QrCode . BlockInfo block = info . levels . get ( qr . error ) ; int wordsBlockAllA = block . codewords ; int wordsBlockDataA = block . dataCodewords ; int wordsEcc = wordsBlockAllA - wordsBlockDataA ; int numBlocksA = block . blocks ; int wordsBlockAllB = wordsBlockAllA + 1 ; int wordsBlockDataB = wordsBlockDataA + 1 ; int numBlocksB = ( info . codewords - wordsBlockAllA * numBlocksA ) / wordsBlockAllB ; int totalBlocks = numBlocksA + numBlocksB ; int totalDataBytes = wordsBlockDataA * numBlocksA + wordsBlockDataB * numBlocksB ; qr . corrected = new byte [ totalDataBytes ] ; ecc . resize ( wordsEcc ) ; rscodes . generator ( wordsEcc ) ; if ( ! decodeBlocks ( qr , wordsBlockDataA , numBlocksA , 0 , 0 , totalDataBytes , totalBlocks ) ) return false ; return decodeBlocks ( qr , wordsBlockDataB , numBlocksB , numBlocksA * wordsBlockDataA , numBlocksA , totalDataBytes , totalBlocks ) ; } | Reconstruct the data while applying error correction . |
27,151 | private QrCode . Mode updateModeLogic ( QrCode . Mode current , QrCode . Mode candidate ) { if ( current == candidate ) return current ; else if ( current == QrCode . Mode . UNKNOWN ) { return candidate ; } else { return QrCode . Mode . MIXED ; } } | If only one mode then that mode is used . If more than one mode is used then set to multiple |
27,152 | boolean checkPaddingBytes ( QrCode qr , int lengthBytes ) { boolean a = true ; for ( int i = lengthBytes ; i < qr . corrected . length ; i ++ ) { if ( a ) { if ( 0b00110111 != ( qr . corrected [ i ] & 0xFF ) ) return false ; } else { if ( 0b10001000 != ( qr . corrected [ i ] & 0xFF ) ) { if ( 0b00110111 == ( qr . corrected [ i ] & 0xFF ) ) { a = true ; } else { return false ; } } } a = ! a ; } return true ; } | Makes sure the used bytes have the expected values |
27,153 | private int decodeNumeric ( QrCode qr , PackedBits8 data , int bitLocation ) { int lengthBits = QrCodeEncoder . getLengthBitsNumeric ( qr . version ) ; int length = data . read ( bitLocation , lengthBits , true ) ; bitLocation += lengthBits ; while ( length >= 3 ) { if ( data . size < bitLocation + 10 ) { qr . failureCause = QrCode . Failure . MESSAGE_OVERFLOW ; return - 1 ; } int chunk = data . read ( bitLocation , 10 , true ) ; bitLocation += 10 ; int valA = chunk / 100 ; int valB = ( chunk - valA * 100 ) / 10 ; int valC = chunk - valA * 100 - valB * 10 ; workString . append ( ( char ) ( valA + '0' ) ) ; workString . append ( ( char ) ( valB + '0' ) ) ; workString . append ( ( char ) ( valC + '0' ) ) ; length -= 3 ; } if ( length == 2 ) { if ( data . size < bitLocation + 7 ) { qr . failureCause = QrCode . Failure . MESSAGE_OVERFLOW ; return - 1 ; } int chunk = data . read ( bitLocation , 7 , true ) ; bitLocation += 7 ; int valA = chunk / 10 ; int valB = chunk - valA * 10 ; workString . append ( ( char ) ( valA + '0' ) ) ; workString . append ( ( char ) ( valB + '0' ) ) ; } else if ( length == 1 ) { if ( data . size < bitLocation + 4 ) { qr . failureCause = QrCode . Failure . MESSAGE_OVERFLOW ; return - 1 ; } int valA = data . read ( bitLocation , 4 , true ) ; bitLocation += 4 ; workString . append ( ( char ) ( valA + '0' ) ) ; } return bitLocation ; } | Decodes a numeric message |
27,154 | private int decodeAlphanumeric ( QrCode qr , PackedBits8 data , int bitLocation ) { int lengthBits = QrCodeEncoder . getLengthBitsAlphanumeric ( qr . version ) ; int length = data . read ( bitLocation , lengthBits , true ) ; bitLocation += lengthBits ; while ( length >= 2 ) { if ( data . size < bitLocation + 11 ) { qr . failureCause = QrCode . Failure . MESSAGE_OVERFLOW ; return - 1 ; } int chunk = data . read ( bitLocation , 11 , true ) ; bitLocation += 11 ; int valA = chunk / 45 ; int valB = chunk - valA * 45 ; workString . append ( valueToAlphanumeric ( valA ) ) ; workString . append ( valueToAlphanumeric ( valB ) ) ; length -= 2 ; } if ( length == 1 ) { if ( data . size < bitLocation + 6 ) { qr . failureCause = QrCode . Failure . MESSAGE_OVERFLOW ; return - 1 ; } int valA = data . read ( bitLocation , 6 , true ) ; bitLocation += 6 ; workString . append ( valueToAlphanumeric ( valA ) ) ; } return bitLocation ; } | Decodes alphanumeric messages |
27,155 | private int decodeByte ( QrCode qr , PackedBits8 data , int bitLocation ) { int lengthBits = QrCodeEncoder . getLengthBitsBytes ( qr . version ) ; int length = data . read ( bitLocation , lengthBits , true ) ; bitLocation += lengthBits ; if ( length * 8 > data . size - bitLocation ) { qr . failureCause = QrCode . Failure . MESSAGE_OVERFLOW ; return - 1 ; } byte rawdata [ ] = new byte [ length ] ; for ( int i = 0 ; i < length ; i ++ ) { rawdata [ i ] = ( byte ) data . read ( bitLocation , 8 , true ) ; bitLocation += 8 ; } String encoding = encodingEci == null ? ( forceEncoding != null ? forceEncoding : guessEncoding ( rawdata ) ) : encodingEci ; try { workString . append ( new String ( rawdata , encoding ) ) ; } catch ( UnsupportedEncodingException ignored ) { qr . failureCause = JIS_UNAVAILABLE ; return - 1 ; } return bitLocation ; } | Decodes byte messages |
27,156 | private int decodeKanji ( QrCode qr , PackedBits8 data , int bitLocation ) { int lengthBits = QrCodeEncoder . getLengthBitsKanji ( qr . version ) ; int length = data . read ( bitLocation , lengthBits , true ) ; bitLocation += lengthBits ; byte rawdata [ ] = new byte [ length * 2 ] ; for ( int i = 0 ; i < length ; i ++ ) { if ( data . size < bitLocation + 13 ) { qr . failureCause = QrCode . Failure . MESSAGE_OVERFLOW ; return - 1 ; } int letter = data . read ( bitLocation , 13 , true ) ; bitLocation += 13 ; letter = ( ( letter / 0x0C0 ) << 8 ) | ( letter % 0x0C0 ) ; if ( letter < 0x01F00 ) { letter += 0x08140 ; } else { letter += 0x0C140 ; } rawdata [ i * 2 ] = ( byte ) ( letter >> 8 ) ; rawdata [ i * 2 + 1 ] = ( byte ) letter ; } try { workString . append ( new String ( rawdata , "Shift_JIS" ) ) ; } catch ( UnsupportedEncodingException ignored ) { qr . failureCause = KANJI_UNAVAILABLE ; return - 1 ; } return bitLocation ; } | Decodes Kanji messages |
27,157 | NodeInfo selectSeedCorner ( ) { NodeInfo best = null ; double bestScore = 0 ; double minAngle = Math . PI + 0.1 ; for ( int i = 0 ; i < contour . size ; i ++ ) { NodeInfo info = contour . get ( i ) ; if ( info . angleBetween < minAngle ) continue ; Edge middleR = selectClosest ( info . right , info , true ) ; if ( middleR == null ) continue ; Edge middleL = selectClosest ( info , info . left , true ) ; if ( middleL == null ) continue ; if ( middleL . target != middleR . target ) continue ; double r = UtilAngle . bound ( middleR . angle + Math . PI ) ; double difference = UtilAngle . dist ( r , middleL . angle ) ; double score = info . angleBetween - difference ; if ( score > bestScore ) { best = info ; bestScore = score ; } } if ( best != null ) { best . marked = true ; } return best ; } | Pick a corner but avoid the pointy edges at the other end |
27,158 | static void bottomTwoColumns ( NodeInfo first , NodeInfo second , List < NodeInfo > column0 , List < NodeInfo > column1 ) { column0 . add ( first ) ; column0 . add ( second ) ; NodeInfo a = selectClosestN ( first , second ) ; if ( a == null ) { return ; } a . marked = true ; column1 . add ( a ) ; NodeInfo b = second ; while ( true ) { NodeInfo t = selectClosestN ( a , b ) ; if ( t == null ) break ; t . marked = true ; column1 . add ( t ) ; a = t ; t = selectClosestN ( a , b ) ; if ( t == null ) break ; t . marked = true ; column0 . add ( t ) ; b = t ; } } | Traverses along the first two columns and sets them up |
27,159 | static Edge selectClosest ( NodeInfo a , NodeInfo b , boolean checkSide ) { double bestScore = Double . MAX_VALUE ; Edge bestEdgeA = null ; Edge edgeAB = a . findEdge ( b ) ; double distAB = a . distance ( b ) ; if ( edgeAB == null ) { return null ; } for ( int i = 0 ; i < a . edges . size ; i ++ ) { Edge edgeA = a . edges . get ( i ) ; NodeInfo aa = a . edges . get ( i ) . target ; if ( aa . marked ) continue ; for ( int j = 0 ; j < b . edges . size ; j ++ ) { Edge edgeB = b . edges . get ( j ) ; NodeInfo bb = b . edges . get ( j ) . target ; if ( bb . marked ) continue ; if ( aa == bb ) { if ( checkSide && UtilAngle . distanceCW ( edgeAB . angle , edgeA . angle ) > Math . PI * 0.75 ) continue ; double angle = UtilAngle . dist ( edgeA . angle , edgeB . angle ) ; if ( angle < 0.3 ) continue ; double da = EllipsesIntoClusters . axisAdjustedDistanceSq ( a . ellipse , aa . ellipse ) ; double db = EllipsesIntoClusters . axisAdjustedDistanceSq ( b . ellipse , aa . ellipse ) ; da = Math . sqrt ( da ) ; db = Math . sqrt ( db ) ; double diffRatio = Math . abs ( da - db ) / Math . max ( da , db ) ; if ( diffRatio > 0.3 ) continue ; double d = ( da + db ) / distAB + 0.1 * angle ; if ( d < bestScore ) { bestScore = d ; bestEdgeA = a . edges . get ( i ) ; } break ; } } } return bestEdgeA ; } | Finds the closest that is the same distance from the two nodes and part of an approximate equilateral triangle |
27,160 | static NodeInfo selectClosestSide ( NodeInfo a , NodeInfo b ) { double ratio = 1.7321 ; NodeInfo best = null ; double bestDistance = Double . MAX_VALUE ; Edge bestEdgeA = null ; Edge bestEdgeB = null ; for ( int i = 0 ; i < a . edges . size ; i ++ ) { NodeInfo aa = a . edges . get ( i ) . target ; if ( aa . marked ) continue ; for ( int j = 0 ; j < b . edges . size ; j ++ ) { NodeInfo bb = b . edges . get ( j ) . target ; if ( bb . marked ) continue ; if ( aa == bb ) { double da = EllipsesIntoClusters . axisAdjustedDistanceSq ( a . ellipse , aa . ellipse ) ; double db = EllipsesIntoClusters . axisAdjustedDistanceSq ( b . ellipse , aa . ellipse ) ; da = Math . sqrt ( da ) ; db = Math . sqrt ( db ) ; double max , min ; if ( da > db ) { max = da ; min = db ; } else { max = db ; min = da ; } double diffRatio = Math . abs ( max - min * ratio ) / max ; if ( diffRatio > 0.25 ) continue ; double d = da + db ; if ( d < bestDistance ) { bestDistance = d ; best = aa ; bestEdgeA = a . edges . get ( i ) ; bestEdgeB = b . edges . get ( j ) ; } break ; } } } if ( best != null ) { double angleA = UtilAngle . distanceCW ( bestEdgeA . angle , bestEdgeB . angle ) ; if ( angleA < Math . PI * 0.25 ) return best ; else return null ; } return null ; } | Selects the closest node with the assumption that it s along the side of the grid . |
27,161 | public static void rgbToYuv ( double r , double g , double b , double yuv [ ] ) { double y = yuv [ 0 ] = 0.299 * r + 0.587 * g + 0.114 * b ; yuv [ 1 ] = 0.492 * ( b - y ) ; yuv [ 2 ] = 0.877 * ( r - y ) ; } | Conversion from RGB to YUV using same equations as Intel IPP . |
27,162 | public static void yuvToRgb ( double y , double u , double v , double rgb [ ] ) { rgb [ 0 ] = y + 1.13983 * v ; rgb [ 1 ] = y - 0.39465 * u - 0.58060 * v ; rgb [ 2 ] = y + 2.032 * u ; } | Conversion from YUV to RGB using same equations as Intel IPP . |
27,163 | public boolean process ( List < AssociatedTriple > observations , TrifocalTensor solution ) { if ( observations . size ( ) < 7 ) throw new IllegalArgumentException ( "At least 7 correspondences must be provided. Found " + observations . size ( ) ) ; LowLevelMultiViewOps . computeNormalization ( observations , N1 , N2 , N3 ) ; createLinearSystem ( observations ) ; solveLinearSystem ( ) ; extractEpipoles . setTensor ( solutionN ) ; extractEpipoles . extractEpipoles ( e2 , e3 ) ; enforce . process ( e2 , e3 , A ) ; enforce . extractSolution ( solutionN ) ; removeNormalization ( solution ) ; return true ; } | Estimates the trifocal tensor given the set of observations |
27,164 | protected void createLinearSystem ( List < AssociatedTriple > observations ) { int N = observations . size ( ) ; A . reshape ( 4 * N , 27 ) ; A . zero ( ) ; for ( int i = 0 ; i < N ; i ++ ) { AssociatedTriple t = observations . get ( i ) ; N1 . apply ( t . p1 , p1_norm ) ; N2 . apply ( t . p2 , p2_norm ) ; N3 . apply ( t . p3 , p3_norm ) ; insert ( i , 0 , p1_norm . x ) ; insert ( i , 1 , p1_norm . y ) ; insert ( i , 2 , 1 ) ; } } | Constructs the linear matrix that describes from the 3 - point constraint with linear dependent rows removed |
27,165 | protected boolean solveLinearSystem ( ) { if ( ! svdNull . decompose ( A ) ) return false ; SingularOps_DDRM . nullVector ( svdNull , true , vectorizedSolution ) ; solutionN . convertFrom ( vectorizedSolution ) ; return true ; } | Computes the null space of the linear system to find the trifocal tensor |
27,166 | protected void removeNormalization ( TrifocalTensor solution ) { DMatrixRMaj N2_inv = N2 . matrixInv ( ) ; DMatrixRMaj N3_inv = N3 . matrixInv ( ) ; DMatrixRMaj N1 = this . N1 . matrix ( ) ; for ( int i = 0 ; i < 3 ; i ++ ) { DMatrixRMaj T = solution . getT ( i ) ; for ( int j = 0 ; j < 3 ; j ++ ) { for ( int k = 0 ; k < 3 ; k ++ ) { double sum = 0 ; for ( int r = 0 ; r < 3 ; r ++ ) { double n1 = N1 . get ( r , i ) ; DMatrixRMaj TN = solutionN . getT ( r ) ; for ( int s = 0 ; s < 3 ; s ++ ) { double n2 = N2_inv . get ( j , s ) ; for ( int t = 0 ; t < 3 ; t ++ ) { sum += n1 * n2 * N3_inv . get ( k , t ) * TN . get ( s , t ) ; } } } T . set ( j , k , sum ) ; } } } } | Translates the trifocal tensor back into regular coordinate system |
27,167 | public double computeAverageDerivative ( Point2D_F64 a , Point2D_F64 b , double tanX , double tanY ) { samplesInside = 0 ; averageUp = averageDown = 0 ; for ( int i = 0 ; i < numSamples ; i ++ ) { double x = ( b . x - a . x ) * i / ( numSamples - 1 ) + a . x ; double y = ( b . y - a . y ) * i / ( numSamples - 1 ) + a . y ; double x0 = x + tanX ; double y0 = y + tanY ; if ( ! BoofMiscOps . checkInside ( integralImage . getWidth ( ) , integralImage . getHeight ( ) , x0 , y0 ) ) continue ; double x1 = x - tanX ; double y1 = y - tanY ; if ( ! BoofMiscOps . checkInside ( integralImage . getWidth ( ) , integralImage . getHeight ( ) , x1 , y1 ) ) continue ; samplesInside ++ ; double up = integral . compute ( x , y , x0 , y0 ) ; double down = integral . compute ( x , y , x1 , y1 ) ; averageUp += up ; averageDown += down ; } if ( samplesInside == 0 ) return 0 ; averageUp /= samplesInside ; averageDown /= samplesInside ; return averageUp - averageDown ; } | Returns average tangential derivative along the line segment . Derivative is computed in direction of tangent . A positive step in the tangent direction will have a positive value . If all samples go outside the image then zero is returned . |
27,168 | public static void rgbToXyz ( int r , int g , int b , double xyz [ ] ) { srgbToXyz ( r / 255.0 , g / 255.0 , b / 255.0 , xyz ) ; } | Conversion from 8 - bit RGB into XYZ . 8 - bit = range of 0 to 255 . |
27,169 | public void configureCamera ( CameraPinholeBrown intrinsic , Se3_F64 planeToCamera ) { this . planeToCamera = planeToCamera ; if ( ! selectOverhead . process ( intrinsic , planeToCamera ) ) throw new IllegalArgumentException ( "Can't find a reasonable overhead map. Can the camera view the plane?" ) ; overhead . centerX = selectOverhead . getCenterX ( ) ; overhead . centerY = selectOverhead . getCenterY ( ) ; createOverhead . configure ( intrinsic , planeToCamera , overhead . centerX , overhead . centerY , overhead . cellSize , selectOverhead . getOverheadWidth ( ) , selectOverhead . getOverheadHeight ( ) ) ; origToMap . set ( overhead . centerX , overhead . centerY , 0 ) ; mapToOrigin . set ( - overhead . centerX , - overhead . centerY , 0 ) ; overhead . image . reshape ( selectOverhead . getOverheadWidth ( ) , selectOverhead . getOverheadHeight ( ) ) ; GImageMiscOps . fill ( overhead . image , 0 ) ; } | Camera the camera s intrinsic and extrinsic parameters . Can be called at any time . |
27,170 | public Se3_F64 getWorldToCurr3D ( ) { worldToCurr3D . getT ( ) . set ( - worldToCurr2D . T . y , 0 , worldToCurr2D . T . x ) ; DMatrixRMaj R = worldToCurr3D . getR ( ) ; R . unsafe_set ( 0 , 0 , worldToCurr2D . c ) ; R . unsafe_set ( 0 , 2 , - worldToCurr2D . s ) ; R . unsafe_set ( 1 , 1 , 1 ) ; R . unsafe_set ( 2 , 0 , worldToCurr2D . s ) ; R . unsafe_set ( 2 , 2 , worldToCurr2D . c ) ; worldToCurr3D . concat ( planeToCamera , worldToCurrCam3D ) ; return worldToCurrCam3D ; } | 3D motion . |
27,171 | public void process ( T gray , GrayU8 binary ) { results . reset ( ) ; ellipseDetector . process ( binary ) ; if ( ellipseRefiner != null ) ellipseRefiner . setImage ( gray ) ; intensityCheck . setImage ( gray ) ; List < BinaryEllipseDetectorPixel . Found > found = ellipseDetector . getFound ( ) ; for ( BinaryEllipseDetectorPixel . Found f : found ) { if ( ! intensityCheck . process ( f . ellipse ) ) { if ( verbose ) System . out . println ( "Rejecting ellipse. Initial fit didn't have intense enough edge" ) ; continue ; } EllipseInfo r = results . grow ( ) ; r . contour = f . contour ; if ( ellipseRefiner != null ) { if ( ! ellipseRefiner . process ( f . ellipse , r . ellipse ) ) { if ( verbose ) System . out . println ( "Rejecting ellipse. Refined fit didn't have an intense enough edge" ) ; results . removeTail ( ) ; continue ; } else if ( ! intensityCheck . process ( f . ellipse ) ) { if ( verbose ) System . out . println ( "Rejecting ellipse. Refined fit didn't have an intense enough edge" ) ; continue ; } } else { r . ellipse . set ( f . ellipse ) ; } r . averageInside = intensityCheck . averageInside ; r . averageOutside = intensityCheck . averageOutside ; } } | Detects ellipses inside the binary image and refines the edges for all detections inside the gray image |
27,172 | public boolean refine ( EllipseRotated_F64 ellipse ) { if ( autoRefine ) throw new IllegalArgumentException ( "Autorefine is true, no need to refine again" ) ; if ( ellipseRefiner == null ) throw new IllegalArgumentException ( "Refiner has not been passed in" ) ; if ( ! ellipseRefiner . process ( ellipse , ellipse ) ) { return false ; } else { return true ; } } | If auto refine is turned off an ellipse can be refined after the fact using this function provided that the refinement algorithm was passed in to the constructor |
27,173 | public static void colorizeSign ( GrayF32 input , float maxAbsValue , Bitmap output , byte [ ] storage ) { shapeShape ( input , output ) ; if ( storage == null ) storage = declareStorage ( output , null ) ; if ( maxAbsValue < 0 ) maxAbsValue = ImageStatistics . maxAbs ( input ) ; int indexDst = 0 ; for ( int y = 0 ; y < input . height ; y ++ ) { int indexSrc = input . startIndex + y * input . stride ; for ( int x = 0 ; x < input . width ; x ++ ) { float value = input . data [ indexSrc ++ ] ; if ( value > 0 ) { storage [ indexDst ++ ] = ( byte ) ( 255f * value / maxAbsValue ) ; storage [ indexDst ++ ] = 0 ; storage [ indexDst ++ ] = 0 ; } else { storage [ indexDst ++ ] = 0 ; storage [ indexDst ++ ] = ( byte ) ( - 255f * value / maxAbsValue ) ; storage [ indexDst ++ ] = 0 ; } storage [ indexDst ++ ] = ( byte ) 0xFF ; } } output . copyPixelsFromBuffer ( ByteBuffer . wrap ( storage ) ) ; } | Renders positive and negative values as two different colors . |
27,174 | public static void grayMagnitude ( GrayS32 input , int maxAbsValue , Bitmap output , byte [ ] storage ) { shapeShape ( input , output ) ; if ( storage == null ) storage = declareStorage ( output , null ) ; if ( maxAbsValue < 0 ) maxAbsValue = ImageStatistics . maxAbs ( input ) ; int indexDst = 0 ; for ( int y = 0 ; y < input . height ; y ++ ) { int indexSrc = input . startIndex + y * input . stride ; for ( int x = 0 ; x < input . width ; x ++ ) { byte gray = ( byte ) ( 255 * Math . abs ( input . data [ indexSrc ++ ] ) / maxAbsValue ) ; storage [ indexDst ++ ] = gray ; storage [ indexDst ++ ] = gray ; storage [ indexDst ++ ] = gray ; storage [ indexDst ++ ] = ( byte ) 0xFF ; } } output . copyPixelsFromBuffer ( ByteBuffer . wrap ( storage ) ) ; } | Renders the image using its gray magnitude |
27,175 | public static void disparity ( GrayI disparity , int minValue , int maxValue , int invalidColor , Bitmap output , byte [ ] storage ) { shapeShape ( disparity , output ) ; if ( storage == null ) storage = declareStorage ( output , null ) ; int range = maxValue - minValue ; int indexDst = 0 ; for ( int y = 0 ; y < disparity . height ; y ++ ) { for ( int x = 0 ; x < disparity . width ; x ++ ) { int v = disparity . unsafe_get ( x , y ) ; int r , g , b ; if ( v > range ) { r = ( invalidColor >> 16 ) & 0xFF ; g = ( invalidColor >> 8 ) & 0xFF ; b = ( invalidColor ) & 0xFF ; } else { g = 0 ; if ( v == 0 ) { r = b = 0 ; } else { r = 255 * v / maxValue ; b = 255 * ( maxValue - v ) / maxValue ; } } storage [ indexDst ++ ] = ( byte ) r ; storage [ indexDst ++ ] = ( byte ) g ; storage [ indexDst ++ ] = ( byte ) b ; storage [ indexDst ++ ] = ( byte ) 0xFF ; } } output . copyPixelsFromBuffer ( ByteBuffer . wrap ( storage ) ) ; } | Colorizes a disparity image . |
27,176 | public static void drawEdgeContours ( List < EdgeContour > contours , int color , Bitmap output , byte [ ] storage ) { if ( output . getConfig ( ) != Bitmap . Config . ARGB_8888 ) throw new IllegalArgumentException ( "Only ARGB_8888 is supported" ) ; if ( storage == null ) storage = declareStorage ( output , null ) ; else Arrays . fill ( storage , ( byte ) 0 ) ; byte r = ( byte ) ( ( color >> 16 ) & 0xFF ) ; byte g = ( byte ) ( ( color >> 8 ) & 0xFF ) ; byte b = ( byte ) ( color ) ; for ( int i = 0 ; i < contours . size ( ) ; i ++ ) { EdgeContour e = contours . get ( i ) ; for ( int j = 0 ; j < e . segments . size ( ) ; j ++ ) { EdgeSegment s = e . segments . get ( j ) ; for ( int k = 0 ; k < s . points . size ( ) ; k ++ ) { Point2D_I32 p = s . points . get ( k ) ; int index = p . y * 4 * output . getWidth ( ) + p . x * 4 ; storage [ index ++ ] = b ; storage [ index ++ ] = g ; storage [ index ++ ] = r ; storage [ index ] = ( byte ) 0xFF ; } } } output . copyPixelsFromBuffer ( ByteBuffer . wrap ( storage ) ) ; } | Draws each contour using a single color . |
27,177 | public void massage ( T input , T output ) { if ( clip ) { T inputAdjusted = clipInput ( input , output ) ; transform . a11 = input . width / ( float ) output . width ; transform . a22 = input . height / ( float ) output . height ; distort . apply ( inputAdjusted , output ) ; } else { transform . a11 = input . width / ( float ) output . width ; transform . a22 = input . height / ( float ) output . height ; distort . apply ( input , output ) ; } } | Clipps and scales the input iamge as neccisary |
27,178 | T clipInput ( T input , T output ) { double ratioInput = input . width / ( double ) input . height ; double ratioOutput = output . width / ( double ) output . height ; T a = input ; if ( ratioInput > ratioOutput ) { int width = input . height * output . width / output . height ; int x0 = ( input . width - width ) / 2 ; int x1 = x0 + width ; clipped = input . subimage ( x0 , 0 , x1 , input . height , clipped ) ; a = clipped ; } else if ( ratioInput < ratioOutput ) { int height = input . width * output . height / output . width ; int y0 = ( input . height - height ) / 2 ; int y1 = y0 + height ; clipped = input . subimage ( 0 , y0 , input . width , y1 , clipped ) ; a = clipped ; } return a ; } | Clip the input image to ensure a constant aspect ratio |
27,179 | public static int nextPow2 ( int x ) { if ( x < 1 ) throw new IllegalArgumentException ( "x must be greater or equal 1" ) ; if ( ( x & ( x - 1 ) ) == 0 ) { if ( x == 1 ) return 2 ; return x ; } x |= ( x >>> 1 ) ; x |= ( x >>> 2 ) ; x |= ( x >>> 4 ) ; x |= ( x >>> 8 ) ; x |= ( x >>> 16 ) ; x |= ( x >>> 32 ) ; return x + 1 ; } | Returns the closest power - of - two number greater than or equal to x . |
27,180 | public static void checkImageArguments ( ImageBase image , ImageInterleaved transform ) { InputSanityCheck . checkSameShape ( image , transform ) ; if ( 2 != transform . getNumBands ( ) ) throw new IllegalArgumentException ( "The transform must have two bands" ) ; } | Checks to see if the image and its transform are appropriate sizes . The transform should have twice the width and twice the height as the image . |
27,181 | public static Se3_F64 estimateCameraMotion ( CameraPinholeBrown intrinsic , List < AssociatedPair > matchedNorm , List < AssociatedPair > inliers ) { ModelMatcherMultiview < Se3_F64 , AssociatedPair > epipolarMotion = FactoryMultiViewRobust . baselineRansac ( new ConfigEssential ( ) , new ConfigRansac ( 200 , 0.5 ) ) ; epipolarMotion . setIntrinsic ( 0 , intrinsic ) ; epipolarMotion . setIntrinsic ( 1 , intrinsic ) ; if ( ! epipolarMotion . process ( matchedNorm ) ) throw new RuntimeException ( "Motion estimation failed" ) ; inliers . addAll ( epipolarMotion . getMatchSet ( ) ) ; return epipolarMotion . getModelParameters ( ) ; } | Estimates the camera motion robustly using RANSAC and a set of associated points . |
27,182 | public static List < AssociatedPair > convertToNormalizedCoordinates ( List < AssociatedPair > matchedFeatures , CameraPinholeBrown intrinsic ) { Point2Transform2_F64 p_to_n = LensDistortionFactory . narrow ( intrinsic ) . undistort_F64 ( true , false ) ; List < AssociatedPair > calibratedFeatures = new ArrayList < > ( ) ; for ( AssociatedPair p : matchedFeatures ) { AssociatedPair c = new AssociatedPair ( ) ; p_to_n . compute ( p . p1 . x , p . p1 . y , c . p1 ) ; p_to_n . compute ( p . p2 . x , p . p2 . y , c . p2 ) ; calibratedFeatures . add ( c ) ; } return calibratedFeatures ; } | Convert a set of associated point features from pixel coordinates into normalized image coordinates . |
27,183 | public static < T extends ImageBase < T > > void rectifyImages ( T distortedLeft , T distortedRight , Se3_F64 leftToRight , CameraPinholeBrown intrinsicLeft , CameraPinholeBrown intrinsicRight , T rectifiedLeft , T rectifiedRight , GrayU8 rectifiedMask , DMatrixRMaj rectifiedK , DMatrixRMaj rectifiedR ) { RectifyCalibrated rectifyAlg = RectifyImageOps . createCalibrated ( ) ; DMatrixRMaj K1 = PerspectiveOps . pinholeToMatrix ( intrinsicLeft , ( DMatrixRMaj ) null ) ; DMatrixRMaj K2 = PerspectiveOps . pinholeToMatrix ( intrinsicRight , ( DMatrixRMaj ) null ) ; rectifyAlg . process ( K1 , new Se3_F64 ( ) , K2 , leftToRight ) ; DMatrixRMaj rect1 = rectifyAlg . getRect1 ( ) ; DMatrixRMaj rect2 = rectifyAlg . getRect2 ( ) ; rectifiedR . set ( rectifyAlg . getRectifiedRotation ( ) ) ; rectifiedK . set ( rectifyAlg . getCalibrationMatrix ( ) ) ; RectifyImageOps . fullViewLeft ( intrinsicLeft , rect1 , rect2 , rectifiedK ) ; FMatrixRMaj rect1_F32 = new FMatrixRMaj ( 3 , 3 ) ; FMatrixRMaj rect2_F32 = new FMatrixRMaj ( 3 , 3 ) ; ConvertMatrixData . convert ( rect1 , rect1_F32 ) ; ConvertMatrixData . convert ( rect2 , rect2_F32 ) ; ImageDistort < T , T > distortLeft = RectifyImageOps . rectifyImage ( intrinsicLeft , rect1_F32 , BorderType . EXTENDED , distortedLeft . getImageType ( ) ) ; ImageDistort < T , T > distortRight = RectifyImageOps . rectifyImage ( intrinsicRight , rect2_F32 , BorderType . EXTENDED , distortedRight . getImageType ( ) ) ; distortLeft . apply ( distortedLeft , rectifiedLeft , rectifiedMask ) ; distortRight . apply ( distortedRight , rectifiedRight ) ; } | Remove lens distortion and rectify stereo images |
27,184 | public static void drawInliers ( BufferedImage left , BufferedImage right , CameraPinholeBrown intrinsic , List < AssociatedPair > normalized ) { Point2Transform2_F64 n_to_p = LensDistortionFactory . narrow ( intrinsic ) . distort_F64 ( false , true ) ; List < AssociatedPair > pixels = new ArrayList < > ( ) ; for ( AssociatedPair n : normalized ) { AssociatedPair p = new AssociatedPair ( ) ; n_to_p . compute ( n . p1 . x , n . p1 . y , p . p1 ) ; n_to_p . compute ( n . p2 . x , n . p2 . y , p . p2 ) ; pixels . add ( p ) ; } AssociationPanel panel = new AssociationPanel ( 20 ) ; panel . setAssociation ( pixels ) ; panel . setImages ( left , right ) ; ShowImages . showWindow ( panel , "Inlier Features" , true ) ; } | Draw inliers for debugging purposes . Need to convert from normalized to pixel coordinates . |
27,185 | public static double euclideanSq ( TupleDesc_F64 a , TupleDesc_F64 b ) { final int N = a . value . length ; double total = 0 ; for ( int i = 0 ; i < N ; i ++ ) { double d = a . value [ i ] - b . value [ i ] ; total += d * d ; } return total ; } | Returns the Euclidean distance squared between the two descriptors . |
27,186 | private float iterationSorSafe ( GrayF32 image1 , int x , int y , int pixelIndex ) { float w = SOR_RELAXATION ; float uf ; float vf ; float ui = initFlowX . data [ pixelIndex ] ; float vi = initFlowY . data [ pixelIndex ] ; float u = flowX . data [ pixelIndex ] ; float v = flowY . data [ pixelIndex ] ; float I1 = image1 . data [ pixelIndex ] ; float I2 = warpImage2 . data [ pixelIndex ] ; float I2x = warpDeriv2X . data [ pixelIndex ] ; float I2y = warpDeriv2Y . data [ pixelIndex ] ; float AU = A_safe ( x , y , flowX ) ; float AV = A_safe ( x , y , flowY ) ; flowX . data [ pixelIndex ] = uf = ( 1 - w ) * u + w * ( ( I1 - I2 + I2x * ui - I2y * ( v - vi ) ) * I2x + alpha2 * AU ) / ( I2x * I2x + alpha2 ) ; flowY . data [ pixelIndex ] = vf = ( 1 - w ) * v + w * ( ( I1 - I2 + I2y * vi - I2x * ( uf - ui ) ) * I2y + alpha2 * AV ) / ( I2y * I2y + alpha2 ) ; return ( uf - u ) * ( uf - u ) + ( vf - v ) * ( vf - v ) ; } | SOR iteration for border pixels |
27,187 | protected static float A_safe ( int x , int y , GrayF32 flow ) { float u0 = safe ( x - 1 , y , flow ) ; float u1 = safe ( x + 1 , y , flow ) ; float u2 = safe ( x , y - 1 , flow ) ; float u3 = safe ( x , y + 1 , flow ) ; float u4 = safe ( x - 1 , y - 1 , flow ) ; float u5 = safe ( x + 1 , y - 1 , flow ) ; float u6 = safe ( x - 1 , y + 1 , flow ) ; float u7 = safe ( x + 1 , y + 1 , flow ) ; return ( 1.0f / 6.0f ) * ( u0 + u1 + u2 + u3 ) + ( 1.0f / 12.0f ) * ( u4 + u5 + u6 + u7 ) ; } | See equation 25 . Safe version |
27,188 | protected static float A ( int x , int y , GrayF32 flow ) { int index = flow . getIndex ( x , y ) ; float u0 = flow . data [ index - 1 ] ; float u1 = flow . data [ index + 1 ] ; float u2 = flow . data [ index - flow . stride ] ; float u3 = flow . data [ index + flow . stride ] ; float u4 = flow . data [ index - 1 - flow . stride ] ; float u5 = flow . data [ index + 1 - flow . stride ] ; float u6 = flow . data [ index - 1 + flow . stride ] ; float u7 = flow . data [ index + 1 + flow . stride ] ; return ( 1.0f / 6.0f ) * ( u0 + u1 + u2 + u3 ) + ( 1.0f / 12.0f ) * ( u4 + u5 + u6 + u7 ) ; } | See equation 25 . Fast unsafe version |
27,189 | protected static float safe ( int x , int y , GrayF32 image ) { if ( x < 0 ) x = 0 ; else if ( x >= image . width ) x = image . width - 1 ; if ( y < 0 ) y = 0 ; else if ( y >= image . height ) y = image . height - 1 ; return image . unsafe_get ( x , y ) ; } | Ensures pixel values are inside the image . If output it is assigned to the nearest pixel inside the image |
27,190 | public void search ( float cx , float cy ) { peakX = cx ; peakY = cy ; setRegion ( cx , cy ) ; for ( int i = 0 ; i < maxIterations ; i ++ ) { float total = 0 ; float sumX = 0 , sumY = 0 ; int kernelIndex = 0 ; if ( interpolate . isInFastBounds ( x0 , y0 ) && interpolate . isInFastBounds ( x0 + width - 1 , y0 + width - 1 ) ) { for ( int yy = 0 ; yy < width ; yy ++ ) { for ( int xx = 0 ; xx < width ; xx ++ ) { float w = weights . weightIndex ( kernelIndex ++ ) ; float weight = w * interpolate . get_fast ( x0 + xx , y0 + yy ) ; total += weight ; sumX += weight * ( xx + x0 ) ; sumY += weight * ( yy + y0 ) ; } } } else { for ( int yy = 0 ; yy < width ; yy ++ ) { for ( int xx = 0 ; xx < width ; xx ++ ) { float w = weights . weightIndex ( kernelIndex ++ ) ; float weight = w * interpolate . get ( x0 + xx , y0 + yy ) ; total += weight ; sumX += weight * ( xx + x0 ) ; sumY += weight * ( yy + y0 ) ; } } } cx = sumX / total ; cy = sumY / total ; setRegion ( cx , cy ) ; float dx = cx - peakX ; float dy = cy - peakY ; peakX = cx ; peakY = cy ; if ( Math . abs ( dx ) < convergenceTol && Math . abs ( dy ) < convergenceTol ) { break ; } } } | Performs a mean - shift search center at the specified coordinates |
27,191 | protected void setRegion ( float cx , float cy ) { x0 = cx - radius ; y0 = cy - radius ; if ( x0 < 0 ) { x0 = 0 ; } else if ( x0 + width > image . width ) { x0 = image . width - width ; } if ( y0 < 0 ) { y0 = 0 ; } else if ( y0 + width > image . height ) { y0 = image . height - width ; } } | Updates the location of the rectangular bounding box |
27,192 | public void gaussianDerivToDirectDeriv ( ) { T blur = GeneralizedImageOps . createSingleBand ( imageType , width , height ) ; T blurDeriv = GeneralizedImageOps . createSingleBand ( imageType , width , height ) ; T gaussDeriv = GeneralizedImageOps . createSingleBand ( imageType , width , height ) ; BlurStorageFilter < T > funcBlur = FactoryBlurFilter . gaussian ( ImageType . single ( imageType ) , sigma , radius ) ; ImageGradient < T , T > funcDeriv = FactoryDerivative . three ( imageType , imageType ) ; ImageGradient < T , T > funcGaussDeriv = FactoryDerivative . gaussian ( sigma , radius , imageType , imageType ) ; funcBlur . process ( input , blur ) ; funcDeriv . process ( blur , blurDeriv , derivY ) ; funcGaussDeriv . process ( input , gaussDeriv , derivY ) ; printIntensity ( "Blur->Deriv" , blurDeriv ) ; printIntensity ( "Gauss Deriv" , gaussDeriv ) ; } | Compare computing the image |
27,193 | public static PaperSize lookup ( String word ) { for ( PaperSize paper : values ) { if ( paper . name . compareToIgnoreCase ( word ) == 0 ) { return paper ; } } return null ; } | Sees if the specified work matches any of the units full name or short name . |
27,194 | public static < In extends ImageBase < In > , Out extends ImageBase < Out > , K extends Kernel1D , B extends ImageBorder < In > > void horizontal ( K kernel , In input , Out output , B border ) { switch ( input . getImageType ( ) . getFamily ( ) ) { case GRAY : { if ( input instanceof GrayF32 ) { ConvolveImage . horizontal ( ( Kernel1D_F32 ) kernel , ( GrayF32 ) input , ( GrayF32 ) output , ( ImageBorder_F32 ) border ) ; } else if ( input instanceof GrayU8 ) { if ( GrayI16 . class . isAssignableFrom ( output . getClass ( ) ) ) ConvolveImage . horizontal ( ( Kernel1D_S32 ) kernel , ( GrayU8 ) input , ( GrayI16 ) output , ( ImageBorder_S32 ) border ) ; else ConvolveImage . horizontal ( ( Kernel1D_S32 ) kernel , ( GrayU8 ) input , ( GrayS32 ) output , ( ImageBorder_S32 ) border ) ; } else if ( input instanceof GrayS16 ) { ConvolveImage . horizontal ( ( Kernel1D_S32 ) kernel , ( GrayS16 ) input , ( GrayI16 ) output , ( ImageBorder_S32 ) border ) ; } else { throw new IllegalArgumentException ( "Unknown image type: " + input . getClass ( ) . getName ( ) ) ; } } break ; case INTERLEAVED : { if ( input instanceof InterleavedF32 ) { ConvolveImage . horizontal ( ( Kernel1D_F32 ) kernel , ( InterleavedF32 ) input , ( InterleavedF32 ) output , ( ImageBorder_IL_F32 ) border ) ; } else if ( input instanceof InterleavedU8 ) { if ( InterleavedI16 . class . isAssignableFrom ( output . getClass ( ) ) ) ConvolveImage . horizontal ( ( Kernel1D_S32 ) kernel , ( InterleavedU8 ) input , ( InterleavedI16 ) output , ( ImageBorder_IL_S32 ) border ) ; else ConvolveImage . horizontal ( ( Kernel1D_S32 ) kernel , ( InterleavedU8 ) input , ( InterleavedS32 ) output , ( ImageBorder_IL_S32 ) border ) ; } else if ( input instanceof InterleavedS16 ) { ConvolveImage . horizontal ( ( Kernel1D_S32 ) kernel , ( InterleavedS16 ) input , ( InterleavedU16 ) output , ( ImageBorder_IL_S32 ) border ) ; } else { throw new IllegalArgumentException ( "Unknown image type: " + input . getClass ( ) . getName ( ) ) ; } } break ; case PLANAR : { Planar inp = ( Planar ) input ; Planar outp = ( Planar ) output ; for ( int i = 0 ; i < inp . getNumBands ( ) ; i ++ ) { horizontal ( kernel , inp . getBand ( i ) , outp . getBand ( i ) , ( ImageBorder ) border ) ; } } break ; } } | Performs a horizontal 1D convolution across the image . Borders are handled as specified by the border parameter . |
27,195 | public static < In extends ImageBase < In > , Out extends ImageBase < Out > , K extends Kernel1D > void horizontal ( K kernel , In input , Out output ) { switch ( input . getImageType ( ) . getFamily ( ) ) { case GRAY : { if ( input instanceof GrayF32 ) { ConvolveImageNoBorder . horizontal ( ( Kernel1D_F32 ) kernel , ( GrayF32 ) input , ( GrayF32 ) output ) ; } else if ( input instanceof GrayU8 ) { if ( GrayI16 . class . isAssignableFrom ( output . getClass ( ) ) ) ConvolveImageNoBorder . horizontal ( ( Kernel1D_S32 ) kernel , ( GrayU8 ) input , ( GrayI16 ) output ) ; else ConvolveImageNoBorder . horizontal ( ( Kernel1D_S32 ) kernel , ( GrayU8 ) input , ( GrayS32 ) output ) ; } else if ( input instanceof GrayS16 ) { ConvolveImageNoBorder . horizontal ( ( Kernel1D_S32 ) kernel , ( GrayS16 ) input , ( GrayI16 ) output ) ; } else { throw new IllegalArgumentException ( "Unknown image type: " + input . getClass ( ) . getName ( ) ) ; } } break ; case INTERLEAVED : { if ( output instanceof InterleavedF32 ) { ConvolveImageNoBorder . horizontal ( ( Kernel1D_F32 ) kernel , ( InterleavedF32 ) input , ( InterleavedF32 ) output ) ; } else if ( input instanceof InterleavedU8 ) { if ( InterleavedI16 . class . isAssignableFrom ( output . getClass ( ) ) ) ConvolveImageNoBorder . horizontal ( ( Kernel1D_S32 ) kernel , ( InterleavedU8 ) input , ( InterleavedI16 ) output ) ; else ConvolveImageNoBorder . horizontal ( ( Kernel1D_S32 ) kernel , ( InterleavedU8 ) input , ( InterleavedS32 ) output ) ; } else if ( input instanceof InterleavedS16 ) { ConvolveImageNoBorder . horizontal ( ( Kernel1D_S32 ) kernel , ( InterleavedS16 ) input , ( InterleavedI16 ) output ) ; } else { throw new IllegalArgumentException ( "Unknown image type: " + input . getClass ( ) . getName ( ) ) ; } } break ; case PLANAR : { Planar inp = ( Planar ) input ; Planar outp = ( Planar ) output ; for ( int i = 0 ; i < inp . getNumBands ( ) ; i ++ ) { horizontal ( kernel , inp . getBand ( i ) , outp . getBand ( i ) ) ; } } break ; default : throw new IllegalArgumentException ( "Unknown image family" ) ; } } | Performs a horizontal 1D convolution across the image . The horizontal border is not processed . |
27,196 | public static < In extends ImageBase , Out extends ImageBase , K extends Kernel1D > void horizontalNormalized ( K kernel , In input , Out output ) { switch ( input . getImageType ( ) . getFamily ( ) ) { case GRAY : { if ( input instanceof GrayF32 ) { ConvolveImageNormalized . horizontal ( ( Kernel1D_F32 ) kernel , ( GrayF32 ) input , ( GrayF32 ) output ) ; } else if ( input instanceof GrayF64 ) { ConvolveImageNormalized . horizontal ( ( Kernel1D_F64 ) kernel , ( GrayF64 ) input , ( GrayF64 ) output ) ; } else if ( input instanceof GrayU8 ) { ConvolveImageNormalized . horizontal ( ( Kernel1D_S32 ) kernel , ( GrayU8 ) input , ( GrayI8 ) output ) ; } else if ( input instanceof GrayS16 ) { ConvolveImageNormalized . horizontal ( ( Kernel1D_S32 ) kernel , ( GrayS16 ) input , ( GrayI16 ) output ) ; } else { throw new IllegalArgumentException ( "Unknown image type: " + input . getClass ( ) . getName ( ) ) ; } } break ; case INTERLEAVED : { if ( input instanceof InterleavedF32 ) { ConvolveImageNormalized . horizontal ( ( Kernel1D_F32 ) kernel , ( InterleavedF32 ) input , ( InterleavedF32 ) output ) ; } else if ( input instanceof InterleavedF64 ) { ConvolveImageNormalized . horizontal ( ( Kernel1D_F64 ) kernel , ( InterleavedF64 ) input , ( InterleavedF64 ) output ) ; } else if ( input instanceof InterleavedU8 ) { ConvolveImageNormalized . horizontal ( ( Kernel1D_S32 ) kernel , ( InterleavedU8 ) input , ( InterleavedI8 ) output ) ; } else if ( input instanceof InterleavedS16 ) { ConvolveImageNormalized . horizontal ( ( Kernel1D_S32 ) kernel , ( InterleavedS16 ) input , ( InterleavedI16 ) output ) ; } else { throw new IllegalArgumentException ( "Unknown image type: " + input . getClass ( ) . getName ( ) ) ; } } break ; case PLANAR : { Planar inp = ( Planar ) input ; Planar outp = ( Planar ) output ; for ( int i = 0 ; i < inp . getNumBands ( ) ; i ++ ) { horizontalNormalized ( kernel , inp . getBand ( i ) , outp . getBand ( i ) ) ; } } break ; default : throw new IllegalArgumentException ( "Unknown image family" ) ; } } | Performs a horizontal 1D convolution across the image while re - normalizing the kernel depending on its overlap with the image . |
27,197 | public static < T extends ImageBase < T > , K extends Kernel2D > void convolveNormalized ( K kernel , T input , T output ) { switch ( input . getImageType ( ) . getFamily ( ) ) { case GRAY : { if ( input instanceof GrayF32 ) { ConvolveImageNormalized . convolve ( ( Kernel2D_F32 ) kernel , ( GrayF32 ) input , ( GrayF32 ) output ) ; } else if ( input instanceof GrayF64 ) { ConvolveImageNormalized . convolve ( ( Kernel2D_F64 ) kernel , ( GrayF64 ) input , ( GrayF64 ) output ) ; } else if ( input instanceof GrayU8 ) { ConvolveImageNormalized . convolve ( ( Kernel2D_S32 ) kernel , ( GrayU8 ) input , ( GrayI8 ) output ) ; } else if ( input instanceof GrayS16 ) { ConvolveImageNormalized . convolve ( ( Kernel2D_S32 ) kernel , ( GrayS16 ) input , ( GrayI16 ) output ) ; } else { throw new IllegalArgumentException ( "Unknown image type: " + input . getClass ( ) . getName ( ) ) ; } } break ; case INTERLEAVED : { if ( input instanceof InterleavedF32 ) { ConvolveImageNormalized . convolve ( ( Kernel2D_F32 ) kernel , ( InterleavedF32 ) input , ( InterleavedF32 ) output ) ; } else if ( input instanceof InterleavedF64 ) { ConvolveImageNormalized . convolve ( ( Kernel2D_F64 ) kernel , ( InterleavedF64 ) input , ( InterleavedF64 ) output ) ; } else if ( input instanceof InterleavedU8 ) { ConvolveImageNormalized . convolve ( ( Kernel2D_S32 ) kernel , ( InterleavedU8 ) input , ( InterleavedI8 ) output ) ; } else if ( input instanceof InterleavedS16 ) { ConvolveImageNormalized . convolve ( ( Kernel2D_S32 ) kernel , ( InterleavedS16 ) input , ( InterleavedI16 ) output ) ; } else { throw new IllegalArgumentException ( "Unknown image type: " + input . getClass ( ) . getName ( ) ) ; } } break ; case PLANAR : { Planar inp = ( Planar ) input ; Planar outp = ( Planar ) output ; for ( int i = 0 ; i < inp . getNumBands ( ) ; i ++ ) { convolveNormalized ( kernel , inp . getBand ( i ) , outp . getBand ( i ) ) ; } } break ; default : throw new IllegalArgumentException ( "Unknown image family" ) ; } } | Performs a 2D convolution across the image while re - normalizing the kernel depending on its overlap with the image . |
27,198 | private void addFirstSegment ( int x , int y ) { Point2D_I32 p = queuePoints . grow ( ) ; p . set ( x , y ) ; EdgeSegment s = new EdgeSegment ( ) ; s . points . add ( p ) ; s . index = 0 ; s . parent = s . parentPixel = - 1 ; e . segments . add ( s ) ; open . add ( s ) ; } | Starts a new segment at the first point in the contour |
27,199 | public static < T extends ImageBase < T > > void abs ( T input , T output ) { if ( input instanceof ImageGray ) { if ( GrayS8 . class == input . getClass ( ) ) { PixelMath . abs ( ( GrayS8 ) input , ( GrayS8 ) output ) ; } else if ( GrayS16 . class == input . getClass ( ) ) { PixelMath . abs ( ( GrayS16 ) input , ( GrayS16 ) output ) ; } else if ( GrayS32 . class == input . getClass ( ) ) { PixelMath . abs ( ( GrayS32 ) input , ( GrayS32 ) output ) ; } else if ( GrayS64 . class == input . getClass ( ) ) { PixelMath . abs ( ( GrayS64 ) input , ( GrayS64 ) output ) ; } else if ( GrayF32 . class == input . getClass ( ) ) { PixelMath . abs ( ( GrayF32 ) input , ( GrayF32 ) output ) ; } else if ( GrayF64 . class == input . getClass ( ) ) { PixelMath . abs ( ( GrayF64 ) input , ( GrayF64 ) output ) ; } } else if ( input instanceof ImageInterleaved ) { if ( InterleavedS8 . class == input . getClass ( ) ) { PixelMath . abs ( ( InterleavedS8 ) input , ( InterleavedS8 ) output ) ; } else if ( InterleavedS16 . class == input . getClass ( ) ) { PixelMath . abs ( ( InterleavedS16 ) input , ( InterleavedS16 ) output ) ; } else if ( InterleavedS32 . class == input . getClass ( ) ) { PixelMath . abs ( ( InterleavedS32 ) input , ( InterleavedS32 ) output ) ; } else if ( InterleavedS64 . class == input . getClass ( ) ) { PixelMath . abs ( ( InterleavedS64 ) input , ( InterleavedS64 ) output ) ; } else if ( InterleavedF32 . class == input . getClass ( ) ) { PixelMath . abs ( ( InterleavedF32 ) input , ( InterleavedF32 ) output ) ; } else if ( InterleavedF64 . class == input . getClass ( ) ) { PixelMath . abs ( ( InterleavedF64 ) input , ( InterleavedF64 ) output ) ; } } else { Planar in = ( Planar ) input ; Planar out = ( Planar ) output ; for ( int i = 0 ; i < in . getNumBands ( ) ; i ++ ) { abs ( in . getBand ( i ) , out . getBand ( i ) ) ; } } } | Sets each pixel in the output image to be the absolute value of the input image . Both the input and output image can be the same instance . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.