Skip to content

Commit

Permalink
channel selection
Browse files Browse the repository at this point in the history
  • Loading branch information
mzouink committed Jul 12, 2020
1 parent d3aba62 commit b020809
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 64 deletions.
24 changes: 18 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
</mailingLists>



<scm>
<connection>scm:git:git://github.com/PreibischLab/annotation_plugin</connection>
<developerConnection>scm:git:[email protected]:PreibischLab/annotation_plugin</developerConnection>
Expand Down Expand Up @@ -164,11 +163,11 @@
</dependency>

<!-- Kotlin -->
<!-- <dependency>-->
<!-- <groupId>org.openjfx</groupId>-->
<!-- <artifactId>javafx-controls</artifactId>-->
<!-- <version>12.0.1</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.openjfx</groupId>-->
<!-- <artifactId>javafx-controls</artifactId>-->
<!-- <version>12.0.1</version>-->
<!-- </dependency>-->

<dependency>
<groupId>no.tornado</groupId>
Expand Down Expand Up @@ -199,6 +198,19 @@
<artifactId>sqlite-jdbc</artifactId>
<version>3.30.1</version>
</dependency>

<!-- Eclipse collection -->
<dependency>
<groupId>org.eclipse.collections</groupId>
<artifactId>eclipse-collections-api</artifactId>
<version>10.2.0</version>
</dependency>

<dependency>
<groupId>org.eclipse.collections</groupId>
<artifactId>eclipse-collections</artifactId>
<version>10.2.0</version>
</dependency>
</dependencies>

<repositories>
Expand Down
123 changes: 77 additions & 46 deletions src/main/java/com/preibisch/pinna2d/tools/Imp.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,62 +17,72 @@
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.*;

//< T extends RealType< T > & NativeType< T >>
public class Imp extends ImpHelpers {
private LUT lut;
// private List<Integer> category_vals;
private final static int CLICK_VALUE = 255;
private final static int CLICK_VALUE = 150;
public final static int WITH_CLICK = 2, WITHOUT_CLICK = 1;
private static Imp instance;
private final int mode;

private final int clickViewChannel;
// private final int maskChannel;
private final int maskChannel;
private final int categoryChannel;
private FloatType min;
private FloatType max;
private CompositeImage gui_image;
private Img<FloatType> img, mask;

private Map<String, Boolean> channelsActivation;
// private List<Integer> activation_channels;
private List<Imp> slices;


public static Imp get() throws Exception {
if (instance == null)
throw new Exception("Not initialized");
return instance;
}

public static Imp init(String imagePath, String maskPath,String lutPath) throws IOException {
return init(imagePath, maskPath, lutPath, WITH_CLICK);
}

public static Imp init(String imagePath, String maskPath, String lutPath, int mode) throws IOException {
instance = new Imp(imagePath, maskPath,lutPath, mode);
public static Imp init(String imagePath, String maskPath, String lutPath) throws IOException {
instance = new Imp(imagePath, maskPath, lutPath);
return instance;
}

public Image toImage(Point point) {
gui_image.updateImage();
int position = categoryChannel+1;
if(lut!=null)
gui_image.setChannelLut(lut, position);
BufferedImage buff = gui_image.getBufferedImage();
Rectangle rect = getRectangle(point,30,new Point(buff.getWidth(),buff.getHeight()));
Log.info("rectangle: " +rect.toString());
addRectangle(buff,rect);
BufferedImage buff = update();
Rectangle rect = getRectangle(point, 30, new Point(buff.getWidth(), buff.getHeight()));
Log.info("rectangle: " + rect.toString());
addRectangle(buff, rect);
Image fxImage = ImpHelpers.toImage(buff);
return fxImage;
}

public Image toImage() {
gui_image.updateImage();
int position = categoryChannel+1;
if(lut!=null)
gui_image.setChannelLut(lut, position);
BufferedImage buff = gui_image.getBufferedImage();
Image fxImage = ImpHelpers.toImage(buff);
Image fxImage = ImpHelpers.toImage(update());
return fxImage;
}

private BufferedImage update() {
int position = categoryChannel + 1;
activateSpecificChannels(gui_image,new ArrayList<Boolean>(channelsActivation.values()));
if (lut != null)
gui_image.setChannelLut(lut, position);
gui_image.updateImage();
BufferedImage buff = gui_image.flatten().getBufferedImage();
return buff;
}

private void activateSpecificChannels(CompositeImage compositeImage, ArrayList<Boolean> activations) {
for (int i = 0; i < activations.size(); i++)
compositeImage.getActiveChannels()[i] = activations.get(i);
}


private void addRectangle(BufferedImage buff, Rectangle rectangle) {
Graphics2D graph = buff.createGraphics();
graph.setColor(Color.RED);
Expand All @@ -82,46 +92,47 @@ private void addRectangle(BufferedImage buff, Rectangle rectangle) {
}

private Rectangle getRectangle(Point point, int dim, Point maxPoint) {
int x1 = Math.max(point.x-dim,0);
int y1 = Math.max(point.y-dim,0);
int x1 = Math.max(point.x - dim, 0);
int y1 = Math.max(point.y - dim, 0);

int x2 = Math.min(point.x+dim,maxPoint.x-1);
int y2 = Math.min(point.y+dim,maxPoint.y-1);
return new Rectangle(x1,y1,x2-x1,y2-y1);
int x2 = Math.min(point.x + dim, maxPoint.x - 1);
int y2 = Math.min(point.y + dim, maxPoint.y - 1);
return new Rectangle(x1, y1, x2 - x1, y2 - y1);
}

private Imp(String imagePath, String maskPath,String lutPath, int mode) throws IOException {
private Imp(String imagePath, String maskPath, String lutPath) throws IOException {
// String p = Imp.class.getClassLoader().getResource("glasbey_inverted.lut").getPath();

// activation_channels = new ArrayList<>();
slices = new ArrayList<>();
File LUT_PATH = new File(lutPath);
Log.info("Lut path: "+LUT_PATH.getAbsolutePath());
Log.info("Lut path: " + LUT_PATH.getAbsolutePath());
if (LUT_PATH.exists())
lut = LutLoader.openLut(LUT_PATH.getAbsolutePath());
lut = LutLoader.openLut(LUT_PATH.getAbsolutePath());
else
Log.error("Lut not found !");

switch (mode) {
case WITH_CLICK:
Log.info("Extra layer for click");
break;
case WITHOUT_CLICK:
Log.info("No layer for click");
break;
default:
throw new IOException("Invalid mode :" + mode);
}
this.mode = mode;

final ImagePlus imp = openImp(new File(imagePath));
printInfos(imp);
ImagePlus impMask = openImp(new File(maskPath));
printInfos(impMask);
mask = ImagePlusAdapter.wrap(impMask);

int nChannels = imp.getNChannels();
List<String> channels = new ArrayList();
for(int i= 0 ;i< nChannels;i++)
channels.add(String.valueOf(i+1));
// channels.addAll(Interval.oneTo(nChannels).stream().map(s -> String.valueOf(s)).collect(Collectors.toList()));
channels.addAll(Arrays.asList("Mask", "Category", "Click"));
channelsActivation = generateChannelsMap(channels);

this.maskChannel = nChannels++;
this.categoryChannel = nChannels++;
this.clickViewChannel = nChannels++;
Log.info("Channels: " + nChannels);
// imp.getStack().addSlice(impMask.getProcessor());
gui_image = ImpHelpers.getComposite(imp, mode);
imp.getStack().addSlice(impMask.getProcessor());
gui_image = ImpHelpers.getComposite(imp, WITH_CLICK);

img = ImagePlusAdapter.wrap(gui_image);

Expand All @@ -132,6 +143,17 @@ private Imp(String imagePath, String maskPath,String lutPath, int mode) throws I
gui_image.draw();
}

private Map<String, Boolean> generateChannelsMap(List<String> channels) {
Map<String, Boolean> result = new LinkedHashMap();
for (String ch : channels){
Log.info(ch);
if (ch.equals("Mask"))
result.put(ch, false);
else
result.put(ch, true);}
return result;
}

public float getValue(int x, int y) {
return getValue(mask, x, y);
}
Expand All @@ -145,8 +167,8 @@ public Point set(float value) {
public long add(float value, int category) {
int dims = img.numDimensions() - 1;
IntervalView<FloatType> results = Views.hyperSlice(img, dims, categoryChannel);
Log.info(String.format("Set category %d to instance %.2f",category,value));
return add(mask, results, value, category+4);
Log.info(String.format("Set category %d to instance %.2f", category, value));
return add(mask, results, value, category + 4);
}

public float getMin() {
Expand All @@ -160,6 +182,15 @@ public float getMax() {
public boolean save(@NotNull File file) {
int dims = img.numDimensions() - 1;
IntervalView<FloatType> view = Views.hyperSlice(img, dims, categoryChannel);
return save(view, file);
return save(view, file);
}

@NotNull
public Map<String, Boolean> getChannelsNames() {
return channelsActivation;
}

public void changeActivationValueFor(@NotNull String text, boolean value) {
channelsActivation.put(text, value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class AnnotationController : Controller() {
private fun newEntry(imageId: Int, img: String, min: Int, max: Int) {
for (i in min..max) {
add(imageId,LocalDate.now(), img, i.toFloat(), -1, 0)

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import java.time.LocalDate

class FilesAnalyzeManager : Controller() {
var model = InputConfiguration()

var files: ObservableList<ImageEntryModel> by singleAssign()
val selectedFile = SimpleObjectProperty<ImageEntryModel>()

Expand All @@ -27,6 +26,7 @@ class FilesAnalyzeManager : Controller() {
}

fun start(input: String, mask: String) {
files.clear()
val inputFiles = getFiles(File(input), ".tif")
val maskFiles = getFiles(File(mask), ".tif")
newEntry(inputFiles, maskFiles)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import java.io.File


class ImageController : Controller() {
private var point = Point(0, 0)

// var channelsActivation: MutableMap<String, Boolean> = HashMap()
val annotationController: AnnotationController by inject()
val scrollFactor = 0.4
private var circle = Circle()
Expand All @@ -24,11 +27,14 @@ class ImageController : Controller() {
private var started = false
var mText = SimpleStringProperty()
var imageView = ImageView()
var currentCategory = 0;
var currentCategory = 0


fun start(input: String, mask: String, imageName: String,lut:String) {
imageView.image = Imp.init(input, mask,lut).toImage()
fun start(input: String, mask: String, imageName: String, lut: String) {
imageView.image = Imp.init(input, mask, lut).toImage()
// channelsActivation.clear()
// channelsActivation.putAll(Imp.get().channelsNames)
// Log.info("Channels: $channelsActivation")
}

fun addCircle(it: MouseEvent, root: Node) {
Expand Down Expand Up @@ -56,14 +62,14 @@ class ImageController : Controller() {

if (v > 0) {
annotationController.select(v)
select(v,point)
select(v, point)
}
Log.info("x: $point.x y: $point.y - Val :$v")
}

fun save(file: File) {
val result = Imp.get().save(file)
showPopup(result,"Saving file!",file.path)
val result = Imp.get().save(file)
showPopup(result, "Saving file!", file.path)
}

fun select(v: Float, point: Point) {
Expand All @@ -73,7 +79,15 @@ class ImageController : Controller() {
}
}

fun updateImage() {
if (point.x > 0)
imageView.image = Imp.get().toImage(point)
else
imageView.image = Imp.get().toImage()
}

fun updateImage(point: Point) {
this.point = point;
imageView.image = Imp.get().toImage(point)
}

Expand All @@ -84,4 +98,13 @@ class ImageController : Controller() {
}
}

fun getActivationMap(): MutableMap<String, Boolean> {
return Imp.get().channelsNames
}

fun changeActivationValueFor(text: String, value: Boolean) {
Imp.get().changeActivationValueFor(text, value)
updateImage()
}

}
2 changes: 1 addition & 1 deletion src/main/kotlin/com/preibisch/pinna2d/util/DEFAULT.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import com.google.common.io.Resources
import com.preibisch.pinna2d.view.MainAnnotationView

//val LUT_PATH = MainAnnotationView::class.java.getResource("/glasbey_inverted.lut").path
var LUT_PATH = ""

//val INPUT_FOLDER = ""
//val MASKS_FOLDER = ""
//var PROJECT_FOLDER = ""
var LUT_PATH = "/Users/Marwan/Desktop/glasbey_inverted.lut"
val INPUT_FOLDER = "/Users/Marwan/Desktop/Irimia Project/Data/raw_Tiff"
val MASKS_FOLDER = "/Users/Marwan/Desktop/Irimia Project/Data/Mask/masks"
var PROJECT_FOLDER = "/Users/Marwan/Desktop/Irimia Project/"
Expand Down
Loading

0 comments on commit b020809

Please sign in to comment.