Commit 52ff7b61 authored by Aliaksandr Halavatyi's avatar Aliaksandr Halavatyi

new protocol for manual selection ofter low zoom imaging of many wells

parent bef95d25
Pipeline #6881 failed with stages
in 53 seconds
package feedback.fly.embryo.jobdistributors;
import ij.gui.GenericDialog;
import ij.gui.WaitForUserDialog;
import ij.plugin.PlugIn;
import automic.online.jobdistributors.JobDistributor_Abstract;
import automic.online.jobs.common.Job_AutofocusInitOffset;
import automic.parameters.ParameterCollection;
import automic.parameters.gui.ParameterGuiManager;
import automic.table.TableModel;
import automic.table.TableProcessor;
import feedback.fly.embryo.jobs.Job_FocusEmbryoAutoDataset;
import feedback.fly.embryo.jobs.Job_RecordFinishDataset;
import feedback.fly.embryo.jobs.Job_SelectMultipleEmbryosManual3D;
public class JobDistributor_ManualSelection3DMultiple_AFocus_Rotation extends JobDistributor_Abstract implements PlugIn {
@Override
protected void fillJobList(){
Job_AutofocusInitOffset job1=new Job_AutofocusInitOffset();
ParameterCollection job1Parameters=job1.createJobParameters();
job1Parameters.setUndefinedValuesFromDefaults();
ParameterGuiManager pgManager1=new ParameterGuiManager(job1Parameters);
try{
pgManager1.refineParametersViaDialog("Coverslip focusing");
}catch(Exception _ex){
new WaitForUserDialog("error in parameter values");
}
job1.parseInputParameterValues(pgManager1.getParameterCollection());
super.addImageJob(job1, "DE_1_", "AFocus", true);
Job_SelectMultipleEmbryosManual3D job2=new Job_SelectMultipleEmbryosManual3D();
ParameterCollection job2Parameters=job2.createJobParameters();
job2Parameters.setUndefinedValuesFromDefaults();
ParameterGuiManager pgManager2=new ParameterGuiManager(job2Parameters);
try{
pgManager2.refineParametersViaDialog("Parameters for manual embryo selection");
}catch(Exception _ex){
new WaitForUserDialog("error in parameter values");
}
job2.parseInputParameterValues(pgManager2.getParameterCollection());
super.addImageJob(job2, "DE_2_", "LZ.Image", true);
Job_FocusEmbryoAutoDataset job3=new Job_FocusEmbryoAutoDataset();
ParameterCollection job3Parameters=job3.createJobParameters();
job3Parameters.setUndefinedValuesFromDefaults();
ParameterGuiManager pgManager3=new ParameterGuiManager(job3Parameters);
try{
pgManager3.refineParametersViaDialog("Parameters for embryo focusing");
}catch(Exception _ex){
new WaitForUserDialog("error in parameter values");
}
job3.parseInputParameterValues(pgManager3.getParameterCollection());
super.addImageJob(job3, "TR1_1_", "Focus.Image", true);
super.addImageJob(Job_RecordFinishDataset.class, "TR2_1_", "Result.Image", true);
}
@Override
protected TableModel constructTabModel(String _rpth){
TableModel outTbl=new TableModel(_rpth);
outTbl.addColumn("Date.Time");
outTbl.addFileColumns("AFocus", "IMG");
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("Focus.Z", "NUM");
outTbl.addValueColumn("Success", "BOOL");
outTbl.addRow(new Object[outTbl.getColumnCount()]);
return outTbl;
}
@Override
protected TableProcessor configureTableProcessor(TableModel _tModel)throws Exception{
TableProcessor tProcessor=new TableProcessor(_tModel);
tProcessor.addFileColumns("Selected.Embryo.LZ", "ROI");
return tProcessor;
}
@Override
protected void putProtocolPreferencesToDialog(GenericDialog _dialog){}
@Override
protected void getProtocolPreferencesFromDialog(GenericDialog _dialog){}
@Override
protected boolean showDialogInDebugRun(){
return false;
}
@Override
protected void setDebugConfiguration(){
final String searchPath="C:/tempDat/AutoMic_test";
this.setGeneralOptions(searchPath, true, false);
this.fileExtension="lsm";
}
}
package feedback.fly.embryo.jobs;
import java.awt.Color;
import java.awt.geom.Point2D;
import java.io.File;
import java.util.concurrent.TimeUnit;
import automic.online.microscope.ZeissKeys;
import automic.online.jobs.Job_Default;
import automic.parameters.ParameterCollection;
import automic.parameters.ParameterType;
import automic.utils.FileUtils;
import ij.ImageJ;
import ij.ImagePlus;
import ij.ImageStack;
import ij.gui.Overlay;
import ij.gui.PointRoi;
import ij.gui.Roi;
import ij.process.ImageProcessor;
import ij.process.ImageStatistics;
import loci.plugins.BF;
import loci.plugins.in.ImporterOptions;
public class Job_FocusEmbryoAutoDataset 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";
//private static final Roi nullRoi=null;
private ImagePlus img=null;
private Integer selectedXPosition;
private Integer selectedYPosition;
private Integer selectedZPosition;
private Integer zSubmit;
private int targetChannel=1;
private int imageOpeningTimeDelay=3000;
private int focusOffset=0;
@Override
protected void cleanIterOutput(){
img=null;
selectedXPosition=null;
selectedYPosition=null;
selectedYPosition=null;
zSubmit=null;
}
@Override
protected void preProcessOnline()throws Exception{
//super.clearSharedData();
//currentTable.cleanRecord(curDInd);
currentTable.setFileAbsolutePath(newImgFile, curDInd, imgColumnNm, "IMG");
Integer zoomIndex=(Integer)getSharedValue("Zoom Counter");
zoomIndex++;
setSharedValue("Zoom Counter",zoomIndex);
Point2D.Double[] zoompts=(Point2D.Double[])this.getSharedValue("Zoom Points");
currentTable.setNumericValue(zoompts[zoomIndex].getX(), curDInd, "Zoom.X");
currentTable.setNumericValue(zoompts[zoomIndex].getY(), curDInd, "Zoom.Y");
Roi selectedEmbryoLZ=((Roi[])this.getSharedValue("Selected Embryo Rois"))[zoomIndex];
selectedEmbryoLZ.setStrokeColor(Color.green);
currentTableProcessor.saveRoiToTable(curDInd, selectedEmbryoLZ, "Selected.Embryo.LZ", String.format("Embryo_%s_%05d",FileUtils.cutExtension(newImgFile.getName()),zoomIndex));
//String Exper_nm=newImgFile.getName();
//Exper_nm=Exper_nm.substring(0, Exper_nm.indexOf(fileTag));
//this.setSharedValue("Experiment Name", Exper_nm);
//img=ImageOpenerWithBioformats.openImage(newImgFile);
TimeUnit.MILLISECONDS.sleep(imageOpeningTimeDelay);
img=openSelectedSlices(newImgFile);
}
@Override
protected void preProcessOffline()throws Exception{
//img=ImageOpenerWithBioformats.openImage(currentTable.getFile(curDInd, imgColumnNm, "IMG"));
img=openSelectedSlices(currentTable.getFile(curDInd, imgColumnNm, "IMG"));
}
private ImagePlus openSelectedSlices(File _imageFile)throws Exception{
ImporterOptions options = new ImporterOptions();
options.setAutoscale(true);
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];
}
@Override
protected boolean runProcessing()throws Exception{
//ImageWindow.setNextLocation(initialLocationX,initialLocationY);
//img=new Duplicator().run(img, 3, 4, 1, img.getNSlices(), 1, 1);
//new WaitForUserDialog ("Select Shift Point").show();
selectedZPosition=getFocusPosition(img);
if (selectedZPosition==null) return false;
selectedZPosition+=focusOffset;
//invert zPosition if required
zSubmit=selectedZPosition-1;//(invert_Z)?(nSlices-selectedZPosition):(selectedZPosition-1);
selectedXPosition=img.getWidth()/2-1;
selectedYPosition=img.getHeight()/2-1;
return true;
}
private Integer getFocusPosition(ImagePlus _image){
int nSlices=_image.getNSlices();
ImageStack imStack=_image.getStack();
double[] focusValues=new double[nSlices];
double maxValue=0;
int maxSliceIndex=0;
ImageProcessor currentProcessor;
ImageStatistics currentStatistics;
double currentValue;
for (int sliceIndex=1; sliceIndex<=nSlices; sliceIndex++){
currentProcessor=imStack.getProcessor(sliceIndex);
currentStatistics=currentProcessor.getStatistics();
focusValues[sliceIndex-1]=currentValue=currentStatistics.stdDev/currentStatistics.mean;//currentStatistics.mean;
if(currentValue>maxValue){
maxValue=currentValue;
maxSliceIndex=sliceIndex;
}
}
return maxSliceIndex;
}
@Override
protected Overlay createOverlay(){
return new Overlay();
}
@Override
public void visualise(int _xvis, int _yvis){
//img.setC(1);
//IJ.run(img, "Cyan", "");
//IJ.run(img, "Enhance Contrast", "saturated=0.35");
//img.setC(2);
//IJ.run(img, "Magenta", "");
//IJ.run(img, "Enhance Contrast", "saturated=0.35");
//img.setDisplayMode(IJ.COMPOSITE);
this.visualiseImg(img, getOverlay(), _xvis, _yvis);
if (selectedZPosition!=null)
img.setPosition(selectedZPosition);
}
@Override
public void postProcessSuccess()throws Exception{
ZeissKeys.submitCommandsToMicroscope("trigger2", ""+selectedXPosition,""+selectedYPosition,""+zSubmit,"","","","","");
Roi saveRoi=null;
if(selectedXPosition!=null && selectedYPosition!=null){
saveRoi=new PointRoi(selectedXPosition, selectedYPosition);
//saveRoi=new OvalRoi(selectedXPosition-3, selectedYPosition-3, 6, 6);
saveRoi.setPosition(0,selectedZPosition,0);
}
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 ParameterCollection createJobParameters(){
ParameterCollection jobCollection=new ParameterCollection();
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);
return jobCollection;
}
@Override
public void parseInputParameterValues(ParameterCollection _jobParameterCollection){
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);
}
/**
* offline debugging
* @param args unsused
*/
public static void main(String[] args)throws Exception{
// start ImageJ
new ImageJ();
String tblPth="C:/tempDat/AutoFRAP_test";
String tblFnm="summary_TEST14_.txt";
Job_FocusEmbryoAutoDataset testJob=new Job_FocusEmbryoAutoDataset();
testJob.initialise(null, "Focus.Image", false);
testJob.testJobMicTable(0, tblPth, tblFnm);
}
}
package feedback.fly.embryo.jobs;
import java.io.File;
import java.util.Date;
import automic.online.jobs.Job_Default;
import automic.table.TableModel;
import automic.table.TableSettings;
public class Job_RecordFinishDataset extends Job_Default{
@Override
protected void preProcessOnline()throws Exception{
int rowIndex=(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.setStringValue(TableSettings.dateTimeFormat.format(new Date())/*new Date().toString()*/, rowIndex, "Date.Time");
experimentTable.setFileAbsolutePath(newImgFile, rowIndex, imgColumnNm, "IMG");
//outTbl.setStringValue(new Date().toString(), "Date.Time", 0);
experimentTable.writeNewFile("summary_"+Exper_nm+".txt", true);
}
@Override
public void postProcessSuccess()throws Exception{}
}
package feedback.fly.embryo.jobs;
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.utils.roi.ROIManipulator2D;
import ij.IJ;
import ij.ImageJ;
import ij.ImagePlus;
import ij.gui.ImageWindow;
import ij.gui.Overlay;
import ij.gui.PointRoi;
import ij.gui.Roi;
import ij.gui.WaitForUserDialog;
import ij.plugin.frame.RoiManager;
import loci.plugins.BF;
import loci.plugins.in.ImporterOptions;
public class Job_SelectMultipleEmbryosManual3D extends Job_Default{
private String KEY_SCREEN_POSITION_MANUAL_SELECTION_X="Screen position X";
private String KEY_SCREEN_POSITION_MANUAL_SELECTION_Y="Screen position Y";
private int screenPositionX=100;
private int screenPositionY=100;
private ImagePlus img=null;
private Roi[] selectedPointsRois;
private Integer numberOfSelectedPoints;
private Point3d[] selectedPoints;
@Override
protected void cleanIterOutput(){
img=null;
selectedPointsRois=null;
numberOfSelectedPoints=null;
selectedPoints=null;
}
@Override
protected void preProcessOnline()throws Exception{
super.clearSharedData();
//currentTable.cleanRecord(curDInd);
currentTable.setFileAbsolutePath(newImgFile, curDInd, imgColumnNm, "IMG");
String Exper_nm=newImgFile.getName();
Exper_nm=Exper_nm.substring(0, Exper_nm.indexOf(fileTag));
this.setSharedValue("Experiment Name", Exper_nm);
TimeUnit.MILLISECONDS.sleep(2000);
img=openSelectedSlices(newImgFile);
}
@Override
protected void preProcessOffline()throws Exception{
img=openSelectedSlices(currentTable.getFile(curDInd, imgColumnNm, "IMG"));
}
private ImagePlus openSelectedSlices(File _imageFile)throws Exception{
ImporterOptions options = new ImporterOptions();
options.setAutoscale(true);
options.setId(_imageFile.getAbsolutePath());
return BF.openImagePlus(options)[0];
}
@Override
protected boolean runProcessing()throws Exception{
img.setDisplayMode(IJ.COMPOSITE);
ImageWindow.setNextLocation(screenPositionX, screenPositionY);
RoiManager rm=ROIManipulator2D.getEmptyRm();
rm.runCommand("Associate", "true");
img.show();
IJ.setTool("point");
new WaitForUserDialog ("Select Embryo Positions","Add Embryo Positions as Single Points to RoiManager").show();
selectedPointsRois=rm.getRoisAsArray();
rm.runCommand("Reset");
if (selectedPointsRois==null) return false;
numberOfSelectedPoints=selectedPointsRois.length;
if (numberOfSelectedPoints<1) return false;
//if(!(selectedPointsRoi instanceof PointRoi)) return false;
double x,y,z;
selectedPoints=new Point3d[numberOfSelectedPoints];
for (int i=0;i<numberOfSelectedPoints;i++){
x=selectedPointsRois[i].getXBase();
y=selectedPointsRois[i].getYBase();
z=selectedPointsRois[i].getZPosition();
selectedPoints[i]=new Point3d(x, y,z);
}
img.hide();
return true;
}
@Override
protected Overlay createOverlay(){
return new Overlay();
}
@Override
public void visualise(int _xvis, int _yvis){
//this.visualiseImg(img, getOverlay(), _xvis, _yvis);
}
@Override
public void postProcessSuccess()throws Exception{
PointRoi saveRoi=null;
//form comma-separated strings with coordinates
String xstr="", ystr="",zstr="";
// submit 3d points in future
for (int i=0;i<numberOfSelectedPoints;i++){
if (i>0){
xstr+=";";
ystr+=";";
zstr+=";";
}
xstr+=selectedPoints[i].x;
ystr+=selectedPoints[i].y;
zstr+=selectedPoints[i].z-1;
if (i==0)
saveRoi=new PointRoi(selectedPoints[i].x,selectedPoints[i].y);
else
saveRoi=saveRoi.addPoint(selectedPoints[i].x,selectedPoints[i].y);
this.recordSummaryDataset(true);
}
ZeissKeys.submitCommandsToMicroscope("trigger1", xstr,ystr,zstr,"","","","","","");
saveRoiForImage(newImgFile,saveRoi);
//this.setSharedValue("Zoom Points", selectedPoints);
this.setSharedValue("Zoom Counter", -1);
this.setSharedValue("Table Row Counter", -1);
}
public ParameterCollection createJobParameters(){
ParameterCollection jobCollection=new ParameterCollection();
jobCollection.addParameter(KEY_SCREEN_POSITION_MANUAL_SELECTION_X, null, screenPositionX, ParameterType.INT_PARAMETER);
jobCollection.addParameter(KEY_SCREEN_POSITION_MANUAL_SELECTION_Y, null, screenPositionY, ParameterType.INT_PARAMETER);
return jobCollection;
}
@Override
public void parseInputParameterValues(ParameterCollection _jobParameterCollection){
this.screenPositionX=(Integer)_jobParameterCollection.getParameterValue(KEY_SCREEN_POSITION_MANUAL_SELECTION_X);
this.screenPositionY=(Integer)_jobParameterCollection.getParameterValue(KEY_SCREEN_POSITION_MANUAL_SELECTION_Y);
}
/**
* offline debugging
* @param args unsused
*/
public static void main(String[] args)throws Exception{
// start ImageJ
new ImageJ();
String tblPth="C:\\tempDat\\Crocker-lab\\fly feedback files 20180207";
String tblFnm="summary_TEST14_corrected_fake.txt";
Job_SelectMultipleEmbryosManual3D testJob=new Job_SelectMultipleEmbryosManual3D();
testJob.initialise(null, "LZ.Image", false);
testJob.testJobMicTable(3, tblPth, tblFnm);
}
}
......@@ -10,5 +10,6 @@ Plugins>Auto Mic Tools>Fly Embryo Screen, "Manual selection of multiple embryos"
Plugins>Auto Mic Tools>Fly Embryo Screen, "Automated selection of multiple embryos", feedback.fly.embryo.jobdistributors.JobDistributor_AutoSelectionMultiple
Plugins>Auto Mic Tools>Fly Embryo Screen, "Automated selection of multiple embryos with reflection autofocus", feedback.fly.embryo.jobdistributors.JobDistributor_AutoSelectionMultiple_AFocus
Plugins>Auto Mic Tools>Fly Embryo Screen, "Automated selection of multiple embryos with reflection autofocus and embryo rotation", feedback.fly.embryo.jobdistributors.JobDistributor_AutoSelectionMultiple_AFocus_Rotation
Plugins>Auto Mic Tools>Fly Embryo Screen, "Manual selection of multiple embryos with reflection autofocus and embryo rotation", feedback.fly.embryo.jobdistributors.JobDistributor_ManualSelection3DMultiple_AFocus_Rotation
Plugins>Auto Mic Tools>Fly Embryo Screen,"-"
Plugins>Auto Mic Tools>Fly Embryo Screen, "Test segmentation parameters", feedback.fly.embryo.jobtests.Embryo_Selection_Tester
package jobdistributors.run.debug;
import feedback.fly.embryo.jobdistributors.JobDistributor_ManualSelection3DMultiple_AFocus_Rotation;
import ij.IJ;
import ij.ImageJ;