Skip to content

Commit

Permalink
Added seed picker tool and improved Seeds structure
Browse files Browse the repository at this point in the history
Adapted RW UI for grayscale support.

Task: #284 (http://github.com/CellDynamics/QuimP/issues/284)
Reworked SeedPicker

Changed UI

Added conversion to stack and grayscale image.

Task: #239

Added conversion from grayscale to Seeds

Task: #284

Changes in UI

Task: #284

Added exception on empty roi seeds

Task: #284

Almost finished
  • Loading branch information
CellDynamics committed Jan 10, 2018
1 parent c4aa3b7 commit 3e6211a
Show file tree
Hide file tree
Showing 14 changed files with 878 additions and 234 deletions.
Expand Up @@ -20,7 +20,7 @@
public class ProbabilityMaps extends ListMap<RealMatrix> {

/**
*
* Default constructor.
*/
public ProbabilityMaps() {
super();
Expand All @@ -36,6 +36,7 @@ public ProbabilityMaps() {
* @throws IllegalArgumentException if size is not equal
*/
public double[][][] convertTo3dMatrix(Object key) {
// TODO consider using ImageStack here
List<RealMatrix> maps = get(key);
// Can be null if points not found
if (maps == null || maps.isEmpty()) {
Expand Down
Expand Up @@ -546,8 +546,9 @@ public Seeds propagateSeed(ImageProcessor previous, ImageProcessor org, double s
big.fill();
double stepsshrink = shrinkPower / stepSize; // total shrink/step size
double stepsexp = (expandPower) / stepSize; // total shrink/step size
Seeds ret = new Seeds(2);

List<Outline> outlines = getOutline(previous);
List<Outline> outlines = getOutline(previous); // this supports grayscales

// save extra debug info if property set
if (QuimP.SUPER_DEBUG) {
Expand Down Expand Up @@ -577,6 +578,7 @@ public Seeds propagateSeed(ImageProcessor previous, ImageProcessor org, double s
small.fill(fr);
small.drawRoi(fr);
// small.resetRoi();
ret.put(SeedTypes.FOREGROUNDS, small);
}

for (Outline o : outlines) {
Expand All @@ -596,8 +598,6 @@ public Seeds propagateSeed(ImageProcessor previous, ImageProcessor org, double s
}
big.invert();
// store seeds if option ticked
Seeds ret = new Seeds(2);
ret.put(SeedTypes.FOREGROUNDS, small);
ret.put(SeedTypes.BACKGROUND, getTrueBackground(big, org));
if (storeSeeds) {
seeds.add(ret);
Expand All @@ -610,7 +610,7 @@ public Seeds propagateSeed(ImageProcessor previous, ImageProcessor org, double s
/**
* Convert mask to outline.
*
* @param previous image to outline. White object on black background.
* @param previous image to be converted outline. White object on black background.
* @return List of Outline for current frame
* @see TrackOutline
*/
Expand Down Expand Up @@ -729,8 +729,9 @@ public ImagePlus getCompositeSeed(ImagePlus org, int offset) throws RandomWalkEx

for (Seeds p : seeds) {
// just in case convert to byte
// FIXME compile foregorunds from all images
ImageProcessor fg = (ImageProcessor) p.get(SeedTypes.FOREGROUNDS, 1).convertToByte(true);
// ImageProcessor fg = (ImageProcessor) p.get(SeedTypes.FOREGROUNDS, 1).convertToByte(true);
ImageProcessor fg = SeedProcessor.flatten(p, SeedTypes.FOREGROUNDS, 1).convertToByte(true);
fg.threshold(0); // need 255 not real value of map
ImageProcessor bg = (ImageProcessor) p.get(SeedTypes.BACKGROUND, 1).convertToByte(true);
// make colors transparent
bg.multiply(colorScaling);
Expand Down
Expand Up @@ -43,7 +43,11 @@ public enum SeedSource {
/**
* Seed from binary mask image read from Qconf file.
*/
QconfFile
QconfFile,
/**
* ROIs
*/
Rois
}

/**
Expand Down Expand Up @@ -76,6 +80,16 @@ public String[] getFilteringMethods() {
return Arrays.stream(Filters.values()).map(Enum::name).toArray(String[]::new);
}

/**
* Get seed sources defined in {@link SeedSource}.
*
* @return array of seed sources
* @see SeedSource
*/
public String[] getSeedSources() {
return Arrays.stream(SeedSource.values()).map(Enum::name).toArray(String[]::new);
}

/**
* Image to process.
*/
Expand Down Expand Up @@ -116,7 +130,37 @@ public void setOriginalImage(ImagePlus originalImage) {
/**
* Selected seed source. Depending on value some of fields may be invalid.
*/
public SeedSource seedSource;
private SeedSource selectedSeedSource;

/**
* SeedSource getter.
*
* @return the seedSource
* @see SeedSource
*/
public SeedSource getSelectedSeedSource() {
return selectedSeedSource;
}

/**
* SeedSource setter.
*
* @param selectedSeedSource the selectedSeedSource to set
*/
public void setSelectedSeedSource(SeedSource selectedSeedSource) {
this.selectedSeedSource = selectedSeedSource;
}

/**
* SeedSource setter.
*
* @param selectedSeedSource index of SeedSource to set according to order returned by
* {@link #getSeedSources()}
*/
public void setSelectedSeedSource(int selectedSeedSource) {
this.selectedSeedSource = SeedSource.valueOf(getSeedSources()[selectedSeedSource]);
}

/**
* Seed given by RGB image selected from IJ. Valid for all seed sources.
*/
Expand Down Expand Up @@ -361,7 +405,7 @@ public void setSelectedFilteringPostMethod(int selectedFilteringPostMethod) {
public RandomWalkModel() {
algOptions = new RandomWalkOptions();
originalImage = null;
seedSource = SeedSource.RGBImage;
setSelectedSeedSource(SeedSource.RGBImage);
seedImage = null;
qconfFile = null;
selectedShrinkMethod = Propagators.NONE;
Expand All @@ -386,18 +430,18 @@ public RandomWalkModel() {
@Override
public String toString() {
return "RandomWalkModel [params=" + algOptions + ", originalImage=" + originalImage
+ ", seedSource=" + seedSource + ", seedImage=" + seedImage + ", qconfFile=" + qconfFile
+ ", selectedShrinkMethod=" + selectedShrinkMethod + ", shrinkPower=" + shrinkPower
+ ", expandPower=" + expandPower + ", estimateBackground=" + estimateBackground
+ ", selectedFilteringMethod=" + selectedFilteringMethod + ", hatFilter=" + hatFilter
+ ", alev=" + alev + ", num=" + num + ", window=" + window
+ ", selectedFilteringPostMethod=" + selectedFilteringPostMethod + ", showSeeds="
+ showSeeds + ", showPreview=" + showPreview + ", getShrinkMethods()="
+ Arrays.toString(getShrinkMethods()) + ", getFilteringMethods()="
+ Arrays.toString(getFilteringMethods()) + ", getselectedShrinkMethod()="
+ getselectedShrinkMethod() + ", getSelectedFilteringMethod()="
+ getSelectedFilteringMethod() + ", getSelectedFilteringPostMethod()="
+ getSelectedFilteringPostMethod() + "]";
+ ", seedSource=" + getSelectedSeedSource() + ", seedImage=" + seedImage
+ ", qconfFile=" + qconfFile + ", selectedShrinkMethod=" + selectedShrinkMethod
+ ", shrinkPower=" + shrinkPower + ", expandPower=" + expandPower
+ ", estimateBackground=" + estimateBackground + ", selectedFilteringMethod="
+ selectedFilteringMethod + ", hatFilter=" + hatFilter + ", alev=" + alev + ", num="
+ num + ", window=" + window + ", selectedFilteringPostMethod="
+ selectedFilteringPostMethod + ", showSeeds=" + showSeeds + ", showPreview="
+ showPreview + ", getShrinkMethods()=" + Arrays.toString(getShrinkMethods())
+ ", getFilteringMethods()=" + Arrays.toString(getFilteringMethods())
+ ", getselectedShrinkMethod()=" + getselectedShrinkMethod()
+ ", getSelectedFilteringMethod()=" + getSelectedFilteringMethod()
+ ", getSelectedFilteringPostMethod()=" + getSelectedFilteringPostMethod() + "]";
}

/*
Expand All @@ -420,7 +464,7 @@ public int hashCode() {
result = prime * result + ((algOptions == null) ? 0 : algOptions.hashCode());
result = prime * result + ((qconfFile == null) ? 0 : qconfFile.hashCode());
result = prime * result + ((seedImage == null) ? 0 : seedImage.getTitle().hashCode());
result = prime * result + ((seedSource == null) ? 0 : seedSource.hashCode());
result = prime * result + ((selectedSeedSource == null) ? 0 : selectedSeedSource.hashCode());
result = prime * result
+ ((selectedFilteringMethod == null) ? 0 : selectedFilteringMethod.hashCode());
result = prime * result
Expand Down Expand Up @@ -493,7 +537,7 @@ public boolean equals(Object obj) {
} else if (!seedImage.getTitle().equals(other.seedImage.getTitle())) {
return false;
}
if (seedSource != other.seedSource) {
if (selectedSeedSource != other.selectedSeedSource) {
return false;
}
if (selectedFilteringMethod != other.selectedFilteringMethod) {
Expand Down
Expand Up @@ -88,7 +88,7 @@ public RandomWalkOptions() {
alpha = 4e2;
beta = 2 * 25;
gamma[0] = 100;
gamma[1] = 300;
gamma[1] = 0;
iter = 10000;
dt = 0.1;
relim = new double[] { 8e-3, 10 * 8e-3 };
Expand Down

0 comments on commit 3e6211a

Please sign in to comment.