Commit f19a4557 authored by Andrey Filippov's avatar Andrey Filippov
Browse files

Adding support for a dual-quad camera for CNN ground truth

parent 6db01aca
Loading
Loading
Loading
Loading
+41 −1
Original line number Original line Diff line number Diff line
@@ -521,6 +521,7 @@ G= Y +Pr*(- 2*Kr*(1-Kr))/Kg + Pb*(-2*Kb*(1-Kb))/Kg




    public static class ColorGainsParameters {
    public static class ColorGainsParameters {
    	public static final String AUX_PREFIX = "AUX-";
    	public double[] gain={
    	public double[] gain={
    			1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,
    			1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,
    			1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,
    			1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,
@@ -548,7 +549,7 @@ G= Y +Pr*(- 2*Kr*(1-Kr))/Kg + Pb*(-2*Kb*(1-Kb))/Kg
    			properties.setProperty(prefix+"balanceBlue_"+i,this.balanceBlue[i]+"");
    			properties.setProperty(prefix+"balanceBlue_"+i,this.balanceBlue[i]+"");
    		}
    		}
    	}
    	}
    	public void getProperties(String prefix,Properties properties){
    	public boolean getProperties(String prefix,Properties properties){
    		if (properties.getProperty(prefix+"channels")!=null) {
    		if (properties.getProperty(prefix+"channels")!=null) {
        		int numChannels=Integer.parseInt(properties.getProperty(prefix+"channels"));
        		int numChannels=Integer.parseInt(properties.getProperty(prefix+"channels"));
        		this.gain=       new double[numChannels];
        		this.gain=       new double[numChannels];
@@ -559,7 +560,9 @@ G= Y +Pr*(- 2*Kr*(1-Kr))/Kg + Pb*(-2*Kb*(1-Kb))/Kg
        			this.balanceRed[i]= Double.parseDouble(properties.getProperty(prefix+"balanceRed_"+i));
        			this.balanceRed[i]= Double.parseDouble(properties.getProperty(prefix+"balanceRed_"+i));
        			this.balanceBlue[i]=Double.parseDouble(properties.getProperty(prefix+"balanceBlue_"+i));
        			this.balanceBlue[i]=Double.parseDouble(properties.getProperty(prefix+"balanceBlue_"+i));
        		}
        		}
        		return true;
    		}
    		}
    		return false;
    	}
    	}


    	public void modifyNumChannels(int numChannels){
    	public void modifyNumChannels(int numChannels){
@@ -599,6 +602,43 @@ G= Y +Pr*(- 2*Kr*(1-Kr))/Kg + Pb*(-2*Kb*(1-Kb))/Kg
    		return true;
    		return true;
    	}
    	}


    	public boolean showDialog(ColorGainsParameters aux) {

    		GenericJTabbedDialog gd = new GenericJTabbedDialog("Individual channels colors/gains", 600,1000);
    		if (aux != null) gd.addTab("Main camera");
    		for (int i =0; i<this.gain.length;i++){
    			gd.addMessage(String.format("=== CHANNEL %02d ===",i));
    			gd.addNumericField(String.format("%02d: Gain (brightness)",i), this.gain[i], 3);
    			gd.addNumericField(String.format("%02d: Balance Red/Green",i), this.balanceRed[i], 3);
    			gd.addNumericField(String.format("%02d: Balance Blue/Green",i), this.balanceBlue[i], 3);
    		}
    		if (aux != null) {
    			gd.addTab("Auxiliary camera");
        		for (int i =0; i<this.gain.length;i++){
        			gd.addMessage(String.format("=== CHANNEL %02d ===",i));
        			gd.addNumericField(String.format("%02d: Gain (brightness)",i), aux.gain[i], 3);
        			gd.addNumericField(String.format("%02d: Balance Red/Green",i), aux.balanceRed[i], 3);
        			gd.addNumericField(String.format("%02d: Balance Blue/Green",i), aux.balanceBlue[i], 3);
        		}

    		}
    		gd.showDialog();
    		if (gd.wasCanceled()) return false;
    		for (int i =0; i<this.gain.length;i++){
    			this.gain[i]=       gd.getNextNumber();
    			this.balanceRed[i]= gd.getNextNumber();
    			this.balanceBlue[i]=gd.getNextNumber();
    		}
       		if (aux != null) {
        		for (int i =0; i<this.gain.length;i++){
        			aux.gain[i]=       gd.getNextNumber();
        			aux.balanceRed[i]= gd.getNextNumber();
        			aux.balanceBlue[i]=gd.getNextNumber();
        		}
       		}
    		return true;
    	}



    }
    }


+286 −286

File changed.

Preview size limit exceeded, changes collapsed.

+197 −160
Original line number Original line Diff line number Diff line
@@ -25,6 +25,11 @@
**
**
*/
*/


import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;

import javax.swing.SwingUtilities;

import ij.CompositeImage;
import ij.CompositeImage;
import ij.IJ;
import ij.IJ;
import ij.ImagePlus;
import ij.ImagePlus;
@@ -35,12 +40,6 @@ import ij.io.FileSaver;
import ij.process.ColorProcessor;
import ij.process.ColorProcessor;
import ij.process.FloatProcessor;
import ij.process.FloatProcessor;
import ij.process.ImageProcessor;
import ij.process.ImageProcessor;

import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;

import javax.swing.SwingUtilities;

import loci.common.services.DependencyException;
import loci.common.services.DependencyException;
import loci.common.services.ServiceException;
import loci.common.services.ServiceException;
import loci.formats.FormatException;
import loci.formats.FormatException;
@@ -84,10 +83,39 @@ public class EyesisCorrections {
	}
	}


	public int getNumChannels(){return (this.usedChannels!=null)?this.usedChannels.length:0;}
	public int getNumChannels(){return (this.usedChannels!=null)?this.usedChannels.length:0;}


	// TODO: preserve some data when re-running with new source files
	// TODO: preserve some data when re-running with new source files
	// FIXME: Make forgiving alien files
	public void initSensorFiles(int debugLevel){
	public void initSensorFiles(int debugLevel){
		initSensorFiles(debugLevel, false);
	}
	public void initSensorFiles(int debugLevel, boolean missing_ok){
		this.sharpKernelPaths=null;
		this.sharpKernelPaths=null;
		this.smoothKernelPaths=null;
		this.smoothKernelPaths=null;
		String [] sensorPaths=correctionsParameters.selectSensorFiles(this.debugLevel);
		this.pixelMapping=new PixelMapping(sensorPaths,debugLevel);
		this.usedChannels= usedChannels(correctionsParameters.getSourcePaths(),missing_ok);
		// TODO: Combine with additional channel map to be able to select single image (of all 3)
		if (correctionsParameters.removeUnusedSensorData){
			for (int nChn=0;nChn< this.usedChannels.length; nChn++) if (!this.usedChannels[nChn]) this.pixelMapping.removeChannel(nChn);
		}
		int numUsedChannels=0;
		for (int nChn=0;nChn< this.usedChannels.length; nChn++) if (this.usedChannels[nChn]) numUsedChannels++;
		if (this.debugLevel>0) {
			String sChannels="";
			for (int nChn=0;nChn< this.usedChannels.length; nChn++) if (this.usedChannels[nChn]) sChannels+=" "+nChn;
			System.out.println ("Number of used channels: "+numUsedChannels+" ("+sChannels+" )");
		}
		createChannelVignetting();
		if ((this.debugLevel>101) && (correctionsParameters.sourcePaths!=null) && (correctionsParameters.sourcePaths.length>0)) {
			testFF(correctionsParameters.sourcePaths[0]);
		}
	}

	public void initSensorFilesAux(int debugLevel){
//		this.sharpKernelPaths=null;
//		this.smoothKernelPaths=null;
		String [] sensorPaths=correctionsParameters.selectSensorFiles(this.debugLevel);
		String [] sensorPaths=correctionsParameters.selectSensorFiles(this.debugLevel);
		this.pixelMapping=new PixelMapping(sensorPaths,debugLevel);
		this.pixelMapping=new PixelMapping(sensorPaths,debugLevel);
		this.usedChannels= usedChannels(correctionsParameters.getSourcePaths());
		this.usedChannels= usedChannels(correctionsParameters.getSourcePaths());
@@ -108,8 +136,8 @@ public class EyesisCorrections {
		if ((this.debugLevel>101) && (correctionsParameters.sourcePaths!=null) && (correctionsParameters.sourcePaths.length>0)) {
		if ((this.debugLevel>101) && (correctionsParameters.sourcePaths!=null) && (correctionsParameters.sourcePaths.length>0)) {
			testFF(correctionsParameters.sourcePaths[0]);
			testFF(correctionsParameters.sourcePaths[0]);
		}
		}
		
	}
	}

	public double [] calcReferenceExposures(int debugLevel){
	public double [] calcReferenceExposures(int debugLevel){
		String [] paths=this.correctionsParameters.getSourcePaths();
		String [] paths=this.correctionsParameters.getSourcePaths();
		double [] exposures=new double [paths.length];
		double [] exposures=new double [paths.length];
@@ -329,8 +357,8 @@ public class EyesisCorrections {
			if (this.usedChannels[chn] && (this.sharpKernelPaths[chn]!=null) && (!nonlinParameters.useDiffNoiseGains ||(this.smoothKernelPaths[chn]!=null))){
			if (this.usedChannels[chn] && (this.sharpKernelPaths[chn]!=null) && (!nonlinParameters.useDiffNoiseGains ||(this.smoothKernelPaths[chn]!=null))){
				if (
				if (
						(this.imageNoiseGains[chn]==null) ||
						(this.imageNoiseGains[chn]==null) ||
						(!this.sharpKernelPaths[chn].equals((String) this.imageNoiseGains[chn].getProperty("sharpKernelPath"))) ||
						(!this.sharpKernelPaths[chn].equals(this.imageNoiseGains[chn].getProperty("sharpKernelPath"))) ||
						(!this.smoothKernelPaths[chn].equals((String) this.imageNoiseGains[chn].getProperty("smoothKernelPath")))){
						(!this.smoothKernelPaths[chn].equals(this.imageNoiseGains[chn].getProperty("smoothKernelPath")))){


					ImagePlus imp_kernel_sharp=new ImagePlus(this.sharpKernelPaths[chn]);
					ImagePlus imp_kernel_sharp=new ImagePlus(this.sharpKernelPaths[chn]);
					  if (imp_kernel_sharp.getStackSize()<3) {
					  if (imp_kernel_sharp.getStackSize()<3) {
@@ -486,6 +514,10 @@ public class EyesisCorrections {
	}
	}


	boolean [] usedChannels(String [] paths){
	boolean [] usedChannels(String [] paths){
		return usedChannels(paths, false);
	}

	boolean [] usedChannels(String [] paths, boolean missing_ok){
		if (paths==null) paths=new String[0];
		if (paths==null) paths=new String[0];
		int numChannels=this.pixelMapping.getNumChannels();
		int numChannels=this.pixelMapping.getNumChannels();
		boolean [] usedChannels=new boolean[numChannels];
		boolean [] usedChannels=new boolean[numChannels];
@@ -498,7 +530,9 @@ public class EyesisCorrections {
				if (channels!=null) for (int j=0;j<channels.length;j++) usedChannels[channels[j]]=true;
				if (channels!=null) for (int j=0;j<channels.length;j++) usedChannels[channels[j]]=true;
			} else {
			} else {
				if (!this.pixelMapping.isChannelAvailable(srcChannel)){
				if (!this.pixelMapping.isChannelAvailable(srcChannel)){
					if (debugLevel>0) System.out.println("No sensor data for channel "+srcChannel+", needed for source file "+paths[i]);
					if ((debugLevel>0) && !missing_ok) {
						System.out.println("No sensor data for channel "+srcChannel+", needed for source file "+paths[i]);
					}
				} else usedChannels[srcChannel] = true;
				} else usedChannels[srcChannel] = true;
			}
			}
		}
		}
@@ -1795,6 +1829,7 @@ public class EyesisCorrections {
//			  System.out.println("\n=== nextFirstFindex["+li+"] =" + nextFirstFindex[li]+" === ");
//			  System.out.println("\n=== nextFirstFindex["+li+"] =" + nextFirstFindex[li]+" === ");
			  for (int ithread = 0; ithread < threads.length; ithread++) {
			  for (int ithread = 0; ithread < threads.length; ithread++) {
				  threads[ithread] = new Thread() {
				  threads[ithread] = new Thread() {
					  @Override
					public void run() {
					public void run() {
						  float [] pixels=null;       // will be initialized at first use
						  float [] pixels=null;       // will be initialized at first use
						  float [] kernelPixels=null; // will be initialized at first use
						  float [] kernelPixels=null; // will be initialized at first use
@@ -1880,6 +1915,7 @@ public class EyesisCorrections {
							  final int numFinished=tilesFinishedAtomic.getAndIncrement();
							  final int numFinished=tilesFinishedAtomic.getAndIncrement();
							  if (numFinished % (numberOfKernels/100+1) == 0) {
							  if (numFinished % (numberOfKernels/100+1) == 0) {
								  SwingUtilities.invokeLater(new Runnable() {
								  SwingUtilities.invokeLater(new Runnable() {
									  @Override
									public void run() {
									public void run() {
										  IJ.showProgress(numFinished,numberOfKernels);
										  IJ.showProgress(numFinished,numberOfKernels);
									  }
									  }
@@ -2210,6 +2246,7 @@ public class EyesisCorrections {
		  final long startTime = System.nanoTime();
		  final long startTime = System.nanoTime();
		  for (int ithread = 0; ithread < threads.length; ithread++) {
		  for (int ithread = 0; ithread < threads.length; ithread++) {
			  threads[ithread] = new Thread() {
			  threads[ithread] = new Thread() {
				  @Override
				public void run() {
				public void run() {
					  DoubleGaussianBlur gb=null;
					  DoubleGaussianBlur gb=null;
					  if (blurSigma>0)	 gb=new DoubleGaussianBlur();
					  if (blurSigma>0)	 gb=new DoubleGaussianBlur();
+1079 −1127

File changed.

Preview size limit exceeded, changes collapsed.

+5 −2
Original line number Original line Diff line number Diff line
@@ -154,6 +154,9 @@ public class PixelMapping {
    // as stored in "subcamera" field of the calibration file and "sensor_port". sensor_port may start from non-0, so we need to count all combinations
    // as stored in "subcamera" field of the calibration file and "sensor_port". sensor_port may start from non-0, so we need to count all combinations
    //removeUnusedSensorData xshould be off!
    //removeUnusedSensorData xshould be off!
    public int [] channelsForSubCamera(int subCamera){
    public int [] channelsForSubCamera(int subCamera){
    	if (subCamera < 0) {
    		return null;
    	}
		System.out.println("channelsForSubCamera("+subCamera+"),this.sensors.length="+this.sensors.length);
		System.out.println("channelsForSubCamera("+subCamera+"),this.sensors.length="+this.sensors.length);
//    	ArrayList<ArrayList<ArrayList<Integer>>> camera_IPs = new ArrayList<ArrayList<ArrayList<Integer>>>();
//    	ArrayList<ArrayList<ArrayList<Integer>>> camera_IPs = new ArrayList<ArrayList<ArrayList<Integer>>>();
    	ArrayList<Point> cam_port = new ArrayList<Point>();
    	ArrayList<Point> cam_port = new ArrayList<Point>();
@@ -172,11 +175,11 @@ public class PixelMapping {
			}
			}
		});
		});
		// debugging:
		// debugging:
		System.out.println("----- This filename subcamera "+subCamera+": physical camera "+cam_port_arr[subCamera].x+", sensor_port "+cam_port_arr[subCamera].y);
		if (subCamera >= cam_port_arr.length) {
		if (subCamera >= cam_port_arr.length) {
			System.out.println("Error: Subcamera "+subCamera+" > that total namera of sensor ports in the system = "+cam_port_arr.length);
			System.out.println("Error: Subcamera "+subCamera+" > that total number of sensor ports in the system = "+cam_port_arr.length);
			return null;
			return null;
		}
		}
		System.out.println("----- This filename subcamera "+subCamera+": physical camera "+cam_port_arr[subCamera].x+", sensor_port "+cam_port_arr[subCamera].y);
    	if (this.sensors == null) return null;
    	if (this.sensors == null) return null;
    	int numChannels=0;
    	int numChannels=0;
    	for (int i=0;i<this.sensors.length;i++) if (this.sensors[i]!=null) {
    	for (int i=0;i<this.sensors.length;i++) if (this.sensors[i]!=null) {
Loading