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

saving experimental inofrmation in the table for manual protocol

parent 82b6e7eb
......@@ -82,10 +82,14 @@ public class JobDistributor_ManualSelection3DMultiple_AFocus_Rotation extends Jo
outTbl.addFileColumns("LZ.Image", "IMG");
outTbl.addFileColumns("Focus.Image", "IMG");
outTbl.addFileColumns("Result.Image", "IMG");
outTbl.addValueColumn("Zoom.X", "NUM");
outTbl.addValueColumn("Zoom.Y", "NUM");
outTbl.addValueColumn("Correction.X", "NUM");
outTbl.addValueColumn("Correction.Y", "NUM");
outTbl.addValueColumn("Focus.Z", "NUM");
outTbl.addValueColumn("Rotation", "NUM");
outTbl.addValueColumn("Success", "BOOL");
......
package feedback.fly.embryo.jobs;
import java.awt.Color;
import java.io.File;
import java.util.concurrent.TimeUnit;
import org.scijava.vecmath.Point3d;
import automic.online.microscope.ZeissKeys;
import automic.online.jobs.Job_Default;
import automic.parameters.ParameterCollection;
import automic.parameters.ParameterType;
import automic.table.TableModel;
import automic.utils.FileUtils;
import automic.utils.roi.ROIManipulator2D;
import ij.IJ;
import ij.ImageJ;
import ij.ImagePlus;
import ij.ImageStack;
import ij.gui.Line;
import ij.gui.Overlay;
import ij.gui.PointRoi;
import ij.gui.Roi;
import ij.plugin.Duplicator;
import ij.plugin.frame.RoiManager;
import ij.process.ImageProcessor;
import ij.process.ImageStatistics;
import loci.plugins.BF;
......@@ -32,7 +42,11 @@ public class Job_FocusEmbryoAutoDataset extends Job_Default{
private Double selectedYPosition;
private Integer selectedZPosition;
private Integer zSubmit;
private Roi embyroRoi;
private Double rotation;
private Double halfLength;
private int targetChannel=1;
private int imageOpeningTimeDelay=3000;
private int focusOffset=0;
......@@ -45,6 +59,9 @@ public class Job_FocusEmbryoAutoDataset extends Job_Default{
selectedYPosition=null;
selectedYPosition=null;
zSubmit=null;
embyroRoi=null;
rotation=null;
halfLength=null;
}
@Override
......@@ -55,13 +72,23 @@ public class Job_FocusEmbryoAutoDataset extends Job_Default{
tableRowCounter++;
String Exper_nm=(String)getSharedValue("Experiment Name");// newImgFile.getName();
File experimentTableFile=new File(currentTable.getRootPath(),"summary_"+Exper_nm+".txt");
String rootPath=currentTable.getRootPath();
File experimentTableFile=new File(rootPath,"summary_"+Exper_nm+".txt");
TableModel experimentTable=new TableModel(experimentTableFile);
while(experimentTable.getBooleanValue(tableRowCounter, "Success")==false) {
tableRowCounter++;
}
experimentTable.setFileAbsolutePath(newImgFile, tableRowCounter, imgColumnNm, "IMG");
Point3d lzPoint=((Point3d[])this.getSharedValue("Zoom Points"))[zoomCounter];
Roi lzPointRoi=new PointRoi(lzPoint.x,lzPoint.y);
lzPointRoi.setPosition(0, (int)lzPoint.z, 0);
String saveLzRoiFolder=new File(rootPath,"Selected.Embryo.LZ").getAbsolutePath();
String saveLzRoiBasename=String.format("Embryo_%s_%05d",FileUtils.cutExtension(newImgFile.getName()),zoomCounter);
ROIManipulator2D.saveRoiToFile(saveLzRoiFolder, saveLzRoiBasename, lzPointRoi);
experimentTable.setFileAbsolutePath(saveLzRoiFolder, saveLzRoiBasename, tableRowCounter, "Selected.Embryo.LZ", "ROI");
experimentTable.writeNewFile("summary_"+Exper_nm+".txt", true);
TimeUnit.MILLISECONDS.sleep(imageOpeningTimeDelay);
......@@ -84,8 +111,6 @@ public class Job_FocusEmbryoAutoDataset extends Job_Default{
options.setId(_imageFile.getAbsolutePath());
options.setCBegin(0, targetChannel-1);
options.setCEnd(0, targetChannel-1);
//options.setTBegin(0, 0);
//options.setTEnd(0, 0);
return BF.openImagePlus(options)[0];
}
......@@ -94,8 +119,6 @@ public class Job_FocusEmbryoAutoDataset extends Job_Default{
//ImageWindow.setNextLocation(initialLocationX,initialLocationY);
//img=new Duplicator().run(img, 3, 4, 1, img.getNSlices(), 1, 1);
this.showDebug(img, "Original Image", false);
......@@ -104,20 +127,39 @@ public class Job_FocusEmbryoAutoDataset extends Job_Default{
selectedZPosition=getFocusPosition(img);
this.showDebug(img, "Original Image", false);
if (selectedZPosition==null) return false;
selectedZPosition+=focusOffset;
//correct position
ImagePlus selectedSlice=new Duplicator().run(img, targetChannel, targetChannel, selectedZPosition, selectedZPosition, 1, 1);
ImageStatistics sliceStatistics=selectedSlice.getStatistics(ImageStatistics.CENTER_OF_MASS);
ImagePlus selectedSlice=new Duplicator().run(img, 1, 1, selectedZPosition, selectedZPosition, 1, 1);
this.showDebug(selectedSlice, "Selected Slice Image", true);
RoiManager rManager=ROIManipulator2D.getEmptyRm();
IJ.setAutoThreshold(selectedSlice, "Huang dark");
IJ.run(selectedSlice, "Analyze Particles...", "include add");
Roi[] candidateRois=rManager.getRoisAsArray();
rManager.runCommand("Reset");
if (ROIManipulator2D.isEmptyRoiArr(candidateRois))
return false;
embyroRoi=ROIManipulator2D.selBiggestRoi(selectedSlice, candidateRois);
selectedSlice.setRoi(embyroRoi);
ImageStatistics sliceStatistics=selectedSlice.getStatistics(/*ImageStatistics.CENTER_OF_MASS|*/ImageStatistics.ELLIPSE);
rotation=sliceStatistics.angle;
halfLength=sliceStatistics.major/2.0;
if(rotation>90)
rotation=rotation-180;
selectedXPosition=embyroRoi.getContourCentroid()[0];//sliceStatistics.xCenterOfMass;
selectedYPosition=embyroRoi.getContourCentroid()[1];//sliceStatistics.yCenterOfMass;
//invert zPosition if required
zSubmit=selectedZPosition-1;//(invert_Z)?(nSlices-selectedZPosition):(selectedZPosition-1);
selectedXPosition=sliceStatistics.xCenterOfMass;
selectedYPosition=sliceStatistics.yCenterOfMass;
return true;
......@@ -172,7 +214,30 @@ public class Job_FocusEmbryoAutoDataset extends Job_Default{
@Override
public void postProcessSuccess()throws Exception{
ZeissKeys.submitCommandsToMicroscope("trigger2", ""+selectedXPosition,""+selectedYPosition,""+zSubmit,"","","","","");
ZeissKeys.submitCommandsToMicroscope("trigger2", ""+selectedXPosition,""+selectedYPosition,""+zSubmit,""+rotation,"","","","","");
int tableRowCounter=(int)this.getSharedValue("Table Row Counter");
String Exper_nm=(String)getSharedValue("Experiment Name");// newImgFile.getName();
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.writeNewFile("summary_"+Exper_nm+".txt", true);
embyroRoi.setStrokeColor(Color.ORANGE);
Roi pointRoi=new PointRoi(selectedXPosition, selectedYPosition);
pointRoi.setPosition(0, selectedZPosition, 0);
Double angleRadians=rotation/180*Math.PI;
Roi lineRoi=new Line(selectedXPosition, selectedYPosition, selectedXPosition+halfLength*Math.cos(angleRadians), selectedYPosition*Math.sin(angleRadians));
lineRoi.setStrokeColor(Color.PINK);
saveRoisForImage(newImgFile,new Roi[] {embyroRoi,pointRoi});
// Roi saveRoi=null;
// if(selectedXPosition!=null && selectedYPosition!=null){
......@@ -182,18 +247,22 @@ public class Job_FocusEmbryoAutoDataset extends Job_Default{
// }
//
// saveRoiForImage(newImgFile,saveRoi);
//
// //currentTable.setNumericValue(selectedXPosition, curDInd, "Pos.X");
// //currentTable.setNumericValue(selectedYPosition, curDInd, "Pos.Y");
// currentTable.setNumericValue(selectedZPosition, curDInd, "Focus.Z");
// //this.recordSummaryDataset(true);
}
@Override
public void postProcessFail()throws Exception{
ZeissKeys.submitCommandsToMicroscope("nothing",null,null,null,null,null,null,null, "Suitable object is not found");
ZeissKeys.submitCommandsToMicroscope("nothing",null,null,null,null,null,null,null,null, "Suitable object is not found");
int tableRowCounter=(int)this.getSharedValue("Table Row Counter");
String Exper_nm=(String)getSharedValue("Experiment Name");// newImgFile.getName();
File experimentTableFile=new File(currentTable.getRootPath(),"summary_"+Exper_nm+".txt");
TableModel experimentTable=new TableModel(experimentTableFile);
experimentTable.setBooleanValue(false, tableRowCounter, "Success");
experimentTable.writeNewFile("summary_"+Exper_nm+".txt", true);
}
......
......@@ -143,7 +143,8 @@ public class Job_SelectMultipleEmbryosManual3D extends Job_Default{
saveRoi=new PointRoi(selectedPoints[i].x,selectedPoints[i].y);
else
saveRoi=saveRoi.addPoint(selectedPoints[i].x,selectedPoints[i].y);
currentTable.setNumericValue(selectedPoints[i].x, 0, "Zoom.X");
currentTable.setNumericValue(selectedPoints[i].y, 0, "Zoom.Y");
this.recordSummaryDataset(true);
}
......@@ -153,7 +154,7 @@ public class Job_SelectMultipleEmbryosManual3D extends Job_Default{
saveRoiForImage(newImgFile,saveRoi);
//this.setSharedValue("Zoom Points", selectedPoints);
this.setSharedValue("Zoom Points", selectedPoints);
this.setSharedValue("Zoom Counter", -1);
this.setSharedValue("Table Row Counter", -1);
}
......
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