Skip to content

Commit

Permalink
add scaling of output images according to input image spatial calibra…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
biovoxxel committed Feb 3, 2023
1 parent 3d63b25 commit d58e52c
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 27 deletions.
6 changes: 5 additions & 1 deletion BioVoxxel_3D_Box/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src/main/resources/luts"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources/luts">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
Expand Down
2 changes: 1 addition & 1 deletion BioVoxxel_3D_Box/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.biovoxxel</groupId>
<artifactId>bv3dbox</artifactId>
<version>1.13.4</version>
<version>1.14.2</version>

<name>BioVoxxel 3D Box</name>
<inceptionYear>2021</inceptionYear>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public void run() {

ImagePlus neighborCountMapImp = BV3DBoxUtilities.pullImageFromGPU(neighborAnalysis.getCurrentCLIJ2Instance(), neighbor_image, false, LutNames.GEEN_FIRE_BLUE_LUT);
neighborCountMapImp.setTitle(WindowManager.getUniqueName("NeighborCount_" + inputImagePlus.getTitle()));

System.out.println("Calibration = " + inputImagePlus.getCalibration());
neighborCountMapImp.setCalibration(inputImagePlus.getCalibration());
neighborCountMapImp.show();

if (plotNeighborCount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ public class BV_ObjectInspectorGUI extends DynamicCommand {
+ " This however introduces a certain bias and error in any analysis and should be used with care or only in test cases.")
private Boolean pad_stack_tops = false;

@Parameter(required = false, label = "Display results tables", description = "")
private Boolean display_results_tables = true;

@Parameter(required = false, label = "Show analysis label map", description = "")
private Boolean display_analyzed_label_maps = false;

Expand Down Expand Up @@ -137,7 +140,8 @@ public void run() {
bvoi.setSecondaryVolumeRange(secondary_volume_range);
bvoi.setSecondaryMMDTCRRange(secondary_MMER_range);
bvoi.setEdgeExclusion(exclude_primary_objects_on_edges);
bvoi.setOutputImageFlags(display_analyzed_label_maps, show_count_map);
bvoi.padStackTops(pad_stack_tops);
bvoi.setOutputImageFlags(display_results_tables, display_analyzed_label_maps, show_count_map);

bvoi.inspect();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import de.biovoxxel.bv3dbox.utilities.BV3DBoxUtilities;
import ij.ImagePlus;
import ij.WindowManager;
import net.haesleinhuepf.clij.clearcl.ClearCLBuffer;
import net.haesleinhuepf.clij2.CLIJ2;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public void flatFieldCorrection() {

if (showDebugImages) {

BV3DBoxUtilities.pullAndDisplayImageFromGPU(clij2, corrected_image, false, LutNames.GRAY);
BV3DBoxUtilities.pullAndDisplayImageFromGPU(clij2, corrected_image, false, LutNames.GRAY, originalImagePlus.getCalibration());

}

Expand All @@ -288,6 +288,7 @@ public void flatFieldCorrection() {

correctedImagePlus.setTitle(WindowManager.getUniqueName("FFCorr_" + originalImagePlus.getTitle()));
correctedImagePlus.getProcessor().resetMinAndMax();
correctedImagePlus.setCalibration(originalImagePlus.getCalibration());
correctedImagePlus.show();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public class BV_NeighborAnalysis {

private LogService log = new StderrLogService();
private PrefService prefs = new DefaultPrefService();
private Boolean displayDebugImages = prefs.getBoolean(BV3DBoxSettings.class, "bv_3d_box_settings_display_debug_images", false);
// private Boolean displayDebugImages = prefs.getBoolean(BV3DBoxSettings.class, "bv_3d_box_settings_display_debug_images", false);
private Boolean displayDebugImages = false;
private CLIJ2 clij2;
private ClearCLBuffer connectedComponentLabels;

Expand Down Expand Up @@ -126,7 +127,7 @@ public ClearCLBuffer getNeighborCountMap(ClearCLBuffer input_image, String metho

clij2.excludeLabelsOutsideSizeRange(size_limited_label_image, input_image, minSize, maxSize);

if(displayDebugImages) { BV3DBoxUtilities.pullAndDisplayImageFromGPU(clij2, input_image, true, LutNames.GLASBEY_LUT); }
if(displayDebugImages) { BV3DBoxUtilities.pullAndDisplayImageFromGPU(clij2, input_image, true, LutNames.GLASBEY_LUT, null); }

size_limited_label_image.close();
}
Expand All @@ -138,7 +139,7 @@ public ClearCLBuffer getNeighborCountMap(ClearCLBuffer input_image, String metho

clij2.extendLabelingViaVoronoi(input_image, voronoi_image);

if (displayDebugImages) { BV3DBoxUtilities.pullAndDisplayImageFromGPU(clij2, voronoi_image, false, LutNames.GLASBEY_LUT); }
if (displayDebugImages) { BV3DBoxUtilities.pullAndDisplayImageFromGPU(clij2, voronoi_image, false, LutNames.GLASBEY_LUT, null); }

if (method.equals(NeighborMethods.OBJECTS.method)) {

Expand Down Expand Up @@ -289,7 +290,7 @@ public static void main(String[] args) {

ImagePlus neighborCountMapImp = BV3DBoxUtilities.pullImageFromGPU(neighborAnalysis.getCurrentCLIJ2Instance(), neighbor_image, false, LutNames.GEEN_FIRE_BLUE_LUT);
neighborCountMapImp.setTitle(WindowManager.getUniqueName("NeighborCount_" + inputImagePlus.getTitle()));

neighborCountMapImp.setCalibration(inputImagePlus.getCalibration());
neighborCountMapImp.show();

if (plotNeighborCount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public class BV_ObjectInspector implements Cancelable {
private String secondary_MMER_range = "0.00-1.00";
private Boolean exclude_primary_objects_on_edges = true;
private Boolean pad_stack_tops = false;
private Boolean display_results_tables = true;
private Boolean display_analyzed_label_maps = false;
private Boolean show_count_map = false;

Expand Down Expand Up @@ -191,7 +192,8 @@ public void padStackTops(boolean pad_stack_tops) {
* @param display_analyzed_label_maps
* @param show_count_map
*/
public void setOutputImageFlags(boolean display_analyzed_label_maps, boolean show_count_map) {
public void setOutputImageFlags(boolean display_results_tables, boolean display_analyzed_label_maps, boolean show_count_map) {
this.display_results_tables = display_results_tables;
this.display_analyzed_label_maps = display_analyzed_label_maps;
this.show_count_map = show_count_map;
}
Expand All @@ -215,6 +217,7 @@ public void inspect() {
log.debug("secondary_MMDTCR_range = " + secondary_MMER_range);
log.debug("exclude_primary_objects_on_edges = " + exclude_primary_objects_on_edges);
log.debug("pad_stack_tops = " + pad_stack_tops);
log.debug("display_results_tables = " + display_results_tables);
log.debug("display_analyzed_label_maps = " + display_analyzed_label_maps);
log.debug("show_count_map = " + show_count_map);
log.debug("------------------------------------------------------");
Expand Down Expand Up @@ -474,7 +477,7 @@ public void inspect() {
final_primary_results_table.setColumn("SEC_OBJECT_COUNT", secondaryObjectCountArray);

if (show_count_map) {
BV3DBoxUtilities.pullAndDisplayImageFromGPU(clij2, overlapCountMap, true, LutNames.GEEN_FIRE_BLUE_LUT); //test output
BV3DBoxUtilities.pullAndDisplayImageFromGPU(clij2, overlapCountMap, true, LutNames.GEEN_FIRE_BLUE_LUT, voxel_calibration); //test output
}
overlapCountMap.close();

Expand Down Expand Up @@ -585,8 +588,8 @@ public void inspect() {


if (display_analyzed_label_maps) {
BV3DBoxUtilities.pullAndDisplayImageFromGPU(clij2, finalLabels_1, true, LutNames.GLASBEY_LUT);
BV3DBoxUtilities.pullAndDisplayImageFromGPU(clij2, finalLabels_2, true, LutNames.GLASBEY_LUT);
BV3DBoxUtilities.pullAndDisplayImageFromGPU(clij2, finalLabels_1, true, LutNames.GLASBEY_LUT, voxel_calibration);
BV3DBoxUtilities.pullAndDisplayImageFromGPU(clij2, finalLabels_2, true, LutNames.GLASBEY_LUT, voxel_calibration);
}
finalLabels_1.close();
finalLabels_2.close();
Expand Down Expand Up @@ -677,8 +680,10 @@ public void inspect() {

secondary_original_measurements_table = null;

final_primary_results_table.show(PRIMARY_RESULTS_TABLE_NAME);
final_secondary_results_table.show(SECONDARY_RESULTS_TABLE_NAME);
if (display_results_tables) {
final_primary_results_table.show(PRIMARY_RESULTS_TABLE_NAME);
final_secondary_results_table.show(SECONDARY_RESULTS_TABLE_NAME);
}

clij2.clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public void extract() {
ClearCLBuffer percent_volume_vector = clij2.push(percent_volume_image);
percent_volume_map.setName("%volume_" + image_plus_2.getTitle());
clij2.generateParametricImage(image_1_CCL, percent_volume_vector, percent_volume_map);
BV3DBoxUtilities.pullAndDisplayImageFromGPU(clij2, percent_volume_map, true, LutNames.GEEN_FIRE_BLUE_LUT);
BV3DBoxUtilities.pullAndDisplayImageFromGPU(clij2, percent_volume_map, true, LutNames.GEEN_FIRE_BLUE_LUT, image_plus_1.getCalibration());
percent_volume_map.close();
percent_volume_vector.close();
}
Expand All @@ -237,7 +237,7 @@ public void extract() {
ClearCLBuffer kept_image_1_CCL = clij2.create(image_1_CCL);
kept_image_1_CCL.setName("extracted_" + image_plus_1.getTitle());
clij2.excludeLabels(flag_list_vector, image_1_CCL, kept_image_1_CCL);
BV3DBoxUtilities.pullAndDisplayImageFromGPU(clij2, kept_image_1_CCL, true, LutNames.GEEN_FIRE_BLUE_LUT);
BV3DBoxUtilities.pullAndDisplayImageFromGPU(clij2, kept_image_1_CCL, true, LutNames.GEEN_FIRE_BLUE_LUT, image_plus_1.getCalibration());
flag_list_vector.close();
kept_image_1_CCL.close();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class BV_PostProcessor extends DynamicCommand {
private final PrefService prefs = new DefaultPrefService();
private static CLIJ2 clij2;
private ClearCLBuffer input_image;
private BV_LabelSeparator bvls = new BV_LabelSeparator();
// private BV_LabelSeparator bvls = new BV_LabelSeparator();

/**
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package de.biovoxxel.bv3dbox.plugins;

import java.awt.Point;

import org.scijava.Cancelable;
import org.scijava.log.LogLevel;
import org.scijava.log.LogService;
Expand All @@ -14,7 +12,6 @@
import de.biovoxxel.bv3dbox.utilities.BV3DBoxUtilities.LutNames;
import ij.ImagePlus;
import ij.WindowManager;
import ij.gui.ImageWindow;
import ij.measure.Calibration;
import net.haesleinhuepf.clij.clearcl.ClearCLBuffer;
import net.haesleinhuepf.clij.coremem.enums.NativeTypeEnum;
Expand Down Expand Up @@ -165,8 +162,7 @@ public void runCorrection(float radius, boolean force2D, boolean showBackgroundI

outputImagePlus.setImage(tempOutputImagePlus);
outputImagePlus.setTitle(outputImageName);
//ImageWindow inputImageWindow = inputImagePlus.getWindow();
//Point inputImageLocation = inputImageWindow.getLocationOnScreen();
outputImagePlus.setCalibration(inputImagePlus.getCalibration());
outputImagePlus.show();
//outputImagePlus.getWindow().setLocation(inputImageLocation.x + inputImageWindow.getWidth() + 10, inputImageLocation.y);
BV3DBoxUtilities.adaptImageDisplay(inputImagePlus, outputImagePlus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,19 +233,20 @@ public void applyThreshold(double thresholdValue) {

ImagePlus outputImagePlus = clij2.pullBinary(outputImage);
outputImagePlus.setTitle(outputImageName);
outputImagePlus.setCalibration(inputImagePlus.getCalibration());
outputImagePlus.show();

} else if (outputImageStyle.equals("0/1")) {

outputImage.setName(outputImageName);
BV3DBoxUtilities.pullAndDisplayImageFromGPU(clij2, outputImage, true, LutNames.GRAY);
BV3DBoxUtilities.pullAndDisplayImageFromGPU(clij2, outputImage, true, LutNames.GRAY, inputImagePlus.getCalibration());

} else {

ClearCLBuffer labelOutputImage = clij2.create(outputImage.getDimensions(), NativeTypeEnum.Float);
clij2.connectedComponentsLabelingBox(outputImage, labelOutputImage);
labelOutputImage.setName(outputImageName);
BV3DBoxUtilities.pullAndDisplayImageFromGPU(clij2, labelOutputImage, true, LutNames.GLASBEY_LUT);
BV3DBoxUtilities.pullAndDisplayImageFromGPU(clij2, labelOutputImage, true, LutNames.GLASBEY_LUT, inputImagePlus.getCalibration());
labelOutputImage.close();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public static String[] extendImageTitleListWithNone() {
}


public static void pullAndDisplayImageFromGPU(CLIJ2 clij2, ClearCLBuffer imageToShow, boolean autoContrast, LutNames lutName) {
public static void pullAndDisplayImageFromGPU(CLIJ2 clij2, ClearCLBuffer imageToShow, boolean autoContrast, LutNames lutName, Calibration cal) {

ImagePlus imagePlusToBePulled = clij2.pull(imageToShow);
imagePlusToBePulled.setTitle(imageToShow.getName());
Expand All @@ -198,6 +198,12 @@ public static void pullAndDisplayImageFromGPU(CLIJ2 clij2, ClearCLBuffer imageTo
} else {
imagePlusToBePulled.resetDisplayRange();
}

System.out.println("Calubration = " + cal);
if (cal != null) {
imagePlusToBePulled.setCalibration(cal);
}

imagePlusToBePulled.show();

}
Expand Down

0 comments on commit d58e52c

Please sign in to comment.