Skip to content

Commit

Permalink
Merge pull request #5 from LEB-EPFL/ADD_predictor_roi_manager
Browse files Browse the repository at this point in the history
Added automatic cropping of images modulo 4 to the DefaultPredictor
  • Loading branch information
kmdouglass authored May 15, 2018
2 parents 02c7ee4 + 8c2f6a8 commit 18ca689
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 14 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Change Log
All notable changes to this project will be documented in this file.

## [v0.0.2]

### Added

- The `DefaultPredictor` class now automatically crops the input image
to dimensions that are a multiple of four.

### Changed
- Moved the exceptions associated with the `Predictor` interface into
the public `predictors` package.

## [v0.0.1]

### Changed
Expand All @@ -14,5 +25,6 @@ All notable changes to this project will be documented in this file.

- Initial project files.

[v0.0.2]: https://github.com/LEB-EPFL/DEFCoN-ImageJ/releases/tag/0.0.2
[v0.0.1]: https://github.com/LEB-EPFL/DEFCoN-ImageJ/releases/tag/0.0.1
[v0.0.0]: https://github.com/LEB-EPFL/DEFCoN-ImageJ/releases/tag/0.0.0
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
author = 'Baptiste Ottino, Kyle M. Douglass'

# The short X.Y version
version = '0.0.1'
version = '0.0.2'
# The full version, including alpha/beta/rc tags
release = '0.0.1'
release = '0.0.2'


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<groupId>ch.epfl.leb</groupId>
<artifactId>DEFCoN_</artifactId>
<version>0.0.1</version>
<version>0.0.2</version>

<name>DEFCoN-ImageJ</name>
<description>ImageJ plugin for DEFCoN, a fluorescence spot counter using fully convolutional neural networks.</description>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/ch/epfl/leb/defcon/ij/DensityCount.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

import ch.epfl.leb.defcon.predictors.Predictor;
import ch.epfl.leb.defcon.predictors.internal.DefaultPredictor;
import ch.epfl.leb.defcon.predictors.internal.SessionClosedException;
import ch.epfl.leb.defcon.predictors.internal.ImageBitDepthException;
import ch.epfl.leb.defcon.predictors.internal.UninitializedPredictorException;
import ch.epfl.leb.defcon.predictors.SessionClosedException;
import ch.epfl.leb.defcon.predictors.ImageBitDepthException;
import ch.epfl.leb.defcon.predictors.UninitializedPredictorException;

import ij.IJ;
import ij.ImagePlus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*/
package ch.epfl.leb.defcon.predictors.internal;
package ch.epfl.leb.defcon.predictors;

/**
* Raised when an image with an invalid bit-depth is supplied to the predictor.
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/ch/epfl/leb/defcon/predictors/Predictor.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
*/
package ch.epfl.leb.defcon.predictors;

import ch.epfl.leb.defcon.predictors.internal.SessionClosedException;
import ch.epfl.leb.defcon.predictors.internal.ImageBitDepthException;
import ch.epfl.leb.defcon.predictors.internal.UninitializedPredictorException;

import ij.process.ImageProcessor;
import ij.process.FloatProcessor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*/
package ch.epfl.leb.defcon.predictors.internal;
package ch.epfl.leb.defcon.predictors;

/**
* Raised when a prediction is requested but the TensorFlow session has already been closed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*/
package ch.epfl.leb.defcon.predictors.internal;
package ch.epfl.leb.defcon.predictors;

/**
* Raised when a predictor has not yet been fully initialized.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,22 @@
*/
package ch.epfl.leb.defcon.predictors.internal;

import ch.epfl.leb.defcon.predictors.ImageBitDepthException;
import ch.epfl.leb.defcon.predictors.SessionClosedException;
import ch.epfl.leb.defcon.predictors.UninitializedPredictorException;
import ch.epfl.leb.defcon.predictors.Predictor;

import ij.gui.Roi;
import ij.ImagePlus;
import ij.process.ByteProcessor;
import ij.process.FloatProcessor;
import ij.process.ShortProcessor;
import ij.process.ImageProcessor;
import java.awt.Rectangle;

import java.util.logging.Level;
import java.util.logging.Logger;

import org.tensorflow.Tensor;

/**
Expand All @@ -49,6 +57,22 @@ public class DefaultPredictor extends AbstractPredictor implements Predictor {
*/
private FloatProcessor densityMap;

/**
* Checks that an image's dimensions are divisible by four and crops it if not.
*
* This restriction on the size of an image is a requirement of DEFCoN.
*
* @return The input image, possibly cropped.
*/
private ImageProcessor checkDimensions(ImageProcessor ip) {

Rectangle currRoi = ip.getRoi();
ip.setRoi(new Roi(currRoi.x, currRoi.y,
currRoi.width - currRoi.width % 4,
currRoi.height - currRoi.height % 4));
return ip.crop();
}

/**
* Returns the most recent count.
*
Expand Down Expand Up @@ -93,6 +117,9 @@ private void predict(final ByteProcessor bp) {
/**
* Makes a density map prediction from a 2D image.
*
* If either of the image's width or height is not divisible by 4, they will
* be cropped to the next largest multiple of four.
*
* @param ip The image to perform a prediction on.
*/
@Override
Expand All @@ -109,10 +136,10 @@ public void predict(final ImageProcessor ip) throws ImageBitDepthException,
int bitDepth = ip.getBitDepth();
switch (bitDepth) {
case 16:
predict(ip.convertToShortProcessor());
predict(checkDimensions(ip).convertToShortProcessor());
break;
case 8:
predict(ip.convertToByteProcessor());
predict(checkDimensions(ip).convertToByteProcessor());
break;
default:
String msg = "The predictor only works on 8 and 16-bit images.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import ij.IJ;
import ij.ImagePlus;
import ij.process.ImageProcessor;
import ij.process.FloatProcessor;

import java.io.File;
Expand Down Expand Up @@ -101,6 +102,28 @@ public void testGetDensityMap() throws Exception {
assertEquals(imp.getHeight(), fp.getHeight());
assertEquals(imp.getWidth(), fp.getWidth());
}

/**
* Test of getDensityMap method, of class DefaultPredictor.
*
* This test verifies that images whose dimensions are not multiples of four
* are automatically cropped before computing the density map.
*/
@Test
public void testGetDensityMapResized() throws Exception {
System.out.println("testGetDensityMapResized");
ImageProcessor ip = imp.getProcessor();

// Reduce the size of the test data to a non-multiple of four.
ip.setRoi(0, 0, ip.getWidth() - 1, ip.getHeight() - 1);

predictor.predict(ip.crop());
FloatProcessor fp = predictor.getDensityMap();
predictor.close();

assertEquals(imp.getWidth() - 4, fp.getWidth());
assertEquals(imp.getHeight() - 4, fp.getHeight());
}

/**
* Test of predict method, of class DefaultPredictor.
Expand Down

0 comments on commit 18ca689

Please sign in to comment.