Skip to content

Commit

Permalink
show rectangle in top
Browse files Browse the repository at this point in the history
  • Loading branch information
mzouink committed Jul 9, 2020
1 parent 64618ed commit 24f7994
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 27 deletions.
40 changes: 37 additions & 3 deletions src/main/java/com/preibisch/pinna2d/tools/Imp.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import net.imglib2.view.Views;
import org.jetbrains.annotations.NotNull;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

Expand Down Expand Up @@ -48,12 +50,44 @@ public static Imp init(String imagePath, String maskPath, String lutPath, int mo
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);
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);
return ImpHelpers.toImage(gui_image);
BufferedImage buff = gui_image.getBufferedImage();
Image fxImage = ImpHelpers.toImage(buff);
return fxImage;
}

private void addRectangle(BufferedImage buff, Rectangle rectangle) {
Graphics2D graph = buff.createGraphics();
graph.setColor(Color.RED);
graph.draw(rectangle);
// graph.fill(rectangle);
graph.dispose();
}

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 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 {
Expand Down Expand Up @@ -102,10 +136,10 @@ public float getValue(int x, int y) {
return getValue(mask, x, y);
}

public void set(float value) {
public Point set(float value) {
int dims = img.numDimensions() - 1;
IntervalView<FloatType> results = Views.hyperSlice(img, dims, clickViewChannel);
setOnly(mask, results, value, CLICK_VALUE);
return setOnly(mask, results, value, CLICK_VALUE);
}

public long add(float value, int category) {
Expand Down
19 changes: 14 additions & 5 deletions src/main/java/com/preibisch/pinna2d/utils/ImpHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import net.imglib2.view.IntervalView;
import net.imglib2.view.Views;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.Iterator;

Expand Down Expand Up @@ -160,8 +162,8 @@ public static Img<FloatType> createBlackOutput(ImagePlus imp) {
}


public static Image toImage(ImagePlus imp) {
Image fxImage = SwingFXUtils.toFXImage(imp.getBufferedImage(), null);
public static Image toImage(BufferedImage buff) {
Image fxImage = SwingFXUtils.toFXImage(buff, null);
return fxImage;
}

Expand Down Expand Up @@ -201,17 +203,24 @@ public static long add(Img<FloatType> masks, IntervalView<FloatType> result, flo
}


public static void setOnly(Img<FloatType> masks, IntervalView<FloatType> result, float value, int setValue) {
public static Point setOnly(Img<FloatType> masks, IntervalView<FloatType> result, float value, int setValue) {
int x = 0;
int y = 0;
Cursor<FloatType> cursorInput = masks.cursor();
RandomAccess<FloatType> randomAccess = result.randomAccess();
while (cursorInput.hasNext()) {
cursorInput.fwd();
randomAccess.setPosition(cursorInput);
if (cursorInput.get().get() == value)
randomAccess.get().set(setValue);
if (cursorInput.get().get() == value){
x+=cursorInput.getIntPosition(0);
x/=2;
y+=cursorInput.getIntPosition(1);
y/=2;
randomAccess.get().set(setValue);}
else
randomAccess.get().set(0);
}
return new Point(x,y);
}

public static <T extends FloatType> void computeMinMax(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ class AnnotationController : Controller() {
if (it.annotationVal.value.toInt() > 0)
Imp.get().add(it.annotationId.value.toFloat(), it.annotationVal.value.toInt())
}
imageController.updateImage()
imageController.imageView.image = Imp.get().toImage()
// imageController.updateImage()
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.preibisch.pinna2d.controllers

import com.preibisch.pinna2d.model.AnnotationEntryModel
import com.preibisch.pinna2d.tools.Imp
import com.preibisch.pinna2d.tools.Log
import com.preibisch.pinna2d.util.showPopup
Expand All @@ -12,6 +11,7 @@ import javafx.scene.input.MouseEvent
import javafx.scene.paint.Color
import javafx.scene.shape.Circle
import tornadofx.*
import java.awt.Point
import java.io.File


Expand All @@ -26,9 +26,6 @@ class ImageController : Controller() {
var imageView = ImageView()
var currentCategory = 0;

init {

}

fun start(input: String, mask: String, imageName: String,lut:String) {
imageView.image = Imp.init(input, mask,lut).toImage()
Expand All @@ -54,29 +51,37 @@ class ImageController : Controller() {
root.getChildList()!!.add(1, positionCircle)
}

fun clickOnImage(x: Double, y: Double) {
val v = Imp.get().getValue(x.toInt(), y.toInt())
fun clickOnImage(point: Point) {
val v = Imp.get().getValue(point.x, point.y)

if (v > 0) {
annotationController.select(v)
select(v)
select(v,point)
}
Log.info("x: $x y: $y - Val :$v")
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)
}

fun select(v: Float) {
fun select(v: Float, point: Point) {
if (v > 0) {
Imp.get().set(v)
updateImage()
updateImage(point)
}
}

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

fun select(v: Float) {
if (v > 0) {
val point = Imp.get().set(v)
updateImage(point)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.preibisch.pinna2d.model.AnnotationEntryModel
import com.preibisch.pinna2d.model.Instance
import com.preibisch.pinna2d.tools.Imp
import tornadofx.*
import java.awt.Point
import java.io.File

class InstanceController : Controller() {
Expand All @@ -12,6 +13,7 @@ class InstanceController : Controller() {
val annotationController: AnnotationController by inject()
val fileController: FilesAnalyzeManager by inject()
private val imageController: ImageController by inject()
var point = Point(0,0);

fun start(model: Instance) {
val imageName = File(model.inputPath).name
Expand All @@ -23,7 +25,8 @@ class InstanceController : Controller() {
}

fun clickOnImage(x: Double, y: Double) {
imageController.clickOnImage(x, y)
point = Point(x.toInt(),y.toInt())
imageController.clickOnImage(point)
}

fun numberClicked(category: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class AnnotationEditorView : View("Annotations") {
override val root = vbox {
// prefWidth = 200.0
form {
fieldset {
field("image:") {
label(instanceController.model.imageName)
}
}
// fieldset {
// field("image:") {
// label(instanceController.model.imageName)
// }
// }
fieldset { field("ID: ") { label(instanceController.model.annotationId) } }
fieldset { label("Category:") { addClass(Styles.biglabel) } }
fieldset {
Expand Down

0 comments on commit 24f7994

Please sign in to comment.