@Test public void firstTest_MagSpace() throws Exception { clock.start(); processingPath = "/d2/test.processing/unit_tests/etna.volcano/process/crop/01486_21159.cpm/"; dataPath = "coarseCorr/magSpace/"; masterFileName = "master.cr4"; slaveFileName = "slave.cr4"; masterMagnitudeFileName = "masterMagnitude.r4"; slaveMagnitudeFileName = "slaveMagnitude.r4"; correlFileName = "correlMasterSlave.SWAP.r4"; rows = 256 + 1; rowsAcc = 8; cols = 256 + 1; colsAcc = 8; int colsMaster = cols + 2 * rowsAcc; int rowsMaster = rows + 2 * colsAcc; int colsSlave = cols; int rowsSlave = rows; masterCplx = DataReader.readCplxFloatData(processingPath + dataPath + masterFileName, rowsMaster, colsMaster, littleEndian); slaveCplx = DataReader.readCplxFloatData(processingPath + dataPath + slaveFileName, rowsSlave, colsSlave, littleEndian); masterMagnitude = DataReader.readFloatData(processingPath + dataPath + masterMagnitudeFileName, rowsMaster, colsMaster, littleEndian); slaveMagnitude = DataReader.readFloatData(processingPath + dataPath + slaveMagnitudeFileName, rowsSlave, colsSlave, littleEndian); correlMasterSlave_EXPECTED = DataReader.readFloatData(processingPath + dataPath + correlFileName, rowsMaster, colsMaster, bigEndian); clock.stop(); logger.info("Time to read data [ms]: {}", clock.getElapsedTime()); clock.start(); Coregistration coreg = new Coregistration(); DoubleMatrix correlateDouble = coreg.correlate(SarUtils.magnitude(masterCplx), SarUtils.magnitude(slaveCplx)); clock.stop(); logger.info("Time to Cross-correlate in SPACE domain [ms]: {}", clock.getElapsedTime()); float[][] correlateFloatArray = castToFloatMatrix(correlateDouble).toArray2(); float[][] correlMasterSlaveArray = correlMasterSlave_EXPECTED.toArray2(); for (int i = 0; i < correlMasterSlaveArray.length; i++) { float[] floats = correlMasterSlaveArray[i]; Assert.assertArrayEquals(floats, correlateFloatArray[i], (float) DELTA_04); } }
public DoubleMatrix correlate(DoubleMatrix A, DoubleMatrix Mask) { double varM = 0.; Mask.subi(Mask.mean()); for (int ii = 0; ii < Mask.length; ii++) { varM += Math.pow(Mask.get(ii), 2); } int beginl = (Mask.rows - 1) / 2; int beginp = (Mask.columns - 1) / 2; DoubleMatrix Result = DoubleMatrix.zeros(A.rows, A.columns); DoubleMatrix Am = new DoubleMatrix(Mask.rows, Mask.columns); Window winA = new Window(0, Mask.rows - 1, 0, Mask.columns - 1); Window windef = new Window(); for (int i = beginl; i < A.rows - beginl; i++) { for (int j = beginp; j < A.columns - beginp; j++) { LinearAlgebraUtils.setdata(Am, windef, A, winA); Am.subi(Am.mean()); double covAM = 0.; double varA = 0.; for (int l = 0; l < Mask.length; l++) { covAM += (Mask.get(l) * Am.get(l)); varA += Math.pow(Am.get(l), 2); } Result.put(i, j, covAM / Math.sqrt(varM * varA)); winA.pixlo++; winA.pixhi++; } winA.linelo++; winA.linehi++; winA.pixlo = 0; winA.pixhi = winA.pixlo + Mask.columns - 1; } return Result; }
Coregistration implements ICoregistration { public DoubleMatrix correlate(DoubleMatrix A, DoubleMatrix Mask) { double varM = 0.; Mask.subi(Mask.mean()); for (int ii = 0; ii < Mask.length; ii++) { varM += Math.pow(Mask.get(ii), 2); } int beginl = (Mask.rows - 1) / 2; int beginp = (Mask.columns - 1) / 2; DoubleMatrix Result = DoubleMatrix.zeros(A.rows, A.columns); DoubleMatrix Am = new DoubleMatrix(Mask.rows, Mask.columns); Window winA = new Window(0, Mask.rows - 1, 0, Mask.columns - 1); Window windef = new Window(); for (int i = beginl; i < A.rows - beginl; i++) { for (int j = beginp; j < A.columns - beginp; j++) { LinearAlgebraUtils.setdata(Am, windef, A, winA); Am.subi(Am.mean()); double covAM = 0.; double varA = 0.; for (int l = 0; l < Mask.length; l++) { covAM += (Mask.get(l) * Am.get(l)); varA += Math.pow(Am.get(l), 2); } Result.put(i, j, covAM / Math.sqrt(varM * varA)); winA.pixlo++; winA.pixhi++; } winA.linelo++; winA.linehi++; winA.pixlo = 0; winA.pixhi = winA.pixlo + Mask.columns - 1; } return Result; } }
Coregistration implements ICoregistration { public DoubleMatrix correlate(DoubleMatrix A, DoubleMatrix Mask) { double varM = 0.; Mask.subi(Mask.mean()); for (int ii = 0; ii < Mask.length; ii++) { varM += Math.pow(Mask.get(ii), 2); } int beginl = (Mask.rows - 1) / 2; int beginp = (Mask.columns - 1) / 2; DoubleMatrix Result = DoubleMatrix.zeros(A.rows, A.columns); DoubleMatrix Am = new DoubleMatrix(Mask.rows, Mask.columns); Window winA = new Window(0, Mask.rows - 1, 0, Mask.columns - 1); Window windef = new Window(); for (int i = beginl; i < A.rows - beginl; i++) { for (int j = beginp; j < A.columns - beginp; j++) { LinearAlgebraUtils.setdata(Am, windef, A, winA); Am.subi(Am.mean()); double covAM = 0.; double varA = 0.; for (int l = 0; l < Mask.length; l++) { covAM += (Mask.get(l) * Am.get(l)); varA += Math.pow(Am.get(l), 2); } Result.put(i, j, covAM / Math.sqrt(varM * varA)); winA.pixlo++; winA.pixhi++; } winA.linelo++; winA.linehi++; winA.pixlo = 0; winA.pixhi = winA.pixlo + Mask.columns - 1; } return Result; }  }
Coregistration implements ICoregistration { public DoubleMatrix correlate(DoubleMatrix A, DoubleMatrix Mask) { double varM = 0.; Mask.subi(Mask.mean()); for (int ii = 0; ii < Mask.length; ii++) { varM += Math.pow(Mask.get(ii), 2); } int beginl = (Mask.rows - 1) / 2; int beginp = (Mask.columns - 1) / 2; DoubleMatrix Result = DoubleMatrix.zeros(A.rows, A.columns); DoubleMatrix Am = new DoubleMatrix(Mask.rows, Mask.columns); Window winA = new Window(0, Mask.rows - 1, 0, Mask.columns - 1); Window windef = new Window(); for (int i = beginl; i < A.rows - beginl; i++) { for (int j = beginp; j < A.columns - beginp; j++) { LinearAlgebraUtils.setdata(Am, windef, A, winA); Am.subi(Am.mean()); double covAM = 0.; double varA = 0.; for (int l = 0; l < Mask.length; l++) { covAM += (Mask.get(l) * Am.get(l)); varA += Math.pow(Am.get(l), 2); } Result.put(i, j, covAM / Math.sqrt(varM * varA)); winA.pixlo++; winA.pixhi++; } winA.linelo++; winA.linehi++; winA.pixlo = 0; winA.pixhi = winA.pixlo + Mask.columns - 1; } return Result; }  @Override void coarseporbit(Ellipsoid ell, SLCImage master, SLCImage slave, Orbit masterorbit, Orbit slaveorbit, Baseline baseline); @Override void coarsecorrel(Input.CoarseCorr input, SLCImage minfo, SLCImage sinfo); @Override void coarsecorrelfft(Input.CoarseCorr coarsecorrinput, SLCImage minfo, SLCImage sinfo); @Override void mtiming_correl(Input.MasterTiming input, SLCImage minfo, todo_classes.productinfo sinfo); @Override void mtiming_correlfft(Input.MasterTiming input, SLCImage minfo, todo_classes.productinfo sinfo); @Override int[][] distributepoints(float numberofpoints, Window win); @Override void getoffset(DoubleMatrix Result, long offsetLines, long offsetPixels); @Override void getmodeoffset(float[][] Result, long offsetLines, long offsetPixels); @Override void finecoreg(Input.FineCorr fineinput, SLCImage minfo, SLCImage sinfo); @Override double coherencefft(ComplexDoubleMatrix Master, ComplexDoubleMatrix Mask, int ovsfactor, int AccL,
                               int AccP, double offsetL, double offsetP); @Override double crosscorrelate(ComplexDoubleMatrix Master, ComplexDoubleMatrix Mask,
                                 int ovsfactor,
                                 int AccL, int AccP,
                                 double offsetL, double offsetP); @Override double coherencespace(final int AccL, final int AccP, final int osfactor,
                                 ComplexDoubleMatrix Master, ComplexDoubleMatrix Mask,
                                 double offsetL, double offsetP); @Override void coregpm(SLCImage master, SLCImage slave, String i_resfile, Input.CoregPM coregpminput,
                        int demassist); @Override DoubleMatrix getofffile(String file, float threshold); @Override void resample(Input.Resample resampleinput,
                         SLCImage master, SLCImage slave,
                         double[] cpmL, double[] cpmP,
                         int demassist); @Override void ms_timing_error(SLCImage master, String i_resfile, Input.RelTiming timinginput,
                                int coarse_orbit_offsetL, int coarse_orbit_offsetP); DoubleMatrix correlate(DoubleMatrix A, DoubleMatrix Mask); void shiftazispectrum(final ComplexDoubleMatrix data, // slcData in space domain
                                 final double prf,
                                 final double rsr2x,
                                 final double[] doppler,   // polynomial fDC
                                 final double shift); @Deprecated static Window getOverlap(final Window master, final Window slave); static Window getOverlap(final SLCImage master, final SLCImage slave, final double[] cpmL, final double[] cpmP); static Window getOverlap(final SLCImage master, final SLCImage slave,
                                    final double Npointsd2, final double timing_L, final double timing_P); }
Coregistration implements ICoregistration { public DoubleMatrix correlate(DoubleMatrix A, DoubleMatrix Mask) { double varM = 0.; Mask.subi(Mask.mean()); for (int ii = 0; ii < Mask.length; ii++) { varM += Math.pow(Mask.get(ii), 2); } int beginl = (Mask.rows - 1) / 2; int beginp = (Mask.columns - 1) / 2; DoubleMatrix Result = DoubleMatrix.zeros(A.rows, A.columns); DoubleMatrix Am = new DoubleMatrix(Mask.rows, Mask.columns); Window winA = new Window(0, Mask.rows - 1, 0, Mask.columns - 1); Window windef = new Window(); for (int i = beginl; i < A.rows - beginl; i++) { for (int j = beginp; j < A.columns - beginp; j++) { LinearAlgebraUtils.setdata(Am, windef, A, winA); Am.subi(Am.mean()); double covAM = 0.; double varA = 0.; for (int l = 0; l < Mask.length; l++) { covAM += (Mask.get(l) * Am.get(l)); varA += Math.pow(Am.get(l), 2); } Result.put(i, j, covAM / Math.sqrt(varM * varA)); winA.pixlo++; winA.pixhi++; } winA.linelo++; winA.linehi++; winA.pixlo = 0; winA.pixhi = winA.pixlo + Mask.columns - 1; } return Result; }  @Override void coarseporbit(Ellipsoid ell, SLCImage master, SLCImage slave, Orbit masterorbit, Orbit slaveorbit, Baseline baseline); @Override void coarsecorrel(Input.CoarseCorr input, SLCImage minfo, SLCImage sinfo); @Override void coarsecorrelfft(Input.CoarseCorr coarsecorrinput, SLCImage minfo, SLCImage sinfo); @Override void mtiming_correl(Input.MasterTiming input, SLCImage minfo, todo_classes.productinfo sinfo); @Override void mtiming_correlfft(Input.MasterTiming input, SLCImage minfo, todo_classes.productinfo sinfo); @Override int[][] distributepoints(float numberofpoints, Window win); @Override void getoffset(DoubleMatrix Result, long offsetLines, long offsetPixels); @Override void getmodeoffset(float[][] Result, long offsetLines, long offsetPixels); @Override void finecoreg(Input.FineCorr fineinput, SLCImage minfo, SLCImage sinfo); @Override double coherencefft(ComplexDoubleMatrix Master, ComplexDoubleMatrix Mask, int ovsfactor, int AccL,
                               int AccP, double offsetL, double offsetP); @Override double crosscorrelate(ComplexDoubleMatrix Master, ComplexDoubleMatrix Mask,
                                 int ovsfactor,
                                 int AccL, int AccP,
                                 double offsetL, double offsetP); @Override double coherencespace(final int AccL, final int AccP, final int osfactor,
                                 ComplexDoubleMatrix Master, ComplexDoubleMatrix Mask,
                                 double offsetL, double offsetP); @Override void coregpm(SLCImage master, SLCImage slave, String i_resfile, Input.CoregPM coregpminput,
                        int demassist); @Override DoubleMatrix getofffile(String file, float threshold); @Override void resample(Input.Resample resampleinput,
                         SLCImage master, SLCImage slave,
                         double[] cpmL, double[] cpmP,
                         int demassist); @Override void ms_timing_error(SLCImage master, String i_resfile, Input.RelTiming timinginput,
                                int coarse_orbit_offsetL, int coarse_orbit_offsetP); DoubleMatrix correlate(DoubleMatrix A, DoubleMatrix Mask); void shiftazispectrum(final ComplexDoubleMatrix data, // slcData in space domain
                                 final double prf,
                                 final double rsr2x,
                                 final double[] doppler,   // polynomial fDC
                                 final double shift); @Deprecated static Window getOverlap(final Window master, final Window slave); static Window getOverlap(final SLCImage master, final SLCImage slave, final double[] cpmL, final double[] cpmP); static Window getOverlap(final SLCImage master, final SLCImage slave,
                                    final double Npointsd2, final double timing_L, final double timing_P);  }