Skip to content

Commit

Permalink
2024.11.06 (1.54m18; Hyperstack type conversions)
Browse files Browse the repository at this point in the history
  • Loading branch information
rasband committed Nov 7, 2024
1 parent c80f6ef commit 8dceb82
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 28 deletions.
2 changes: 1 addition & 1 deletion ij/ImageJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class ImageJ extends Frame implements ActionListener,

/** 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 = "16";
public static final String BUILD = "18";
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
8 changes: 4 additions & 4 deletions ij/plugin/ImageInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ private String getInfo(ImagePlus imp, ImageProcessor ip) {
String lut = getLutInfo(imp);
s += "(" + lut + ")\n";
if (imp.getNChannels()>1)
s += displayRanges(imp);
s += getDisplayRanges(imp);
else {
s += "Display range: "+(int)ip.getMin()+"-"+(int)ip.getMax()+"\n";
ip.resetRoi();
Expand All @@ -207,7 +207,7 @@ private String getInfo(ImagePlus imp, ImageProcessor ip) {
} else
s += "Bits per pixel: 32 (float, "+getLutInfo(imp)+")\n";
if (imp.getNChannels()>1)
s += displayRanges(imp);
s += getDisplayRanges(imp);
else {
String pvrLabel = "Pixel value range: ";
s += "Display range: ";
Expand Down Expand Up @@ -494,7 +494,7 @@ private String getLutInfo(ImagePlus imp) {
return lut;
}

private String displayRanges(ImagePlus imp) {
public static String getDisplayRanges(ImagePlus imp) {
LUT[] luts = imp.getLuts();
if (luts==null)
return "";
Expand Down Expand Up @@ -529,7 +529,7 @@ private void showInfo(ImagePlus imp, String info, int width, int height) {
//ed.create("Info for "+imp.getTitle(), info);
}

private String d2s(double n) {
private static String d2s(double n) {
return IJ.d2s(n,Tools.getDecimalPlaces(n));
}

Expand Down
38 changes: 32 additions & 6 deletions ij/plugin/Orthogonal_Views.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class Orthogonal_Views implements PlugIn, MouseListener, MouseMotionListe
private boolean initialized;
private boolean sliceSet;
private Thread thread;
final static String CROSS = "|OV|";


public void run(String arg) {
Expand Down Expand Up @@ -563,7 +564,7 @@ void updateZYView(Point p, ImageStack is) {

}

/** draws the crosses in the images */
/** draws the crosses on the images */
void drawCross(ImagePlus imp, Point p, GeneralPath path) {
int width=imp.getWidth();
int height=imp.getHeight();
Expand All @@ -580,7 +581,17 @@ void dispose() {
done = true;
notify();
}
imp.setOverlay(null);
Overlay overlay = imp.getOverlay();
if (overlay!=null) {
overlay.remove(CROSS);
ImageCanvas ic = imp.getCanvas();
if (ic!=null)
ic.setCustomRoi(true);
if (overlay.size()==0)
imp.setOverlay(null);
else
imp.draw();
}
if (canvas!=null) {
canvas.removeMouseListener(this);
canvas.removeMouseMotionListener(this);
Expand Down Expand Up @@ -747,15 +758,30 @@ private void exec() {
updateViews(p, is);
GeneralPath path = new GeneralPath();
drawCross(imp, p, path);
if (!done)
imp.setOverlay(path, color, new BasicStroke(1));
if (!done) {
if (imp.getOverlay()==null)
imp.setOverlay(new Overlay());
setOverlay(imp, path);
}
canvas.setCustomRoi(true);
updateCrosses(p.x, p.y, arat, brat);
if (syncZoom) updateMagnification(p.x, p.y);
arrangeWindows(sticky);
initialized = true;
}

private void setOverlay(ImagePlus imp, GeneralPath path) {
Overlay overlay = imp.getOverlay();
if (overlay==null)
overlay = new Overlay();
Roi roi = new ShapeRoi(path);
roi.setStrokeColor(color);
roi.setStroke(new BasicStroke(1));
overlay.remove(CROSS);
overlay.add(roi, CROSS);
imp.setOverlay(overlay);
}

private void updateCrosses(int x, int y, double arat, double brat) {
Point p;
int z=imp.getNSlices();
Expand All @@ -768,7 +794,7 @@ private void updateCrosses(int x, int y, double arat, double brat) {
GeneralPath path = new GeneralPath();
drawCross(xz_image, p, path);
if (!done)
xz_image.setOverlay(path, color, new BasicStroke(1));
setOverlay(xz_image, path);
if (rotateYZ) {
if (flipXZ)
zcoord=(int)Math.round(brat*(z-zlice));
Expand All @@ -782,7 +808,7 @@ private void updateCrosses(int x, int y, double arat, double brat) {
path = new GeneralPath();
drawCross(yz_image, p, path);
if (!done)
yz_image.setOverlay(path, color, new BasicStroke(1));
setOverlay(yz_image, path);
IJ.showStatus(imp.getLocationAsString(crossLoc.x, crossLoc.y));
}

Expand Down
54 changes: 39 additions & 15 deletions ij/process/StackConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import ij.*;
import ij.gui.*;
import ij.measure.*;
import ij.plugin.RGBStackConverter;
import ij.plugin.*;

/** This class does stack type conversions. */
public class StackConverter {
Expand Down Expand Up @@ -57,6 +57,7 @@ public void convertToGray8() {
int inc = nSlices/20;
if (inc<1) inc = 1;
LUT[] luts = composite?((CompositeImage)imp).getLuts():null;
boolean scale = ImageConverter.getDoScaling();
for(int i=1; i<=nSlices; i++) {
label = stack1.getSliceLabel(1);
ip = stack1.getProcessor(1);
Expand All @@ -67,7 +68,6 @@ public void convertToGray8() {
max = luts[index].max;
}
ip.setMinAndMax(min, max);
boolean scale = ImageConverter.getDoScaling();
stack2.addSlice(label, ip.convertToByte(scale));
if ((i%inc)==0) {
IJ.showProgress((double)i/nSlices);
Expand All @@ -76,9 +76,14 @@ public void convertToGray8() {
}
imp.setStack(null, stack2);
imp.setCalibration(imp.getCalibration()); //update calibration
if (imp.isComposite()) {
((CompositeImage)imp).resetDisplayRanges();
((CompositeImage)imp).updateAllChannelsAndDraw();
if (composite && luts!=null) {
if (scale) {
for (int i=0; i<luts.length; i++) {
luts[i].min = 0;
luts[i].max = 255;
}
}
((CompositeImage)imp).setLuts(luts);
}
ImageConverter.record();
imp.setSlice(currentSlice);
Expand All @@ -99,7 +104,7 @@ void convertRGBToGray8() {
String label;
int inc = nSlices/20;
if (inc<1) inc = 1;
for(int i=1; i<=nSlices; i++) {
for (int i=1; i<=nSlices; i++) {
label = stack1.getSliceLabel(1);
ip = stack1.getProcessor(1);
stack1.deleteSlice(1);
Expand All @@ -116,7 +121,7 @@ void convertRGBToGray8() {
IJ.showProgress(1.0);
}

/** Converts this Stack to 16-bit grayscale. */
/** Converts this Stack to 16-bit grayscale. */
public void convertToGray16() {
if (type==ImagePlus.GRAY16)
return;
Expand All @@ -126,6 +131,9 @@ public void convertToGray16() {
ImageConverter.convertAndCalibrate(imp,"16-bit");
return;
}
ImageProcessor ip = imp.getProcessor();
double min = ip.getMin();
double max = ip.getMax();
ImageStack stack1 = imp.getStack();
ImageStack stack2 = new ImageStack(width, height);
int channels = imp.getNChannels();
Expand All @@ -137,13 +145,15 @@ public void convertToGray16() {
if (inc<1) inc = 1;
boolean scale = type==ImagePlus.GRAY32 && ImageConverter.getDoScaling();
ImageProcessor ip1, ip2;
for(int i=1; i<=nSlices; i++) {
for (int i=1; i<=nSlices; i++) {
label = stack1.getSliceLabel(1);
ip1 = stack1.getProcessor(1);
if (luts!=null) {
int index = ((i-1)%channels);
ip1.setMinAndMax(luts[index].min,luts[index].max);
int index = (i-1)%luts.length;
min = luts[index].min;
max = luts[index].max;
}
ip1.setMinAndMax(min, max);
ip2 = ip1.convertToShort(scale);
stack1.deleteSlice(1);
stack2.addSlice(label, ip2);
Expand All @@ -154,13 +164,16 @@ public void convertToGray16() {
}
IJ.showProgress(1.0);
imp.setStack(null, stack2);
if (scale) {
for (int c=channels; c>=1; c--) {
imp.setPosition(c,imp.getSlice(),imp.getFrame());
imp.setDisplayRange(0,65535);
if (imp.isComposite() && luts!=null) {
if (scale) {
for (int i=0; i<luts.length; i++) {
luts[i].min = 0;
luts[i].max = 65535;
}
}
((CompositeImage)imp).setLuts(luts);
imp.updateAndDraw();
}
ImageConverter.record();
}

/** Converts this Stack to 32-bit (float) grayscale. */
Expand All @@ -176,6 +189,12 @@ public void convertToGray32() {
if (inc<1) inc = 1;
ImageProcessor ip1, ip2;
Calibration cal = imp.getCalibration();
double min = imp.getDisplayRangeMin();
double max = imp.getDisplayRangeMax();
int channels = imp.getNChannels();
LUT[] luts = imp.getLuts();
if ((luts!=null && luts.length!=channels) || cal.calibrated())
luts = null;
for(int i=1; i<=nSlices; i++) {
label = stack1.getSliceLabel(1);
ip1 = stack1.getProcessor(1);
Expand All @@ -195,6 +214,11 @@ public void convertToGray32() {
imp.resetDisplayRange();
imp.updateAndDraw();
}
if (imp.isHyperStack() && luts!=null)
((CompositeImage)imp).setLuts(luts);
else if (!cal.calibrated())
imp.setDisplayRange(min, max);

}

/** Converts the Stack to RGB. */
Expand Down
6 changes: 4 additions & 2 deletions ij/process/TypeConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,13 @@ FloatProcessor convertShortToFloat(float[] cTable) {
if (cTable!=null && cTable.length==65536)
for (int i=0; i<width*height; i++)
pixels32[i] = cTable[pixels16[i]&0xffff];
else
else {
for (int i=0; i<width*height; i++)
pixels32[i] = pixels16[i]&0xffff;
}
ColorModel cm = ip.getColorModel();
return new FloatProcessor(width, height, pixels32, cm);
FloatProcessor fp = new FloatProcessor(width, height, pixels32, cm);
return fp;
}

/** Converts processor to a ColorProcessor. */
Expand Down
2 changes: 2 additions & 0 deletions release-notes.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

<li> <u>1.54m16 28 October 2024</u>
<ul>
<li> Thanks to Michael Cammer, the <i>Orthogonal Views</i> command
no longer removes overlays.
<li> Thanks to 'Patricia' and Herbie Gluender, the
<i>Image&gt;Transform&gt;Image to Results</i> command
now shows NaNs when values are outside non-rectangular
Expand Down

0 comments on commit 8dceb82

Please sign in to comment.