Commit dfc47feb authored by Mikhail Karpenko's avatar Mikhail Karpenko

Add extra sensors processing to lens center measurement

parent 63e87e10
...@@ -3761,92 +3761,99 @@ if (MORE_BUTTONS) { ...@@ -3761,92 +3761,99 @@ if (MORE_BUTTONS) {
POWER_CONTROL.lightsOnWithDelay(); POWER_CONTROL.lightsOnWithDelay();
long startTime=System.nanoTime(); long startTime=System.nanoTime();
FOCUS_MEASUREMENT_PARAMETERS.sensorTemperature=CAMERAS.getSensorTemperature(0,FOCUS_MEASUREMENT_PARAMETERS.EEPROM_channel); FOCUS_MEASUREMENT_PARAMETERS.sensorTemperature=CAMERAS.getSensorTemperature(0,FOCUS_MEASUREMENT_PARAMETERS.EEPROM_channel);
imp_sel= CAMERAS.acquireSingleImage ( ImagePlus [] imp_set_ref = CAMERAS.acquireSeveralImages (
true, //boolean useLasers, true, //boolean useLasers,
UPDATE_STATUS); UPDATE_STATUS);
if (imp_sel==null){ if (imp_set_ref==null){
IJ.showMessage("Error","Failed to get camera image\nProcess canceled"); IJ.showMessage("Error","Failed to get camera image\nProcess canceled");
return; return;
} }
if (FOCUS_MEASUREMENT_PARAMETERS.showAcquiredImages){ ImagePlus [] imp_set = new ImagePlus[imp_set_ref.length];
imp_sel.show(); imp_set = imp_set_ref.clone();
imp_sel.updateAndDraw();
}
if (LENS_DISTORTION_PARAMETERS==null){ if (LENS_DISTORTION_PARAMETERS==null){
IJ.showMessage("LENS_DISTORTION_PARAMETERS is not set"); IJ.showMessage("LENS_DISTORTION_PARAMETERS is not set");
return; return;
} }
MatchSimulatedPattern [] matchSimulatedPatternSet = new MatchSimulatedPattern[imp_set.length];
ImagePlus [] imp_calibrated = new ImagePlus[imp_set.length];
double headPointersTilt=Double.NaN; double headPointersTilt=Double.NaN;
// measure rotation from the optical head lasers for (int imgCounter = 0; imgCounter < imp_set.length; imgCounter++) {
if (findCenter &&FOCUS_MEASUREMENT_PARAMETERS.useHeadLasers){
ImagePlus imp_headLasers= CAMERAS.acquireSingleImage (
UV_LED_LASERS,
UPDATE_STATUS);
if (imp_headLasers==null){
IJ.showMessage("Error","Failed to get camera image\nProcess canceled");
return;
}
if (FOCUS_MEASUREMENT_PARAMETERS.showAcquiredImages){ if (FOCUS_MEASUREMENT_PARAMETERS.showAcquiredImages){
imp_headLasers.show(); imp_set[imgCounter].show();
imp_headLasers.updateAndDraw(); imp_set[imgCounter].updateAndDraw();
}
double [][] headPointers=CAMERAS.getHeadPointers(imp_headLasers);
if (headPointers==null) {
System.out.println("Failed to locate optical head laser pointers");
return;
} }
if (DEBUG_LEVEL>1){
for (int n=0;n<headPointers.length;n++) if (headPointers[n]!=null){ // measure rotation from the optical head lasers for the first image only
System.out.println("Head pointer "+n+": X="+IJ.d2s(headPointers[n][0],2)+", Y="+IJ.d2s(headPointers[n][1],2)); if (imgCounter == 0 && findCenter &&FOCUS_MEASUREMENT_PARAMETERS.useHeadLasers){
ImagePlus imp_headLasers= CAMERAS.acquireSingleImage (
UV_LED_LASERS,
UPDATE_STATUS);
if (imp_headLasers==null){
IJ.showMessage("Error","Failed to get camera image\nProcess canceled");
return;
} }
} if (FOCUS_MEASUREMENT_PARAMETERS.showAcquiredImages){
if ((headPointers[0]!=null) && (headPointers[1]!=null)){ imp_headLasers.show();
headPointersTilt=180.0/Math.PI*Math.atan2(headPointers[1][1]-headPointers[0][1], headPointers[1][0]-headPointers[0][0])-LASER_POINTERS.headLasersTilt; imp_headLasers.updateAndDraw();
if (DEBUG_LEVEL>0){
System.out.println("SFE is rotated by "+IJ.d2s(headPointersTilt,3)+" degrees according to optical head laser pointers (clockwise positive)");
} }
double [][] headPointers=CAMERAS.getHeadPointers(imp_headLasers);
if (headPointers==null) {
System.out.println("Failed to locate optical head laser pointers");
return;
}
if (DEBUG_LEVEL>1){
for (int n=0;n<headPointers.length;n++) if (headPointers[n]!=null){
System.out.println("Head pointer "+n+": X="+IJ.d2s(headPointers[n][0],2)+", Y="+IJ.d2s(headPointers[n][1],2));
}
}
if ((headPointers[0]!=null) && (headPointers[1]!=null)){
headPointersTilt=180.0/Math.PI*Math.atan2(headPointers[1][1]-headPointers[0][1], headPointers[1][0]-headPointers[0][0])-LASER_POINTERS.headLasersTilt;
if (DEBUG_LEVEL>0){
System.out.println("SFE is rotated by "+IJ.d2s(headPointersTilt,3)+" degrees according to optical head laser pointers (clockwise positive)");
}
}
FOCUS_MEASUREMENT_PARAMETERS.result_ROT=headPointersTilt;
} }
FOCUS_MEASUREMENT_PARAMETERS.result_ROT=headPointersTilt;
} if (DEBUG_LEVEL>0) System.out.println("Image acquisition (@"+FOCUS_MEASUREMENT_PARAMETERS.sensorTemperature+"C) done at "+ IJ.d2s(0.000000001*(System.nanoTime()-startTime),3));
// reset matchSimulatedPattern, so it will start from scratch
if (DEBUG_LEVEL>0) System.out.println("Image acquisition (@"+FOCUS_MEASUREMENT_PARAMETERS.sensorTemperature+"C) done at "+ IJ.d2s(0.000000001*(System.nanoTime()-startTime),3)); matchSimulatedPatternSet[imgCounter] = new MatchSimulatedPattern(DISTORTION.FFTSize); // new instance, all reset
// reset matchSimulatedPattern, so it will start from scratch // next 2 lines are not needed for the new instance, but can be used alternatively if keeipg it
matchSimulatedPattern= new MatchSimulatedPattern(DISTORTION.FFTSize); // new instance, all reset matchSimulatedPatternSet[imgCounter].invalidateFlatFieldForGrid(); //Reset Flat Field calibration - different image.
// next 2 lines are not needed for the new instance, but can be used alternatively if keeipg it matchSimulatedPatternSet[imgCounter].invalidateFocusMask();
matchSimulatedPattern.invalidateFlatFieldForGrid(); //Reset Flat Field calibration - different image.
matchSimulatedPattern.invalidateFocusMask();
if (matchSimulatedPatternSet[imgCounter].getPointersXY(imp_set[imgCounter],LASER_POINTERS.laserUVMap.length)==null) { // no pointers in this image
IJ.showMessage("Error","No laser pointers detected for image #" + imgCounter + " - they are needed for absolute grid positioning\nProcess canceled");
if (matchSimulatedPattern.getPointersXY(imp_sel,LASER_POINTERS.laserUVMap.length)==null) { // no pointers in this image return;
IJ.showMessage("Error","No laser pointers detected - they are needed for absolute grid positioning\nProcess canceled"); }
return;
} matchSimulatedPatternSet[imgCounter].debugLevel=DEBUG_LEVEL;
int numAbsolutePoints=LENS_ADJUSTMENT.updateFocusGrid(
matchSimulatedPattern.debugLevel=DEBUG_LEVEL; LENS_DISTORTION_PARAMETERS.px0, // pixel coordinate of the the optical center
int numAbsolutePoints=LENS_ADJUSTMENT.updateFocusGrid( LENS_DISTORTION_PARAMETERS.py0, // pixel coordinate of the the optical center
LENS_DISTORTION_PARAMETERS.px0, // pixel coordinate of the the optical center imp_set[imgCounter],
LENS_DISTORTION_PARAMETERS.py0, // pixel coordinate of the the optical center matchSimulatedPatternSet[imgCounter],
imp_sel, DISTORTION,
matchSimulatedPattern, FOCUS_MEASUREMENT_PARAMETERS,
DISTORTION, PATTERN_DETECT,
FOCUS_MEASUREMENT_PARAMETERS, LASER_POINTERS,
PATTERN_DETECT, SIMUL,
LASER_POINTERS, false, // keep (not remove) non-PSF areas
SIMUL, COMPONENTS.equalizeGreens,
false, // keep (not remove) non-PSF areas THREADS_MAX,
COMPONENTS.equalizeGreens, UPDATE_STATUS,
THREADS_MAX, // DEBUG_LEVEL);
UPDATE_STATUS, DISTORTION.loop_debug_level);
// DEBUG_LEVEL); if (numAbsolutePoints<=0) { // no pointers in this image
DISTORTION.loop_debug_level); String msg="No laser pointers matched - they are needed for absolute grid positioning\nProcess canceled";
if (numAbsolutePoints<=0) { // no pointers in this image IJ.showMessage("Error",msg);
String msg="No laser pointers matched - they are needed for absolute grid positioning\nProcess canceled"; System.out.println("Error: "+msg);
IJ.showMessage("Error",msg); return;
System.out.println("Error: "+msg); }
return; if (DEBUG_LEVEL>0) System.out.println("Matched "+numAbsolutePoints+" laser pointers, grid generated at "+ IJ.d2s(0.000000001*(System.nanoTime()-startTime),3));
imp_calibrated[imgCounter] = matchSimulatedPatternSet[imgCounter].getCalibratedPatternAsImage(imp_set[imgCounter],"grid-",numAbsolutePoints);
} }
if (DEBUG_LEVEL>0) System.out.println("Matched "+numAbsolutePoints+" laser pointers, grid generated at "+ IJ.d2s(0.000000001*(System.nanoTime()-startTime),3));
ImagePlus [] imp_calibrated={matchSimulatedPattern.getCalibratedPatternAsImage(imp_sel,"grid-",numAbsolutePoints)};
if (FOCUS_MEASUREMENT_PARAMETERS.showAcquiredImages) imp_calibrated[0].show(); // DISTORTION_PROCESS_CONFIGURATION.showGridImages if (FOCUS_MEASUREMENT_PARAMETERS.showAcquiredImages) imp_calibrated[0].show(); // DISTORTION_PROCESS_CONFIGURATION.showGridImages
if (findCenter){ if (findCenter){
// Read required calibration files // Read required calibration files
...@@ -1761,6 +1761,16 @@ public class CalibrationHardwareInterface { ...@@ -1761,6 +1761,16 @@ public class CalibrationHardwareInterface {
this.lastTimestamp=(String) this.images[0].getProperty("timestamp"); this.lastTimestamp=(String) this.images[0].getProperty("timestamp");
return this.images[0]; return this.images[0];
} }
public ImagePlus [] acquireSeveralImages (boolean useLasers, boolean updateStatus){
getImages(
null, // UVLEDLasers
selectAllSubcameras(),
(useLasers?selectAllSubcameras():null),
true,
this.debugLevel>1); // reset and trigger
this.lastTimestamp=(String) this.images[0].getProperty("timestamp");
return this.images;
}
public ImagePlus acquireSingleImage (UVLEDandLasers uvLEDLasers, boolean updateStatus){ public ImagePlus acquireSingleImage (UVLEDandLasers uvLEDLasers, boolean updateStatus){
getImages( getImages(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment