use of mcib3d.image3d.legacy.FHTImage3D in project mcib3d-core by mcib3d.
the class Align2DData method computeRotation2ImagesFHT.
/**
* compute the rotation between 2 images using the Fourier Transform.<BR>
* use the power spectrum to be free of translation<BR>
* then convert to polar coordinate to compute rotation with cross-correlation
*
* @param image1 reference image
* @param image2 image to rotate
* @param range the rotation computed will be between [-range,+range[
* @param angleprecision the precision wanted (1 for degrees precision, 0.1
* for decidegrees precision)
* @return angle in degrees to rotate the second image for it to
* coincide with the first
*/
public static double computeRotation2ImagesFHT(ImageProcessor image1, ImageProcessor image2, double range, double angleprecision) {
// System.out.println("FHT " + image1.getWidth());
ImageProcessor img1 = toPolar(new FHTImage3D(image1).center().getPowerSpectrum(true).getProcessor(1), range, angleprecision);
ImageProcessor img2 = toPolar(new FHTImage3D(image2).center().getPowerSpectrum(true).getProcessor(1), range, angleprecision);
Voxel3D corr = FHTImage3D.getMaxCorrelation(img1, img2);
// IJ.write("max (" + corr.getX() + ", " + corr.getY() + ", " + corr.getZ() + ") =" + corr.getValue());
return -corr.getX() * angleprecision;
// ImageProcessor img1 = new FHTImage3D(image1).center().getPowerSpectrum(true).getProcessor(1);
// ImageProcessor img2 = new FHTImage3D(image2).center().getPowerSpectrum(true).getProcessor(1);
// return computeRotation2Images(img1, img2, range, angleprecision);
}
use of mcib3d.image3d.legacy.FHTImage3D in project mcib3d-core by mcib3d.
the class Align2DData method XCorr.
/**
* crosscorrelation of all images
*/
public void XCorr() {
int rayon = sizex < sizey ? sizex / 2 : sizey / 2;
// ImageProcessor tmp = insert2(serie[0].getImage(true), rayon, true);
int oldtx = serie[0].getTx();
int oldty = serie[0].getTy();
ImageProcessor ip = serie[0].getImage(true);
ip.setRoi(selection);
FHTImage3D fht1 = new FHTImage3D(ip.crop());
FHTImage3D fht2;
int totx = 0;
int toty = 0;
System.out.println("Xcorr...");
Chrono time = new Chrono(sizez - 1);
time.start();
for (int i = 1; i < sizez; i++) {
// if (show) {
// IJ.showStatus("" + i + "/" + (sizez - 1));
// }
// tmp = insert2(serie[i].getImage(true), rayon, true);
ip = serie[i].getImage(true);
ip.setRoi(selection);
fht2 = new FHTImage3D(ip.crop());
Voxel3D max = FHTImage3D.getMaxCorrelation(fht1, fht2);
fht1 = fht2;
int tmpx = oldtx;
int tmpy = oldty;
oldtx = serie[i].getTx();
oldty = serie[i].getTy();
serie[i].addTranslation(serie[i - 1].getTx() + max.getX() - tmpx, serie[i - 1].getTy() + max.getY() - tmpy);
totx += serie[i].getTx();
toty += serie[i].getTy();
time.stop();
String strtime = "Xcorr : " + 100 * (i + 1) / sizez + "% remaining " + time.remainString(i);
System.out.print("\r \r" + strtime + " total :" + time.totalTimeEstimateString(i) + " ");
if (show) {
IJ.showStatus(strtime);
}
// System.out.print("\r" + 100 * (i + 1) / sizez + "% \t" + time.delayString() + "\t (" + time.remainString(i) + ") ");
}
totx /= sizez;
toty /= sizez;
for (int i = 0; i < sizez; i++) {
serie[i].addTranslation(-totx, -toty);
IJ.log(" final image " + i + " : tx =" + serie[i].getTx() + ", ty=" + serie[i].getTy());
}
System.out.print("\n");
IJ.freeMemory();
}
Aggregations