Skip to content

Commit

Permalink
2024.12.17 (1.54n4; Combine and Straighten)
Browse files Browse the repository at this point in the history
  • Loading branch information
rasband committed Dec 17, 2024
1 parent 7257bdd commit 63544da
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 7 deletions.
4 changes: 2 additions & 2 deletions ij/ImageJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public class ImageJ extends Frame implements ActionListener,
MouseListener, KeyListener, WindowListener, ItemListener, Runnable {

/** Plugins should call IJ.getVersion() or IJ.getFullVersion() to get the version string. */
public static final String VERSION = "1.54m";
public static final String BUILD = ""; //37
public static final String VERSION = "1.54n";
public static final String BUILD = "4";
public static Color backgroundColor = new Color(237,237,237);
/** SansSerif, 12-point, plain font. */
public static final Font SansSerif12 = new Font("SansSerif", Font.PLAIN, 12);
Expand Down
19 changes: 17 additions & 2 deletions ij/plugin/StackCombiner.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import ij.*;
import ij.process.*;
import ij.gui.*;
import ij.io.FileInfo;
import java.awt.*;

/**
Expand All @@ -24,14 +25,25 @@ public void run(String arg) {
error();
return;
}
imp1.setDisplayMode(IJ.COLOR);
imp2.setDisplayMode(IJ.COLOR);
if (LUT.LutsDiffer(imp1,imp2)) {
RGBStackConverter.convertToRGB(imp1);
RGBStackConverter.convertToRGB(imp2);
}
int[] dim1 = imp1.getDimensions();
int[] dim2 = imp2.getDimensions();
boolean isHyperStack1 = imp1.isHyperStack() || imp1.isComposite();
boolean isHyperStack2 = imp2.isHyperStack() || imp2.isComposite();
if (imp1.isHyperStack() || imp2.isHyperStack()) {
if (dim1[2]!=dim2[2] || dim1[3]!=dim2[3] || dim1[4]!=dim2[4]) {
IJ.error("StackCombiner", "Hyperstacks must have identical CZT dimensions");
return;
}
}
LUT[] luts = null;
if (imp1.isComposite())
luts = imp1.getLuts();
ImageStack stack1 = imp1.getStack();
ImageStack stack2 = imp2.getStack();
ImageStack stack3 = vertical?combineVertically(stack1, stack2):combineHorizontally(stack1, stack2);
Expand All @@ -41,16 +53,19 @@ public void run(String arg) {
imp2.close();
ImagePlus imp3 = imp1.createImagePlus();
imp3.setStack(stack3);
if (imp1.isHyperStack())
if (isHyperStack1)
imp3.setDimensions(dim1[2],dim1[3],dim1[4]);
if (imp1.isComposite()) {
imp3 = new CompositeImage(imp3, imp1.getCompositeMode());
imp3.setDimensions(dim1[2],dim1[3],dim1[4]);
if (luts!=null)
((CompositeImage)imp3).setLuts(luts);
((CompositeImage)imp3).resetDisplayRanges();
}
imp3.setTitle("Combined Stacks");
imp3.show();
}

public ImageStack combineHorizontally(ImageStack stack1, ImageStack stack2) {
int d1 = stack1.getSize();
int d2 = stack2.getSize();
Expand Down
27 changes: 25 additions & 2 deletions ij/plugin/Straightener.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ public void run(String arg) {
int width = (int)Math.round(roi.getStrokeWidth());
boolean isMacro = IJ.macroRunning() && Macro.getOptions()!=null;
int stackSize = imp.getStackSize();
if (stackSize==1) processStack = false;
if (stackSize==1)
processStack = false;
if (imp.isComposite())
processStack = true;
String newTitle = WindowManager.getUniqueName(imp.getTitle());
if (width<=1 || isMacro || stackSize>1) {
if (width<=1) width = 20;
Expand All @@ -49,8 +52,21 @@ public void run(String arg) {
ImageProcessor ip2 = null;
ImagePlus imp2 = null;
if (processStack) {
boolean compositeMode = imp.isComposite() && imp.getDisplayMode()==IJ.COMPOSITE;
if (compositeMode)
imp.setDisplayMode(IJ.COLOR);
ImageStack stack2 = straightenStack(imp, roi, width);
imp2 = new ImagePlus(newTitle, stack2);
if (compositeMode)
imp.setDisplayMode(IJ.COMPOSITE);
if (imp.isComposite()) {
ImageConverter.setDoScaling(false);
if (imp.getBitDepth()==8)
new StackConverter(imp2).convertToGray8();
else if (imp.getBitDepth()==16)
new StackConverter(imp2).convertToGray16();
ImageConverter.setDoScaling(true);
}
} else {
ip2 = straighten(imp, roi, width);
imp2 = new ImagePlus(newTitle, ip2);
Expand All @@ -61,7 +77,14 @@ public void run(String arg) {
Calibration cal = imp.getCalibration();
if (cal.pixelWidth==cal.pixelHeight)
imp2.setCalibration(cal);
imp2.show();
if (imp.isComposite()) {
LUT[] luts = imp.getLuts();
CompositeImage cImp = new CompositeImage(imp2);
cImp.setLuts(luts);
cImp.setDisplayMode(imp.getDisplayMode());
cImp.show();
} else
imp2.show();
}

public ImageProcessor straighten(ImagePlus imp, Roi roi, int width) {
Expand Down
29 changes: 28 additions & 1 deletion ij/process/LUT.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package ij.process;
import ij.IJ;
import ij.*;
import ij.plugin.Colors;
import java.awt.image.*;
import java.awt.Color;
Expand Down Expand Up @@ -107,5 +107,32 @@ public String toString() {
return "rgb[0]="+Colors.colorToString(new Color(getRGB(0)))+", rgb[255]="
+Colors.colorToString(new Color(getRGB(255)))+", min="+IJ.d2s(min,4)+", max="+IJ.d2s(max,4);
}

/** Returns 'true' if the LUTs of these two images differ. */
public static boolean LutsDiffer(ImagePlus imp1, ImagePlus imp2) {
if (!imp1.isComposite() || !imp2.isComposite())
return false;
LUT[] luts1 = ((CompositeImage)imp1).getLuts();
LUT[] luts2 = ((CompositeImage)imp2).getLuts();
if (luts1==null || luts2==null)
return false;
if (luts1.length!=luts2.length)
return true;
for (int i=0; i<luts1.length; i++) {
if (luts1[i].min!=luts2[i].min)
return true;
if (luts1[i].max!=luts2[i].max)
return true;
byte[] bytes1 = luts1[i].getBytes();
byte[] bytes2 = luts2[i].getBytes();
if (bytes1.length!=bytes2.length)
return true;
for (int j=0; j<bytes1.length; j++) {
if (bytes1[j]!=bytes2[j])
return true;
}
}
return false;
}

}
8 changes: 8 additions & 0 deletions release-notes.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
<body>


<li> <u>1.54n4 17 December 2024</u>
<ul>
<li> Thanks to Christophe Leterrier, fixed bugs with how
the <i>Image&gt;Stacks&gt;Tools&gt;Combine</i> and
<i>Edit&gt;Selection&gt;Straighten</i> commands handle
multi-channel images.
</ul>

<li> <u>1.54m 5 December 2024</u>
<ul>
<li> Thanks to Michael Cammer, the <i>Orthogonal Views</i> command
Expand Down

0 comments on commit 63544da

Please sign in to comment.