@Test public void fifthTest_coherenceSpace() throws Exception { processingPath = "/d2/test.processing/unit_tests/etna.volcano/process/crop/01486_21159.cpm/"; dataPath = "fineCoreg/magSpace/"; masterFileName = "master_patch.48x48.cr4"; slaveFileName = "slave_patch.48x48.cr4"; rows = 48; cols = 48; masterCplx = DataReader.readCplxFloatData(processingPath + dataPath + masterFileName, rows, cols, littleEndian); slaveCplx = DataReader.readCplxFloatData(processingPath + dataPath + slaveFileName, rows, cols, littleEndian); final int ovsFactor = 8; final int AccL = 8; final int AccP = 8; int offsetL = 0; int offsetP = 0; Coregistration coreg = new Coregistration(); clock.start(); double coherence = coreg.coherencespace(AccL, AccP, ovsFactor, masterCplx, slaveCplx, offsetL, offsetP); clock.stop(); logger.info("Time to compute cohrence in SPACE domain [ms]: {}", clock.getElapsedTime()); logger.info("Estimated peak coherence: {}", coherence); }
@Override public double coherencespace(final int AccL, final int AccP, final int osfactor, ComplexDoubleMatrix Master, ComplexDoubleMatrix Mask, double offsetL, double offsetP) { logger.trace("coherencespace (PM 14-Feb-2012)"); final int L = Master.rows; final int P = Master.columns; final int factor = osfactor; final int MasksizeL = L - 2 * AccL; final int MasksizeP = P - 2 * AccP; if (!MathUtils.isPower2(AccL) || !MathUtils.isPower2(AccP)) { logger.error("AccL should be power of 2 for oversampling."); throw new IllegalArgumentException("AccL should be power of 2 for oversampling."); } if (MasksizeL < 4 || MasksizeP < 4) { logger.error("Correlationwindow size too small (<4; size= FC_winsize-2*FC_Acc)."); throw new IllegalArgumentException("Correlationwindow size too small (<4; size= FC_winsize-2*FC_Acc)."); } Window winmask = new Window(AccL, AccL + MasksizeL - 1, AccP, AccP + MasksizeP - 1); DoubleMatrix coher = new DoubleMatrix(2 * AccL, 2 * AccP); Window windef = new Window(); DoubleMatrix magMask = SarUtils.magnitude(Mask); magMask.subi(magMask.mean()); DoubleMatrix Mask2 = new DoubleMatrix((int) winmask.lines(), (int) winmask.pixels()); LinearAlgebraUtils.setdata(Mask2, magMask, winmask); double normmask = Math.pow(Mask2.norm2(), 2); DoubleMatrix Master2 = new DoubleMatrix(MasksizeL, MasksizeP); DoubleMatrix magMaster = SarUtils.magnitude(Master); Geometry.center(magMaster); Window winmaster = new Window(); for (int i = 0; i < 2 * AccL; i++) { winmaster.linelo = i; winmaster.linehi = i + MasksizeL - 1; for (int j = 0; j < 2 * AccP; j++) { winmaster.pixlo = j; winmaster.pixhi = j + MasksizeP - 1; LinearAlgebraUtils.setdata(Master2, windef, magMaster, winmaster); double cohs1s2 = 0.; double cohs1s1 = 0.; for (int k = 0; k < MasksizeL; k++) { for (int l = 0; l < MasksizeP; l++) { cohs1s2 += (Master2.get(k, l) * Mask2.get(k, l)); cohs1s1 += Math.pow(Master2.get(k, l), 2); } } coher.put(i, j, cohs1s2 / Math.sqrt(cohs1s1 * normmask)); } } int offL; int offP; final DoubleMatrix coher8 = oversample(coher, factor, factor); int coher8MaxIndex = coher8.argmax(); offL = coher8.indexRows(coher8MaxIndex); offP = coher8.indexColumns(coher8MaxIndex); final double maxcor = coher8.get(coher8MaxIndex); offsetL = AccL - offL / (double) (factor); offsetP = AccP - offP / (double) (factor); System.out.println("Oversampling factor: " + factor); System.out.println("Sub-pixel level offset: " + offsetL + ", " + offsetP + " (corr=" + maxcor + ")"); return maxcor; }
Coregistration implements ICoregistration { @Override public double coherencespace(final int AccL, final int AccP, final int osfactor, ComplexDoubleMatrix Master, ComplexDoubleMatrix Mask, double offsetL, double offsetP) { logger.trace("coherencespace (PM 14-Feb-2012)"); final int L = Master.rows; final int P = Master.columns; final int factor = osfactor; final int MasksizeL = L - 2 * AccL; final int MasksizeP = P - 2 * AccP; if (!MathUtils.isPower2(AccL) || !MathUtils.isPower2(AccP)) { logger.error("AccL should be power of 2 for oversampling."); throw new IllegalArgumentException("AccL should be power of 2 for oversampling."); } if (MasksizeL < 4 || MasksizeP < 4) { logger.error("Correlationwindow size too small (<4; size= FC_winsize-2*FC_Acc)."); throw new IllegalArgumentException("Correlationwindow size too small (<4; size= FC_winsize-2*FC_Acc)."); } Window winmask = new Window(AccL, AccL + MasksizeL - 1, AccP, AccP + MasksizeP - 1); DoubleMatrix coher = new DoubleMatrix(2 * AccL, 2 * AccP); Window windef = new Window(); DoubleMatrix magMask = SarUtils.magnitude(Mask); magMask.subi(magMask.mean()); DoubleMatrix Mask2 = new DoubleMatrix((int) winmask.lines(), (int) winmask.pixels()); LinearAlgebraUtils.setdata(Mask2, magMask, winmask); double normmask = Math.pow(Mask2.norm2(), 2); DoubleMatrix Master2 = new DoubleMatrix(MasksizeL, MasksizeP); DoubleMatrix magMaster = SarUtils.magnitude(Master); Geometry.center(magMaster); Window winmaster = new Window(); for (int i = 0; i < 2 * AccL; i++) { winmaster.linelo = i; winmaster.linehi = i + MasksizeL - 1; for (int j = 0; j < 2 * AccP; j++) { winmaster.pixlo = j; winmaster.pixhi = j + MasksizeP - 1; LinearAlgebraUtils.setdata(Master2, windef, magMaster, winmaster); double cohs1s2 = 0.; double cohs1s1 = 0.; for (int k = 0; k < MasksizeL; k++) { for (int l = 0; l < MasksizeP; l++) { cohs1s2 += (Master2.get(k, l) * Mask2.get(k, l)); cohs1s1 += Math.pow(Master2.get(k, l), 2); } } coher.put(i, j, cohs1s2 / Math.sqrt(cohs1s1 * normmask)); } } int offL; int offP; final DoubleMatrix coher8 = oversample(coher, factor, factor); int coher8MaxIndex = coher8.argmax(); offL = coher8.indexRows(coher8MaxIndex); offP = coher8.indexColumns(coher8MaxIndex); final double maxcor = coher8.get(coher8MaxIndex); offsetL = AccL - offL / (double) (factor); offsetP = AccP - offP / (double) (factor); System.out.println("Oversampling factor: " + factor); System.out.println("Sub-pixel level offset: " + offsetL + ", " + offsetP + " (corr=" + maxcor + ")"); return maxcor; } }
Coregistration implements ICoregistration { @Override public double coherencespace(final int AccL, final int AccP, final int osfactor, ComplexDoubleMatrix Master, ComplexDoubleMatrix Mask, double offsetL, double offsetP) { logger.trace("coherencespace (PM 14-Feb-2012)"); final int L = Master.rows; final int P = Master.columns; final int factor = osfactor; final int MasksizeL = L - 2 * AccL; final int MasksizeP = P - 2 * AccP; if (!MathUtils.isPower2(AccL) || !MathUtils.isPower2(AccP)) { logger.error("AccL should be power of 2 for oversampling."); throw new IllegalArgumentException("AccL should be power of 2 for oversampling."); } if (MasksizeL < 4 || MasksizeP < 4) { logger.error("Correlationwindow size too small (<4; size= FC_winsize-2*FC_Acc)."); throw new IllegalArgumentException("Correlationwindow size too small (<4; size= FC_winsize-2*FC_Acc)."); } Window winmask = new Window(AccL, AccL + MasksizeL - 1, AccP, AccP + MasksizeP - 1); DoubleMatrix coher = new DoubleMatrix(2 * AccL, 2 * AccP); Window windef = new Window(); DoubleMatrix magMask = SarUtils.magnitude(Mask); magMask.subi(magMask.mean()); DoubleMatrix Mask2 = new DoubleMatrix((int) winmask.lines(), (int) winmask.pixels()); LinearAlgebraUtils.setdata(Mask2, magMask, winmask); double normmask = Math.pow(Mask2.norm2(), 2); DoubleMatrix Master2 = new DoubleMatrix(MasksizeL, MasksizeP); DoubleMatrix magMaster = SarUtils.magnitude(Master); Geometry.center(magMaster); Window winmaster = new Window(); for (int i = 0; i < 2 * AccL; i++) { winmaster.linelo = i; winmaster.linehi = i + MasksizeL - 1; for (int j = 0; j < 2 * AccP; j++) { winmaster.pixlo = j; winmaster.pixhi = j + MasksizeP - 1; LinearAlgebraUtils.setdata(Master2, windef, magMaster, winmaster); double cohs1s2 = 0.; double cohs1s1 = 0.; for (int k = 0; k < MasksizeL; k++) { for (int l = 0; l < MasksizeP; l++) { cohs1s2 += (Master2.get(k, l) * Mask2.get(k, l)); cohs1s1 += Math.pow(Master2.get(k, l), 2); } } coher.put(i, j, cohs1s2 / Math.sqrt(cohs1s1 * normmask)); } } int offL; int offP; final DoubleMatrix coher8 = oversample(coher, factor, factor); int coher8MaxIndex = coher8.argmax(); offL = coher8.indexRows(coher8MaxIndex); offP = coher8.indexColumns(coher8MaxIndex); final double maxcor = coher8.get(coher8MaxIndex); offsetL = AccL - offL / (double) (factor); offsetP = AccP - offP / (double) (factor); System.out.println("Oversampling factor: " + factor); System.out.println("Sub-pixel level offset: " + offsetL + ", " + offsetP + " (corr=" + maxcor + ")"); return maxcor; }  }
Coregistration implements ICoregistration { @Override public double coherencespace(final int AccL, final int AccP, final int osfactor, ComplexDoubleMatrix Master, ComplexDoubleMatrix Mask, double offsetL, double offsetP) { logger.trace("coherencespace (PM 14-Feb-2012)"); final int L = Master.rows; final int P = Master.columns; final int factor = osfactor; final int MasksizeL = L - 2 * AccL; final int MasksizeP = P - 2 * AccP; if (!MathUtils.isPower2(AccL) || !MathUtils.isPower2(AccP)) { logger.error("AccL should be power of 2 for oversampling."); throw new IllegalArgumentException("AccL should be power of 2 for oversampling."); } if (MasksizeL < 4 || MasksizeP < 4) { logger.error("Correlationwindow size too small (<4; size= FC_winsize-2*FC_Acc)."); throw new IllegalArgumentException("Correlationwindow size too small (<4; size= FC_winsize-2*FC_Acc)."); } Window winmask = new Window(AccL, AccL + MasksizeL - 1, AccP, AccP + MasksizeP - 1); DoubleMatrix coher = new DoubleMatrix(2 * AccL, 2 * AccP); Window windef = new Window(); DoubleMatrix magMask = SarUtils.magnitude(Mask); magMask.subi(magMask.mean()); DoubleMatrix Mask2 = new DoubleMatrix((int) winmask.lines(), (int) winmask.pixels()); LinearAlgebraUtils.setdata(Mask2, magMask, winmask); double normmask = Math.pow(Mask2.norm2(), 2); DoubleMatrix Master2 = new DoubleMatrix(MasksizeL, MasksizeP); DoubleMatrix magMaster = SarUtils.magnitude(Master); Geometry.center(magMaster); Window winmaster = new Window(); for (int i = 0; i < 2 * AccL; i++) { winmaster.linelo = i; winmaster.linehi = i + MasksizeL - 1; for (int j = 0; j < 2 * AccP; j++) { winmaster.pixlo = j; winmaster.pixhi = j + MasksizeP - 1; LinearAlgebraUtils.setdata(Master2, windef, magMaster, winmaster); double cohs1s2 = 0.; double cohs1s1 = 0.; for (int k = 0; k < MasksizeL; k++) { for (int l = 0; l < MasksizeP; l++) { cohs1s2 += (Master2.get(k, l) * Mask2.get(k, l)); cohs1s1 += Math.pow(Master2.get(k, l), 2); } } coher.put(i, j, cohs1s2 / Math.sqrt(cohs1s1 * normmask)); } } int offL; int offP; final DoubleMatrix coher8 = oversample(coher, factor, factor); int coher8MaxIndex = coher8.argmax(); offL = coher8.indexRows(coher8MaxIndex); offP = coher8.indexColumns(coher8MaxIndex); final double maxcor = coher8.get(coher8MaxIndex); offsetL = AccL - offL / (double) (factor); offsetP = AccP - offP / (double) (factor); System.out.println("Oversampling factor: " + factor); System.out.println("Sub-pixel level offset: " + offsetL + ", " + offsetP + " (corr=" + maxcor + ")"); return maxcor; }  @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 { @Override public double coherencespace(final int AccL, final int AccP, final int osfactor, ComplexDoubleMatrix Master, ComplexDoubleMatrix Mask, double offsetL, double offsetP) { logger.trace("coherencespace (PM 14-Feb-2012)"); final int L = Master.rows; final int P = Master.columns; final int factor = osfactor; final int MasksizeL = L - 2 * AccL; final int MasksizeP = P - 2 * AccP; if (!MathUtils.isPower2(AccL) || !MathUtils.isPower2(AccP)) { logger.error("AccL should be power of 2 for oversampling."); throw new IllegalArgumentException("AccL should be power of 2 for oversampling."); } if (MasksizeL < 4 || MasksizeP < 4) { logger.error("Correlationwindow size too small (<4; size= FC_winsize-2*FC_Acc)."); throw new IllegalArgumentException("Correlationwindow size too small (<4; size= FC_winsize-2*FC_Acc)."); } Window winmask = new Window(AccL, AccL + MasksizeL - 1, AccP, AccP + MasksizeP - 1); DoubleMatrix coher = new DoubleMatrix(2 * AccL, 2 * AccP); Window windef = new Window(); DoubleMatrix magMask = SarUtils.magnitude(Mask); magMask.subi(magMask.mean()); DoubleMatrix Mask2 = new DoubleMatrix((int) winmask.lines(), (int) winmask.pixels()); LinearAlgebraUtils.setdata(Mask2, magMask, winmask); double normmask = Math.pow(Mask2.norm2(), 2); DoubleMatrix Master2 = new DoubleMatrix(MasksizeL, MasksizeP); DoubleMatrix magMaster = SarUtils.magnitude(Master); Geometry.center(magMaster); Window winmaster = new Window(); for (int i = 0; i < 2 * AccL; i++) { winmaster.linelo = i; winmaster.linehi = i + MasksizeL - 1; for (int j = 0; j < 2 * AccP; j++) { winmaster.pixlo = j; winmaster.pixhi = j + MasksizeP - 1; LinearAlgebraUtils.setdata(Master2, windef, magMaster, winmaster); double cohs1s2 = 0.; double cohs1s1 = 0.; for (int k = 0; k < MasksizeL; k++) { for (int l = 0; l < MasksizeP; l++) { cohs1s2 += (Master2.get(k, l) * Mask2.get(k, l)); cohs1s1 += Math.pow(Master2.get(k, l), 2); } } coher.put(i, j, cohs1s2 / Math.sqrt(cohs1s1 * normmask)); } } int offL; int offP; final DoubleMatrix coher8 = oversample(coher, factor, factor); int coher8MaxIndex = coher8.argmax(); offL = coher8.indexRows(coher8MaxIndex); offP = coher8.indexColumns(coher8MaxIndex); final double maxcor = coher8.get(coher8MaxIndex); offsetL = AccL - offL / (double) (factor); offsetP = AccP - offP / (double) (factor); System.out.println("Oversampling factor: " + factor); System.out.println("Sub-pixel level offset: " + offsetL + ", " + offsetP + " (corr=" + maxcor + ")"); return maxcor; }  @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);  }