...
 
Commits (4)
......@@ -7,7 +7,7 @@
<groupId>mosaic</groupId>
<artifactId>MosaicSuite</artifactId>
<packaging>jar</packaging>
<version>1.0.17</version>
<version>1.0.18</version>
<description>Package contains image processing algorithms developed in MOSAIC Group</description>
<url>http://mosaic.mpi-cbg.de/?q=downloads/imageJ</url>
<inceptionYear>2010</inceptionYear>
......@@ -233,11 +233,6 @@
<artifactId>cmaes</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>javaml</groupId>
<artifactId>javaml</artifactId>
<version>0.1.7</version>
</dependency>
</dependencies>
<build>
......
9fee97b1b60eac370e349595ae8103ab
\ No newline at end of file
0257c25af0f9cbba9df72392f77079effc48888e
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>javaml</groupId>
<artifactId>javaml</artifactId>
<version>0.1.7</version>
</project>
718059452e4f135f5a90dbef5e3f2ae9
\ No newline at end of file
3934852f22068e2ea305fe2166b4ed87ab40b3b3
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>javaml</groupId>
<artifactId>javaml</artifactId>
<versioning>
<release>0.1.7</release>
<versions>
<version>0.1.7</version>
</versions>
<lastUpdated>20160906132602</lastUpdated>
</versioning>
</metadata>
8ba10406828460e0448bf0d8bd3dbabb
\ No newline at end of file
82a41485cdad4e57d239f6550e9732c7c075e1be
\ No newline at end of file
......@@ -22,12 +22,10 @@ import mosaic.core.psf.psf;
import mosaic.utils.ArrayOps;
import mosaic.utils.ArrayOps.MinMax;
import net.imglib2.type.numeric.real.DoubleType;
import net.sf.javaml.clustering.KMeans;
import net.sf.javaml.core.Dataset;
import net.sf.javaml.core.DefaultDataset;
import net.sf.javaml.core.DenseInstance;
import net.sf.javaml.core.Instance;
import net.sf.javaml.tools.DatasetTools;
import weka.clusterers.SimpleKMeans;
import weka.core.Attribute;
import weka.core.DenseInstance;
import weka.core.Instances;
class AnalysePatch {
......@@ -465,44 +463,56 @@ class AnalysePatch {
cin = RSS.betaMLEin;
}
private void estimateIntensityClustering(double[][][] aValues, int aNumOfClasters, boolean aUpdateCout) {
final Dataset data = new DefaultDataset();
final double[] pixel = new double[1];
void estimateIntensityClustering(double[][][] aValues, int aNumOfClasters, boolean aUpdateCout) {
SimpleKMeans kmeans = new SimpleKMeans();
ArrayList<Attribute> attr = new ArrayList<>();
attr.add(new Attribute("pixelValue"));
Instances inst = new Instances("DataPoints", attr, 0);
Set<Double> distinctPixelValues = new HashSet<Double>();
for (int z = 0; z < iSizeOverZ; z++) {
for (int i = 0; i < iSizeOverX; i++) {
for (int j = 0; j < iSizeOverY; j++) {
if (iRegionMask[z][i][j] == 1) {
pixel[0] = aValues[z][i][j];
data.add(new DenseInstance(pixel));
distinctPixelValues.add(pixel[0]);
double value = aValues[z][i][j];
distinctPixelValues.add(value);
final DenseInstance iw = new DenseInstance(1, new double[] {value});
iw.setDataset(inst);
inst.add(iw);
}
}
}
}
logger.debug("Data size = " + data.size() + ", number of distinct values in data set = " + distinctPixelValues.size());
// KMeans is not working correctly if data size of number of distinct values in data size is smaller than requested
// number of clusters.
if (data.size() > aNumOfClasters && distinctPixelValues.size() >= aNumOfClasters) {
logger.debug("Data size = " + inst.size() + ", number of distinct values in data set = " + distinctPixelValues.size());
if (inst.size() >= aNumOfClasters && distinctPixelValues.size() >= aNumOfClasters) {
logger.debug("Running KMeans");
final Dataset[] dataSet = new KMeans(aNumOfClasters, 100).cluster(data);
int numOfClustersFound = dataSet.length;
final double[] levels = new double[numOfClustersFound];
for (int i = 0; i < numOfClustersFound; i++) {
final Instance inst = DatasetTools.average(dataSet[i]);
levels[i] = inst.value(0);
try {
kmeans.setNumClusters(aNumOfClasters);
kmeans.setMaxIterations(100);
kmeans.buildClusterer(inst);
Instances centroids = kmeans.getClusterCentroids();
int numOfClustersFound = kmeans.numberOfClusters();
final double[] levels = new double[numOfClustersFound];
for (int i = 0; i < numOfClustersFound; i++) {
levels[i] = centroids.instance(i).value(0);
}
Arrays.sort(levels);
final int inIndex = Math.min(2, numOfClustersFound - 1);
cin = Math.max(iNormalizedMinObjectIntensity, levels[inIndex]);
final int outFrontIndex = Math.max(inIndex - 1, 0);
cout_front = levels[outFrontIndex];
cout = (aUpdateCout) ? cout_front : levels[0];
logger.debug("Region: " + iInputRegion.iLabel + ", Cluster levels: " + Arrays.toString(levels));
}
catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Something went wrong with clustering...");
}
Arrays.sort(levels);
final int inIndex = Math.min(2, numOfClustersFound - 1);
cin = Math.max(iNormalizedMinObjectIntensity, levels[inIndex]);
final int outFrontIndex = Math.max(inIndex - 1, 0);
cout_front = levels[outFrontIndex];
cout = (aUpdateCout) ? cout_front : levels[0];
logger.debug("Region: " + iInputRegion.iLabel + ", Cluster levels: " + Arrays.toString(levels));
}
else {
logger.debug("Data set too small or with not enough number of distinct values. Setting default values.");
......
......@@ -5,7 +5,7 @@ import java.awt.Color;
import ij.gui.Plot;
import ij.gui.PlotWindow;
import mosaic.ia.Potentials.Potential;
import net.sf.javaml.utils.ArrayUtils;
import mosaic.utils.ArrayOps;
/**
* Class responsible for plotting calculated distributions
......@@ -13,7 +13,7 @@ import net.sf.javaml.utils.ArrayUtils;
*/
public class DistributionsPlot extends BasePlot {
public DistributionsPlot(double[] aContextQdDistancesGrid, double[] aContextQdPdf, double[] aNearestNeighborDistancesXtoYPdf) {
double max = Math.max(ArrayUtils.max(aContextQdPdf), ArrayUtils.max(aNearestNeighborDistancesXtoYPdf));
double max = Math.max(ArrayOps.findMinMax(aContextQdPdf).getMax(), ArrayOps.findMinMax(aNearestNeighborDistancesXtoYPdf).getMax());
plot = new Plot("Result: Estimated distance distributions", "Distance", "Probability density");
plot.setLimits(aContextQdDistancesGrid[0], aContextQdDistancesGrid[aContextQdDistancesGrid.length - 1], 0, max);
......@@ -22,7 +22,7 @@ public class DistributionsPlot extends BasePlot {
}
public DistributionsPlot(double[] aContextQdDistancesGrid, double[] aObservedModelFitPdPdf, double[] aContextQdPdf, double[] aNearestNeighborDistancesXtoYPdf, Potential aPotential, double[] aBestPointFound, double aBestFunctionValue) {
double max = Math.max(ArrayUtils.max(aContextQdPdf), Math.max(ArrayUtils.max(aNearestNeighborDistancesXtoYPdf), ArrayUtils.max(aObservedModelFitPdPdf)));
double max = Math.max(ArrayOps.findMinMax(aContextQdPdf).getMax(), Math.max(ArrayOps.findMinMax(aNearestNeighborDistancesXtoYPdf).getMax(), ArrayOps.findMinMax(aObservedModelFitPdPdf).getMax()));
plot = new Plot("Distance distributions", "Distance", "Probability density");
plot.setLimits(aContextQdDistancesGrid[0], aContextQdDistancesGrid[aContextQdDistancesGrid.length - 1], 0, max);
plot.setLineWidth(2);
......
......@@ -17,7 +17,8 @@ import ij.gui.PlotWindow;
import ij.measure.ResultsTable;
import ij.process.ByteProcessor;
import mosaic.core.detection.Particle;
import net.sf.javaml.utils.ArrayUtils;
import mosaic.utils.ArrayOps;
import mosaic.utils.ArrayOps.MinMax;
/**
......@@ -125,10 +126,14 @@ class TrajectoryAnalysisPlot extends ImageWindow implements ActionListener {
// Calculate X/Y min/max for plot
final double minX = aX[0];
final double maxX = aX[aX.length-1];
double minY = ArrayUtils.min(aY);
double maxY = ArrayUtils.max(aY);
minY = Math.min(minY, ArrayUtils.min(slopeLine));
maxY = Math.max(maxY, ArrayUtils.max(slopeLine));
MinMax<Double> mmY = ArrayOps.findMinMax(aY);
double minY = mmY.getMin();
double maxY = mmY.getMax();
MinMax<Double> mmSlopeLine = ArrayOps.findMinMax(slopeLine);
minY = Math.min(minY, mmSlopeLine.getMin());
maxY = Math.max(maxY, mmSlopeLine.getMax());
// Create plot with slope line
PlotWindow.noGridLines = false; // draw grid lines
......
package mosaic.utils;
import static org.junit.Assert.*;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
......@@ -189,4 +190,12 @@ public class ArrayOpsTest extends CommonBase {
for (int z = 0; z < input[0][0].length; ++z)
assertEquals(1.3, input[i][j][z], 1e-9);
}
@Test
public void testFindMinMax1D() {
double input[] = {-1.5, 4, 2, -2.1, 10, 2};
MinMax<Double> mm = ArrayOps.findMinMax(input);
assertEquals(-2.1, mm.getMin().doubleValue(), 1e-9);
assertEquals(10.0, mm.getMax().doubleValue(), 1e-9);
}
}