Commit 1880685e authored by Aliaksandr Halavatyi's avatar Aliaksandr Halavatyi
Browse files

option in embryo focusing job to ignore xy positions from calculations

parent 4af06eda
......@@ -15,7 +15,7 @@
<groupId>embl.almf</groupId>
<version>1.0.6-snapshot</version>
<version>1.0.7-SNAPSHOT</version>
<name>Fly_Embryo_Feedback</name>
<inceptionYear>2017</inceptionYear>
......
......@@ -16,10 +16,14 @@ import de.embl.cba.morphometry.Utils;
import ij.IJ;
import net.imagej.ImageJ;
import ij.ImagePlus;
import ij.ImageStack;
import ij.Prefs;
import ij.gui.Arrow;
import ij.gui.Overlay;
import ij.gui.PointRoi;
import ij.gui.Roi;
import ij.plugin.ImageCalculator;
import ij.process.ImageProcessor;
import loci.plugins.BF;
import loci.plugins.in.ImporterOptions;
import net.imagej.ops.OpService;
......@@ -32,6 +36,7 @@ public class Job_FocusEmbryoAutoDatasetSplit extends Job_Default{
public static final String KEY_FOCUS_CHANNEL_INDEX="Focus channel index";
public static final String KEY_WAIT_IMAGE_OPENING="Wait for image opening (milliseconds)";
public static final String KEY_FOCUS_OFFSET="Focus offset";
public static final String KEY_CORRECT_XY="Correct XY";
......@@ -48,6 +53,10 @@ public class Job_FocusEmbryoAutoDatasetSplit extends Job_Default{
private int targetChannel=1;
private int imageOpeningTimeDelay=3000;
private int focusOffset=0;
private boolean makeBinary=false;
private int thresholdValue=300;
private boolean correctXY=true;
@Override
public void initialise(String _fTag,String _colNm, boolean _visOnline){
......@@ -115,18 +124,38 @@ public class Job_FocusEmbryoAutoDatasetSplit extends Job_Default{
this.showDebug(img, "Original Image", false);
this.showDebug(img, "Original Image", true);
ImagePlus imageToProcess=null;
if (makeBinary) {
Prefs.blackBackground = true;
ImageStack originalStack=img.getStack();
ImageStack binaryStack=new ImageStack(originalStack.getWidth(),originalStack.getHeight());
int nSlices=originalStack.getSize();
for (int iSlice=1;iSlice<=nSlices;iSlice++) {
ImageProcessor originalSlice=originalStack.getProcessor(iSlice);
originalSlice.setThreshold(thresholdValue, Double.MAX_VALUE, originalSlice.getLutUpdateMode());
binaryStack.addSlice(originalSlice.createMask());
}
imageToProcess=new ImagePlus("Image to process", binaryStack);
IJ.run(imageToProcess, "Divide...", "value=255 stack");
ImageCalculator ic=new ImageCalculator();
imageToProcess = ic.run("Multiply create stack", img, imageToProcess);
}else {
imageToProcess=img;
}
//new WaitForUserDialog ("Select Shift Point").show();
this.showDebug(img, "Original Image", false);
this.showDebug(imageToProcess, "ImageToProcess", true);
//////code from Tischi
try{
getEllipsoidParameters(img);
getEllipsoidParameters(imageToProcess,img);
}catch (Exception _ex) {
return false;
}
......@@ -141,7 +170,7 @@ public class Job_FocusEmbryoAutoDatasetSplit extends Job_Default{
}
void getEllipsoidParameters(ImagePlus _image)throws Exception {
void getEllipsoidParameters(ImagePlus _imageProcess, ImagePlus _imageCalibration)throws Exception {
final FlyEmbryoRegistrationSettings settings = new FlyEmbryoRegistrationSettings();
......@@ -149,15 +178,22 @@ public class Job_FocusEmbryoAutoDatasetSplit extends Job_Default{
final FlyEmbryoSingleChannelRegistration registration = new FlyEmbryoSingleChannelRegistration( settings, opService );
final double[] calibration = Utils.getCalibration( _image );
final double[] calibration = Utils.getCalibration( _imageCalibration );
registration.run( _image,0);
registration.run( _imageProcess,0);
final double[] centre = registration.getElliposidCentreInInputImagePixelUnits();
final double[] angles = registration.getElliposidEulerAnglesInDegrees();
selectedXPosition = centre[0];
selectedYPosition = centre[1];
if (correctXY) {
selectedXPosition = centre[0];
selectedYPosition = centre[1];
}else {
selectedXPosition=img.getWidth()/2.0;
selectedYPosition=img.getHeight()/2.0;
}
selectedZPosition = centre[2];
rotation=-angles[0];
......@@ -246,6 +282,7 @@ public class Job_FocusEmbryoAutoDatasetSplit extends Job_Default{
jobCollection.addParameter(KEY_FOCUS_CHANNEL_INDEX, null, targetChannel, ParameterType.INT_PARAMETER);
jobCollection.addParameter(KEY_WAIT_IMAGE_OPENING, null, imageOpeningTimeDelay,ParameterType.INT_PARAMETER);
jobCollection.addParameter(KEY_FOCUS_OFFSET, null, focusOffset, ParameterType.INT_PARAMETER);
jobCollection.addParameter(KEY_CORRECT_XY, null, correctXY, ParameterType.BOOL_PARAMETER);
return jobCollection;
......@@ -256,6 +293,7 @@ public class Job_FocusEmbryoAutoDatasetSplit extends Job_Default{
this.targetChannel= (Integer)_jobParameterCollection.getParameterValue(KEY_FOCUS_CHANNEL_INDEX);
this.imageOpeningTimeDelay= (Integer)_jobParameterCollection.getParameterValue(KEY_WAIT_IMAGE_OPENING);
this.focusOffset= (Integer)_jobParameterCollection.getParameterValue(KEY_FOCUS_OFFSET);
this.correctXY= (Boolean)_jobParameterCollection.getParameterValue(KEY_CORRECT_XY);
}
......@@ -267,11 +305,11 @@ public class Job_FocusEmbryoAutoDatasetSplit extends Job_Default{
// start ImageJ
new ImageJ().ui().showUI();
String tblPth="X:\\group\\Aliaksandr\\User_data\\Crocker-fly-feedback\\03082019_march_test";
String tblFnm="summary_test03_.txt";
String tblPth="C:\\tempdat\\Raquel\\Raquel-LSM880_15042021_finok";
String tblFnm="summary_Test1_.txt";
Job_FocusEmbryoAutoDatasetSplit testJob=new Job_FocusEmbryoAutoDatasetSplit();
testJob.initialise(null, "Focus.Image", false);
testJob.testJobMicTable(11, tblPth, tblFnm);
testJob.testJobMicTable(3, tblPth, tblFnm);
}
}
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