Commit 98f61e34 authored by gonciarz's avatar gonciarz

Colocalization GUI cleaned up a little - now it is able to handle n-channels instead of fixed 2

parent 52bdd612
...@@ -23,15 +23,20 @@ import javax.swing.JFileChooser; ...@@ -23,15 +23,20 @@ import javax.swing.JFileChooser;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import org.apache.log4j.Logger;
import ij.IJ; import ij.IJ;
import ij.ImagePlus; import ij.ImagePlus;
import ij.gui.GenericDialog; import ij.gui.GenericDialog;
import mosaic.bregman.Parameters; import mosaic.bregman.Parameters;
import mosaic.core.GUI.HelpGUI; import mosaic.core.GUI.HelpGUI;
import mosaic.plugins.BregmanGLM_Batch.RunMode; import mosaic.plugins.BregmanGLM_Batch.RunMode;
import mosaic.utils.ImgUtils;
public class GenericGUI { public class GenericGUI {
private static final Logger logger = Logger.getLogger(GenericGUI.class);
// Input params // Input params
protected final Parameters iParameters; protected final Parameters iParameters;
protected ImagePlus iInputImage; protected ImagePlus iInputImage;
...@@ -39,11 +44,11 @@ public class GenericGUI { ...@@ -39,11 +44,11 @@ public class GenericGUI {
private boolean iIsConfigReadFromArguments; private boolean iIsConfigReadFromArguments;
private String iInputField = ""; private String iInputField = "";
protected ImagePlus imgch2; // TODO: it is not used currently (never assigned)
public GenericGUI(ImagePlus aInputImg, boolean aUseGui, Parameters aParameters, boolean aIsConfigReadFromArguments) { public GenericGUI(ImagePlus aInputImg, boolean aUseGui, Parameters aParameters, boolean aIsConfigReadFromArguments) {
iParameters = aParameters; iParameters = aParameters;
iInputImage = aInputImg; iInputImage = aInputImg;
logger.info("GUI input image: " + ImgUtils.getImageInfo(aInputImg));
iUseGui = aUseGui; iUseGui = aUseGui;
iIsConfigReadFromArguments = aIsConfigReadFromArguments; iIsConfigReadFromArguments = aIsConfigReadFromArguments;
} }
...@@ -95,7 +100,7 @@ public class GenericGUI { ...@@ -95,7 +100,7 @@ public class GenericGUI {
addButton(p, "Options", new ActionListener() { addButton(p, "Options", new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent arg0) { public void actionPerformed(ActionEvent arg0) {
final ColocalizationGUI gds = new ColocalizationGUI(iInputImage, imgch2, iParameters); final ColocalizationGUI gds = new ColocalizationGUI(iInputImage, iParameters);
gds.run(); gds.run();
} }
}); });
...@@ -128,7 +133,7 @@ public class GenericGUI { ...@@ -128,7 +133,7 @@ public class GenericGUI {
if (!iUseGui && !iIsConfigReadFromArguments) { if (!iUseGui && !iIsConfigReadFromArguments) {
BackgroundSubGUI.getParameters(iParameters); BackgroundSubGUI.getParameters(iParameters);
SegmentationGUI.getParameters(iParameters); SegmentationGUI.getParameters(iParameters);
new ColocalizationGUI(iInputImage, imgch2, iParameters).run(); new ColocalizationGUI(iInputImage, iParameters).run();
VisualizationGUI.getParameters(iParameters); VisualizationGUI.getParameters(iParameters);
} }
iInputField = gd.getNextString(); iInputField = gd.getNextString();
...@@ -176,14 +181,11 @@ public class GenericGUI { ...@@ -176,14 +181,11 @@ public class GenericGUI {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
// close previosuly opened images
if (iInputImage != null) { if (iInputImage != null) {
iInputImage.close(); iInputImage.close();
iInputImage = null; iInputImage = null;
} }
if (imgch2 != null) {
imgch2.close();
imgch2 = null;
}// close previosuly opened images
final JFileChooser fc = new JFileChooser(); final JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
......
...@@ -39,7 +39,7 @@ public class Mask { ...@@ -39,7 +39,7 @@ public class Mask {
double minNorm = iGlobalMin; double minNorm = iGlobalMin;
double maxNorm = iGlobalMax; double maxNorm = iGlobalMax;
if (iGlobalMax == 0) { if (iGlobalMax == 0) {
MinMax<Double> mm = ImgUtils.findMinMax(aImage); MinMax<Double> mm = ImgUtils.findMinMax(aImage, 1, 1);
minNorm = mm.getMin(); minNorm = mm.getMin();
maxNorm = mm.getMax(); maxNorm = mm.getMax();
} }
...@@ -47,7 +47,7 @@ public class Mask { ...@@ -47,7 +47,7 @@ public class Mask {
} }
private boolean[][][] generateMask(final ImagePlus aImage, double aNormalizationMin, double aNormalizationMax, double aMaskThreshold) { private boolean[][][] generateMask(final ImagePlus aImage, double aNormalizationMin, double aNormalizationMax, double aMaskThreshold) {
ImagePlus mask = Mask.createBinaryCellMask(aImage, "Cell mask", aMaskThreshold * (aNormalizationMax - aNormalizationMin) + aNormalizationMin); ImagePlus mask = Mask.createBinaryCellMask(aImage, "Cell mask", aMaskThreshold * (aNormalizationMax - aNormalizationMin) + aNormalizationMin, 1);
return ImgUtils.imgToZXYbinaryArray(mask); return ImgUtils.imgToZXYbinaryArray(mask);
} }
...@@ -97,13 +97,13 @@ public class Mask { ...@@ -97,13 +97,13 @@ public class Mask {
return ((inside / size) > InsideThreshold); return ((inside / size) > InsideThreshold);
} }
public static ImagePlus createBinaryCellMask(ImagePlus aInputImage, String aTitle, double aThreshold) { public static ImagePlus createBinaryCellMask(ImagePlus aInputImage, String aTitle, double aThreshold, int aChannel) {
int ni = aInputImage.getWidth(); int ni = aInputImage.getWidth();
int nj = aInputImage.getHeight(); int nj = aInputImage.getHeight();
int nz = aInputImage.getNSlices(); int nz = aInputImage.getNSlices();
final ImageStack maskStack = new ImageStack(ni, nj); final ImageStack maskStack = new ImageStack(ni, nj);
for (int z = 0; z < nz; z++) { for (int z = 0; z < nz; z++) {
aInputImage.setSlice(z + 1); aInputImage.setPosition(aChannel, z, 1);
ImageProcessor ip = aInputImage.getProcessor(); ImageProcessor ip = aInputImage.getProcessor();
final byte[] mask = new byte[ni * nj]; final byte[] mask = new byte[ni * nj];
for (int i = 0; i < ni; i++) { for (int i = 0; i < ni; i++) {
......
...@@ -6,7 +6,6 @@ import java.io.IOException; ...@@ -6,7 +6,6 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Scanner; import java.util.Scanner;
...@@ -47,7 +46,7 @@ public class RScript { ...@@ -47,7 +46,7 @@ public class RScript {
* ----------------------------------------------------------------------------------------- * -----------------------------------------------------------------------------------------
*/ */
public static void makeRScript(String path, String aObjectsDataFile, String aObjectsColocFile, String aImagesColocFile, List<ChannelPair> aChannelPairs, int[] ImagesPerGroup, String[] GroupNames, String Ch1Name, String Ch2Name) { public static void makeRScript(String path, String aObjectsDataFile, String aObjectsColocFile, String aImagesColocFile, List<ChannelPair> aChannelPairs, int[] ImagesPerGroup, String[] GroupNames, String Ch1Name, String Ch2Name) {
logger.info("Generateing Rscript with path=[" + path + "] aObjectsDataFile=[" + aObjectsDataFile + "] aObjectsColocFile=[" + aObjectsColocFile + "] aImagesColocFile=[" + aImagesColocFile + "] aChannelPairs=[" + aChannelPairs + "] ImagesPerGroup=[" + Debug.getString(ImagesPerGroup) + "] GroupNames=[" + Debug.getString(GroupNames) + "] Ch1Name=[" + Ch1Name + "] Ch2Name=[" + Ch2Name + "]"); logger.info("Generateing Rscript with path=[" + path + "] aObjectsDataFile=[" + aObjectsDataFile + "] aObjectsColocFile=[" + aObjectsColocFile + "] aImagesColocFile=[" + aImagesColocFile + "] aChannelPairs=[" + aChannelPairs + "] ImagesPerGroup=[" + Debug.getString(ImagesPerGroup) + "] GroupNames=[" + Debug.getString((Object[])GroupNames) + "] Ch1Name=[" + Ch1Name + "] Ch2Name=[" + Ch2Name + "]");
try { try {
PrintWriter Script = new PrintWriter(path + File.separator + ScriptName); PrintWriter Script = new PrintWriter(path + File.separator + ScriptName);
......
...@@ -31,12 +31,12 @@ class SamplePearsonCorrelationCoefficient { ...@@ -31,12 +31,12 @@ class SamplePearsonCorrelationCoefficient {
iImageA = new double[iDepth][iWidth][iHeight]; iImageA = new double[iDepth][iWidth][iHeight];
double maxA = initImageAndGetMax(aImgA, iImageA); double maxA = initImageAndGetMax(aImgA, iImageA);
double tx = aMaskImgA ? aMaskThresholdA * maxA : -1; double tx = aMaskImgA ? aMaskThresholdA * maxA : -1;
iMaskA = ImgUtils.imgToZXYbinaryArray(Mask.createBinaryCellMask(aImgA, "Channel1", tx)); iMaskA = ImgUtils.imgToZXYbinaryArray(Mask.createBinaryCellMask(aImgA, "Channel1", tx, 1));
iImageB = new double[iDepth][iWidth][iHeight]; iImageB = new double[iDepth][iWidth][iHeight];
double maxB = initImageAndGetMax(aImgB, iImageB); double maxB = initImageAndGetMax(aImgB, iImageB);
double ty = aMaskImgB ? aMaskThresholdB * maxB : -1; double ty = aMaskImgB ? aMaskThresholdB * maxB : -1;
iMaskB = ImgUtils.imgToZXYbinaryArray(Mask.createBinaryCellMask(aImgB, "Channel2", ty)); iMaskB = ImgUtils.imgToZXYbinaryArray(Mask.createBinaryCellMask(aImgB, "Channel2", ty, 1));
} }
/** /**
......
...@@ -387,7 +387,7 @@ public class SquasshLauncher { ...@@ -387,7 +387,7 @@ public class SquasshLauncher {
double max = iGlobalNormalizationMax; double max = iGlobalNormalizationMax;
logger.info("Global min/max: " + min + "/" + max); logger.info("Global min/max: " + min + "/" + max);
if (iGlobalNormalizationMax == 0) { if (iGlobalNormalizationMax == 0) {
MinMax<Double> mm = ImgUtils.findMinMax(img); MinMax<Double> mm = ImgUtils.findMinMax(img, 1, 1);
min = mm.getMin(); min = mm.getMin();
max = mm.getMax(); max = mm.getMax();
logger.info("Global min/max from image: " + min + "/" + max); logger.info("Global min/max from image: " + min + "/" + max);
......
...@@ -402,7 +402,7 @@ public class ImgUtils { ...@@ -402,7 +402,7 @@ public class ImgUtils {
return aImg.factory().create(dims, aImg.firstElement().copy()); return aImg.factory().create(dims, aImg.firstElement().copy());
} }
public static MinMax<Double> findMinMax(ImagePlus img) { public static MinMax<Double> findMinMax(ImagePlus img, int channel, int frame) {
int ni = img.getWidth(); int ni = img.getWidth();
int nj = img.getHeight(); int nj = img.getHeight();
int nz = img.getNSlices(); int nz = img.getNSlices();
...@@ -410,7 +410,7 @@ public class ImgUtils { ...@@ -410,7 +410,7 @@ public class ImgUtils {
double max = -Double.MAX_VALUE; double max = -Double.MAX_VALUE;
for (int z = 0; z < nz; z++) { for (int z = 0; z < nz; z++) {
img.setSlice(z + 1); img.setPosition(channel, z + 1, frame);
ImageProcessor imp = img.getProcessor(); ImageProcessor imp = img.getProcessor();
for (int i = 0; i < ni; i++) { for (int i = 0; i < ni; i++) {
for (int j = 0; j < nj; j++) { for (int j = 0; j < nj; j++) {
......
package mosaic.bregman; package mosaic.bregman;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
...@@ -9,13 +10,16 @@ import java.util.Map; ...@@ -9,13 +10,16 @@ import java.util.Map;
import org.junit.Test; import org.junit.Test;
import ij.ImagePlus;
import mosaic.bregman.ColocalizationAnalysis.ChannelPair; import mosaic.bregman.ColocalizationAnalysis.ChannelPair;
import mosaic.bregman.ColocalizationAnalysis.ColocResult; import mosaic.bregman.ColocalizationAnalysis.ColocResult;
import mosaic.bregman.ColocalizationAnalysis.RegionColoc; import mosaic.bregman.ColocalizationAnalysis.RegionColoc;
import mosaic.bregman.GUI.ColocalizationGUI;
import mosaic.bregman.segmentation.Pix; import mosaic.bregman.segmentation.Pix;
import mosaic.bregman.segmentation.Region; import mosaic.bregman.segmentation.Region;
import mosaic.test.framework.CommonBase;
public class ColocalizationAnalysisTest { public class ColocalizationAnalysisTest extends CommonBase {
@Test @Test
public void testSimpleTwoRegions() { public void testSimpleTwoRegions() {
...@@ -85,4 +89,15 @@ public class ColocalizationAnalysisTest { ...@@ -85,4 +89,15 @@ public class ColocalizationAnalysisTest {
assertEquals(true, rc10.singleRegionColoc); assertEquals(true, rc10.singleRegionColoc);
} }
@Test
public void testGUI() {
ImagePlus iInputImage = loadImagePlus("/Users/gonciarz/1/3C.tif");
Parameters iParameters = new Parameters();
iParameters.usecellmaskY=true;
iParameters.thresholdcellmasky = 0.5;
final ColocalizationGUI gds = new ColocalizationGUI(iInputImage, iParameters);
gds.run();
System.out.println(iParameters);
}
} }
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