Commit c0c4f03d authored by Aliaksandr Halavatyi's avatar Aliaksandr Halavatyi
Browse files

Modifying the code to match updates in fly-reg

parent 2a5d5fd0
......@@ -15,7 +15,7 @@
<groupId>embl.almf</groupId>
<version>1.0.8-SNAPSHOT</version>
<version>1.0.9-SNAPSHOT</version>
<name>Fly_Embryo_Feedback</name>
<inceptionYear>2017</inceptionYear>
......@@ -100,13 +100,13 @@
<dependency>
<groupId>embl.almf</groupId>
<artifactId>AutoMicTools_</artifactId>
<version>1.1.17-SNAPSHOT</version>
<version>1.1.20-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>de.embl.cba</groupId>
<artifactId>fly-reg</artifactId>
<version>0.1.1</version>
<version>0.1.3-SNAPSHOT</version>
</dependency>
</dependencies>
......@@ -172,7 +172,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
......
......@@ -10,9 +10,10 @@ import automic.online.jobs.Job_Default;
import automic.parameters.ParameterCollection;
import automic.parameters.ParameterType;
import automic.table.TableModel;
import automic.geom.Position3DWithRotation;
import de.embl.cba.flyreg.FlyEmbryoNerveCordRegistration;
import de.embl.cba.flyreg.FlyEmbryoRegistrationSettings;
import de.embl.cba.morphometry.Utils;
import ij.IJ;
import net.imagej.ImageJ;
import ij.ImagePlus;
......@@ -27,10 +28,12 @@ import ij.process.ImageProcessor;
import loci.plugins.BF;
import loci.plugins.in.ImporterOptions;
import net.imagej.ops.OpService;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.type.NativeType;
import net.imglib2.type.numeric.RealType;
public class Job_FocusEmbryoAutoDatasetSplit extends Job_Default{
public static final String KEY_FOCUS_CHANNEL_INDEX="Focus channel index";
......@@ -40,13 +43,10 @@ public class Job_FocusEmbryoAutoDatasetSplit extends Job_Default{
private OpService opService=null;
private static OpService opService=null;
private ImagePlus img=null;
private Double selectedXPosition;
private Double selectedYPosition;
private Double selectedZPosition;
private Double rotation;
Position3DWithRotation selectedPosition;
private Double halfLength;
......@@ -61,17 +61,15 @@ public class Job_FocusEmbryoAutoDatasetSplit extends Job_Default{
@Override
public void initialise(String _fTag,String _colNm, boolean _visOnline){
super.initialise(_fTag, _colNm, _visOnline);
opService=new ImageJ().op();
if(opService==null)
opService=new ImageJ().op();
}
@Override
protected void cleanIterOutput(){
img=null;
selectedXPosition=null;
selectedYPosition=null;
selectedYPosition=null;
rotation=null;
selectedPosition=null;
halfLength=null;
}
......@@ -155,61 +153,60 @@ public class Job_FocusEmbryoAutoDatasetSplit extends Job_Default{
//////code from Tischi
try{
getEllipsoidParameters(imageToProcess,img);
selectedPosition=getEllipsoidParameters(imageToProcess,img);
}catch (Exception _ex) {
return false;
}
////
if (!correctXY) {
selectedPosition.setX(img.getWidth()/2.0);
selectedPosition.setX(img.getHeight()/2.0);
}
halfLength=img.getWidth()/3.0;
if(rotation>90)
rotation=rotation-180;
double angle=selectedPosition.getAngle();
if(angle>90)
selectedPosition.setAngle(angle-180);
return true;
}
void getEllipsoidParameters(ImagePlus _imageProcess, ImagePlus _imageCalibration)throws Exception {
static < T extends RealType< T > & NativeType< T > > Position3DWithRotation getEllipsoidParameters(ImagePlus _imageProcess, ImagePlus _imageCalibration)throws Exception {
final FlyEmbryoRegistrationSettings settings = new FlyEmbryoRegistrationSettings();
settings.onlyComputeEllipsoidParameters = true;
final FlyEmbryoNerveCordRegistration registration = new FlyEmbryoNerveCordRegistration( settings, opService );
final FlyEmbryoNerveCordRegistration<T> registration = new FlyEmbryoNerveCordRegistration<>( settings, opService );
final double[] calibration = Utils.getCalibration( _imageCalibration );
registration.run( _imageProcess,0);
final double[] centre = registration.getElliposidCentreInInputImagePixelUnits();
final double[] angles = registration.getElliposidEulerAnglesInDegrees();
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];
return new Position3DWithRotation(centre[0], centre[1], centre[2], -angles[0]);
}
@Override
protected Overlay createOverlay(){
Overlay o=new Overlay();
if (selectedXPosition!=null) {
Roi pointRoi=new PointRoi(selectedXPosition, selectedYPosition);
pointRoi.setPosition((int)(selectedZPosition+1));
if (selectedPosition!=null) {
double roiX=selectedPosition.getX();
double roiY=selectedPosition.getY();
int roiZ=(int)(selectedPosition.getZ()+1);
Roi pointRoi=new PointRoi(roiX, roiY);
pointRoi.setPosition(roiZ);
o.add(pointRoi);
Double angleRadians=rotation/180*Math.PI;
Roi lineRoi=new Arrow(selectedXPosition, selectedYPosition, selectedXPosition+halfLength*Math.cos(angleRadians), selectedYPosition-halfLength*Math.sin(angleRadians));
Double angleRadians=selectedPosition.getAngle()/180*Math.PI;
Roi lineRoi=new Arrow(roiX, roiY, roiX+halfLength*Math.cos(angleRadians), roiY-halfLength*Math.sin(angleRadians));
lineRoi.setStrokeColor(Color.PINK);
lineRoi.setStrokeWidth(1);
o.add(lineRoi);
......@@ -221,8 +218,8 @@ public class Job_FocusEmbryoAutoDatasetSplit extends Job_Default{
public void visualise(int _xvis, int _yvis){
this.visualiseImg(img, getOverlay(), _xvis, _yvis);
if (selectedZPosition!=null)
img.setPosition((int)(selectedZPosition+1));
if (selectedPosition!=null)
img.setPosition((int)(selectedPosition.getZ()+1));
}
......@@ -230,7 +227,7 @@ public class Job_FocusEmbryoAutoDatasetSplit extends Job_Default{
@Override
public void postProcessSuccess()throws Exception{
ZeissKeys.submitCommandsToMicroscope("trigger2", ""+selectedXPosition,""+selectedYPosition,""+selectedZPosition,""+rotation,"","","","","");
ZeissKeys.submitCommandsToMicroscope("trigger2", ""+selectedPosition.getX(),""+selectedPosition.getY(),""+selectedPosition.getZ(),""+selectedPosition.getAngle(),"","","","","");
int tableRowCounter=(int)this.getSharedValue("Table Row Counter");
......@@ -239,10 +236,10 @@ public class Job_FocusEmbryoAutoDatasetSplit extends Job_Default{
File experimentTableFile=new File(currentTable.getRootPath(),"summary_"+Exper_nm+".txt");
TableModel experimentTable=new TableModel(experimentTableFile);
experimentTable.setNumericValue(selectedXPosition, tableRowCounter, "Correction.X");
experimentTable.setNumericValue(selectedYPosition, tableRowCounter, "Correction.Y");
experimentTable.setNumericValue(selectedZPosition, tableRowCounter, "Focus.Z");
experimentTable.setNumericValue(rotation, tableRowCounter, "Rotation");
experimentTable.setNumericValue(selectedPosition.getX(), tableRowCounter, "Correction.X");
experimentTable.setNumericValue(selectedPosition.getY(), tableRowCounter, "Correction.Y");
experimentTable.setNumericValue(selectedPosition.getZ(), tableRowCounter, "Focus.Z");
experimentTable.setNumericValue(selectedPosition.getAngle(), tableRowCounter, "Rotation");
experimentTable.writeNewFile("summary_"+Exper_nm+".txt", true);
......
......@@ -11,14 +11,12 @@ import automic.parameters.ParameterCollection;
import automic.parameters.ParameterType;
import automic.utils.ArrIndUtils;
import automic.utils.DebugVisualiserSettings;
import automic.utils.FileUtils;
import automic.utils.roi.ParticleFilterer;
import automic.utils.roi.ROIManipulator2D;
import ij.IJ;
import ij.ImageJ;
import ij.ImagePlus;
import ij.gui.Overlay;
import ij.gui.PointRoi;
import ij.gui.Roi;
import ij.plugin.Duplicator;
import ij.plugin.ZProjector;
......
......@@ -6,7 +6,6 @@ import java.io.File;
import de.embl.cba.flyreg.FlyEmbryoNerveCordRegistration;
import de.embl.cba.flyreg.FlyEmbryoRegistrationSettings;
//import de.embl.cba.flyreg.FlyEmbryoSingleChannelRegistration;
import ij.ImagePlus;
import loci.plugins.BF;
......@@ -33,7 +32,7 @@ public class FindEmbryoOrientationTischi {
final FlyEmbryoRegistrationSettings settings = new FlyEmbryoRegistrationSettings();
settings.onlyComputeEllipsoidParameters = true;
final FlyEmbryoNerveCordRegistration registration = new FlyEmbryoNerveCordRegistration( settings, opService );
final FlyEmbryoNerveCordRegistration<T> registration = new FlyEmbryoNerveCordRegistration<>( settings, opService );
registration.run(imagePlus, 0);
......
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