Commit dba08293 authored by Aliaksandr Halavatyi's avatar Aliaksandr Halavatyi

removing obsolete online Jobs

parent 75abc10c
package feedback.fly.embryo.jobs;
import java.awt.Color;
//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.utils.imagefiles.ImageOpenerWithBioformats;
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 ij.gui.WaitForUserDialog;
//import ij.plugin.Duplicator;
import loci.plugins.BF;
import loci.plugins.in.ImporterOptions;
public class Job_FocusEmbryoAuto 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)";
//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;
@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;
//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.mean;//currentStatistics.stdDev/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);
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);
}
/**
* 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_FocusEmbryoAuto testJob=new Job_FocusEmbryoAuto();
testJob.initialise(null, "Focus.Image", false);
testJob.testJobMicTable(0, tblPth, tblFnm);
}
}
package feedback.fly.embryo.jobs;
import java.awt.Color;
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.table.TableModel;
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.measure.Calibration;
import ij.plugin.Duplicator;
import ij.plugin.frame.RoiManager;
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 Double selectedXPosition;
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;
@Override
protected void cleanIterOutput(){
img=null;
selectedXPosition=null;
selectedYPosition=null;
selectedYPosition=null;
zSubmit=null;
embyroRoi=null;
rotation=null;
halfLength=null;
}
@Override
protected void preProcessOnline()throws Exception{
int zoomCounter=(int)this.getSharedValue("Zoom Counter");
int tableRowCounter=(int)this.getSharedValue("Table Row Counter");
zoomCounter++;
tableRowCounter++;
String Exper_nm=(String)getSharedValue("Experiment Name");// newImgFile.getName();
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");
experimentTable.writeNewFile("summary_"+Exper_nm+".txt", true);
TimeUnit.MILLISECONDS.sleep(imageOpeningTimeDelay);
img=openSelectedSlices(newImgFile);
this.setSharedValue("Zoom Counter", zoomCounter);
this.setSharedValue("Table Row Counter", tableRowCounter);
}
@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);
return BF.openImagePlus(options)[0];
}
@Override
protected boolean runProcessing()throws Exception{
this.showDebug(img, "Original Image", false);
//new WaitForUserDialog ("Select Shift Point").show();
selectedZPosition=getFocusPosition(img);
this.showDebug(img, "Original Image", false);
if (selectedZPosition==null) return false;
selectedZPosition+=focusOffset;
//correct position
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);
selectedSlice.setCalibration(new Calibration());
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);
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.mean;//currentStatistics.stdDev/currentStatistics.mean;//
if(currentValue>maxValue){
maxValue=currentValue;
maxSliceIndex=sliceIndex;
}
}
return maxSliceIndex;
}
@Override
protected Overlay createOverlay(){
Overlay o=new Overlay();
if (embyroRoi==null)
return o;
embyroRoi.setStrokeColor(Color.ORANGE);
o.add(embyroRoi);
Roi pointRoi=new PointRoi(selectedXPosition, selectedYPosition);
pointRoi.setPosition(selectedZPosition);
o.add(pointRoi);
Double angleRadians=rotation/180*Math.PI;
Roi lineRoi=new Line(selectedXPosition, selectedYPosition, selectedXPosition+halfLength*Math.cos(angleRadians), selectedYPosition-halfLength*Math.sin(angleRadians));
lineRoi.setStrokeColor(Color.PINK);
o.add(lineRoi);
return o;
}
@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,""+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);
saveRoisForImage(newImgFile,getOverlay().toArray());
}
@Override
public void postProcessFail()throws Exception{
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);
}
protected void postProcessOffline(){
try {
this.showDebug(img, "Image with overlay", true,getOverlay());
}catch (Exception ex){
IJ.error("Error during offline visualisation");
}
}
@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\\Crocker-lab\\Test_protocol_update_20181109";
String tblFnm="summary_test8_m.txt";
Job_FocusEmbryoAutoDataset testJob=new Job_FocusEmbryoAutoDataset();
testJob.initialise(null, "Focus.Image", false);
testJob.testJobMicTable(1, tblPth, tblFnm);
}
}
package feedback.fly.embryo.jobs;
public class Job_FocusEmbryoAutoRotation extends Job_FocusEmbryoAuto {
@Override
protected void preProcessOnline()throws Exception{
super.preProcessOnline();
Integer zoomIndex=(Integer)getSharedValue("Zoom Counter");
Double[] rotations=(Double[])this.getSharedValue("Rotations");
currentTable.setNumericValue(rotations[zoomIndex], curDInd, "Rotation");
}
}
package feedback.fly.embryo.jobs;
import java.awt.Color;
import java.awt.Polygon;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
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.utils.imagefiles.ImageOpenerWithBioformats;
import automic.parameters.ParameterCollection;
//import automic.parameters.ParameterType;
import ij.IJ;
import ij.ImageJ;
import ij.ImagePlus;
import ij.gui.ImageCanvas;
//import ij.gui.ImageWindow;
//import ij.gui.OvalRoi;
import ij.gui.Overlay;
import ij.gui.PointRoi;
import ij.gui.Roi;
import ij.gui.Toolbar;
//import ij.gui.WaitForUserDialog;
//import ij.plugin.Duplicator;
import loci.plugins.BF;
import loci.plugins.in.ImporterOptions;
public class Job_SelectEmbryoManual extends Job_Default{
//public static final String KEY_INVERT_Z="Invert Z position (piezo)";
//public static final String KEY_ZOOM_ITERATIONS="Zoom iterations";