Skip to content

Commit 8dceb82

Browse files
committed
2024.11.06 (1.54m18; Hyperstack type conversions)
1 parent c80f6ef commit 8dceb82

File tree

6 files changed

+82
-28
lines changed

6 files changed

+82
-28
lines changed

ij/ImageJ.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public class ImageJ extends Frame implements ActionListener,
7979

8080
/** Plugins should call IJ.getVersion() or IJ.getFullVersion() to get the version string. */
8181
public static final String VERSION = "1.54m";
82-
public static final String BUILD = "16";
82+
public static final String BUILD = "18";
8383
public static Color backgroundColor = new Color(237,237,237);
8484
/** SansSerif, 12-point, plain font. */
8585
public static final Font SansSerif12 = new Font("SansSerif", Font.PLAIN, 12);

ij/plugin/ImageInfo.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ private String getInfo(ImagePlus imp, ImageProcessor ip) {
192192
String lut = getLutInfo(imp);
193193
s += "(" + lut + ")\n";
194194
if (imp.getNChannels()>1)
195-
s += displayRanges(imp);
195+
s += getDisplayRanges(imp);
196196
else {
197197
s += "Display range: "+(int)ip.getMin()+"-"+(int)ip.getMax()+"\n";
198198
ip.resetRoi();
@@ -207,7 +207,7 @@ private String getInfo(ImagePlus imp, ImageProcessor ip) {
207207
} else
208208
s += "Bits per pixel: 32 (float, "+getLutInfo(imp)+")\n";
209209
if (imp.getNChannels()>1)
210-
s += displayRanges(imp);
210+
s += getDisplayRanges(imp);
211211
else {
212212
String pvrLabel = "Pixel value range: ";
213213
s += "Display range: ";
@@ -494,7 +494,7 @@ private String getLutInfo(ImagePlus imp) {
494494
return lut;
495495
}
496496

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

532-
private String d2s(double n) {
532+
private static String d2s(double n) {
533533
return IJ.d2s(n,Tools.getDecimalPlaces(n));
534534
}
535535

ij/plugin/Orthogonal_Views.java

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class Orthogonal_Views implements PlugIn, MouseListener, MouseMotionListe
5353
private boolean initialized;
5454
private boolean sliceSet;
5555
private Thread thread;
56+
final static String CROSS = "|OV|";
5657

5758

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

564565
}
565566

566-
/** draws the crosses in the images */
567+
/** draws the crosses on the images */
567568
void drawCross(ImagePlus imp, Point p, GeneralPath path) {
568569
int width=imp.getWidth();
569570
int height=imp.getHeight();
@@ -580,7 +581,17 @@ void dispose() {
580581
done = true;
581582
notify();
582583
}
583-
imp.setOverlay(null);
584+
Overlay overlay = imp.getOverlay();
585+
if (overlay!=null) {
586+
overlay.remove(CROSS);
587+
ImageCanvas ic = imp.getCanvas();
588+
if (ic!=null)
589+
ic.setCustomRoi(true);
590+
if (overlay.size()==0)
591+
imp.setOverlay(null);
592+
else
593+
imp.draw();
594+
}
584595
if (canvas!=null) {
585596
canvas.removeMouseListener(this);
586597
canvas.removeMouseMotionListener(this);
@@ -747,15 +758,30 @@ private void exec() {
747758
updateViews(p, is);
748759
GeneralPath path = new GeneralPath();
749760
drawCross(imp, p, path);
750-
if (!done)
751-
imp.setOverlay(path, color, new BasicStroke(1));
761+
if (!done) {
762+
if (imp.getOverlay()==null)
763+
imp.setOverlay(new Overlay());
764+
setOverlay(imp, path);
765+
}
752766
canvas.setCustomRoi(true);
753767
updateCrosses(p.x, p.y, arat, brat);
754768
if (syncZoom) updateMagnification(p.x, p.y);
755769
arrangeWindows(sticky);
756770
initialized = true;
757771
}
758772

773+
private void setOverlay(ImagePlus imp, GeneralPath path) {
774+
Overlay overlay = imp.getOverlay();
775+
if (overlay==null)
776+
overlay = new Overlay();
777+
Roi roi = new ShapeRoi(path);
778+
roi.setStrokeColor(color);
779+
roi.setStroke(new BasicStroke(1));
780+
overlay.remove(CROSS);
781+
overlay.add(roi, CROSS);
782+
imp.setOverlay(overlay);
783+
}
784+
759785
private void updateCrosses(int x, int y, double arat, double brat) {
760786
Point p;
761787
int z=imp.getNSlices();
@@ -768,7 +794,7 @@ private void updateCrosses(int x, int y, double arat, double brat) {
768794
GeneralPath path = new GeneralPath();
769795
drawCross(xz_image, p, path);
770796
if (!done)
771-
xz_image.setOverlay(path, color, new BasicStroke(1));
797+
setOverlay(xz_image, path);
772798
if (rotateYZ) {
773799
if (flipXZ)
774800
zcoord=(int)Math.round(brat*(z-zlice));
@@ -782,7 +808,7 @@ private void updateCrosses(int x, int y, double arat, double brat) {
782808
path = new GeneralPath();
783809
drawCross(yz_image, p, path);
784810
if (!done)
785-
yz_image.setOverlay(path, color, new BasicStroke(1));
811+
setOverlay(yz_image, path);
786812
IJ.showStatus(imp.getLocationAsString(crossLoc.x, crossLoc.y));
787813
}
788814

ij/process/StackConverter.java

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import ij.*;
66
import ij.gui.*;
77
import ij.measure.*;
8-
import ij.plugin.RGBStackConverter;
8+
import ij.plugin.*;
99

1010
/** This class does stack type conversions. */
1111
public class StackConverter {
@@ -57,6 +57,7 @@ public void convertToGray8() {
5757
int inc = nSlices/20;
5858
if (inc<1) inc = 1;
5959
LUT[] luts = composite?((CompositeImage)imp).getLuts():null;
60+
boolean scale = ImageConverter.getDoScaling();
6061
for(int i=1; i<=nSlices; i++) {
6162
label = stack1.getSliceLabel(1);
6263
ip = stack1.getProcessor(1);
@@ -67,7 +68,6 @@ public void convertToGray8() {
6768
max = luts[index].max;
6869
}
6970
ip.setMinAndMax(min, max);
70-
boolean scale = ImageConverter.getDoScaling();
7171
stack2.addSlice(label, ip.convertToByte(scale));
7272
if ((i%inc)==0) {
7373
IJ.showProgress((double)i/nSlices);
@@ -76,9 +76,14 @@ public void convertToGray8() {
7676
}
7777
imp.setStack(null, stack2);
7878
imp.setCalibration(imp.getCalibration()); //update calibration
79-
if (imp.isComposite()) {
80-
((CompositeImage)imp).resetDisplayRanges();
81-
((CompositeImage)imp).updateAllChannelsAndDraw();
79+
if (composite && luts!=null) {
80+
if (scale) {
81+
for (int i=0; i<luts.length; i++) {
82+
luts[i].min = 0;
83+
luts[i].max = 255;
84+
}
85+
}
86+
((CompositeImage)imp).setLuts(luts);
8287
}
8388
ImageConverter.record();
8489
imp.setSlice(currentSlice);
@@ -99,7 +104,7 @@ void convertRGBToGray8() {
99104
String label;
100105
int inc = nSlices/20;
101106
if (inc<1) inc = 1;
102-
for(int i=1; i<=nSlices; i++) {
107+
for (int i=1; i<=nSlices; i++) {
103108
label = stack1.getSliceLabel(1);
104109
ip = stack1.getProcessor(1);
105110
stack1.deleteSlice(1);
@@ -116,7 +121,7 @@ void convertRGBToGray8() {
116121
IJ.showProgress(1.0);
117122
}
118123

119-
/** Converts this Stack to 16-bit grayscale. */
124+
/** Converts this Stack to 16-bit grayscale. */
120125
public void convertToGray16() {
121126
if (type==ImagePlus.GRAY16)
122127
return;
@@ -126,6 +131,9 @@ public void convertToGray16() {
126131
ImageConverter.convertAndCalibrate(imp,"16-bit");
127132
return;
128133
}
134+
ImageProcessor ip = imp.getProcessor();
135+
double min = ip.getMin();
136+
double max = ip.getMax();
129137
ImageStack stack1 = imp.getStack();
130138
ImageStack stack2 = new ImageStack(width, height);
131139
int channels = imp.getNChannels();
@@ -137,13 +145,15 @@ public void convertToGray16() {
137145
if (inc<1) inc = 1;
138146
boolean scale = type==ImagePlus.GRAY32 && ImageConverter.getDoScaling();
139147
ImageProcessor ip1, ip2;
140-
for(int i=1; i<=nSlices; i++) {
148+
for (int i=1; i<=nSlices; i++) {
141149
label = stack1.getSliceLabel(1);
142150
ip1 = stack1.getProcessor(1);
143151
if (luts!=null) {
144-
int index = ((i-1)%channels);
145-
ip1.setMinAndMax(luts[index].min,luts[index].max);
152+
int index = (i-1)%luts.length;
153+
min = luts[index].min;
154+
max = luts[index].max;
146155
}
156+
ip1.setMinAndMax(min, max);
147157
ip2 = ip1.convertToShort(scale);
148158
stack1.deleteSlice(1);
149159
stack2.addSlice(label, ip2);
@@ -154,13 +164,16 @@ public void convertToGray16() {
154164
}
155165
IJ.showProgress(1.0);
156166
imp.setStack(null, stack2);
157-
if (scale) {
158-
for (int c=channels; c>=1; c--) {
159-
imp.setPosition(c,imp.getSlice(),imp.getFrame());
160-
imp.setDisplayRange(0,65535);
167+
if (imp.isComposite() && luts!=null) {
168+
if (scale) {
169+
for (int i=0; i<luts.length; i++) {
170+
luts[i].min = 0;
171+
luts[i].max = 65535;
172+
}
161173
}
174+
((CompositeImage)imp).setLuts(luts);
175+
imp.updateAndDraw();
162176
}
163-
ImageConverter.record();
164177
}
165178

166179
/** Converts this Stack to 32-bit (float) grayscale. */
@@ -176,6 +189,12 @@ public void convertToGray32() {
176189
if (inc<1) inc = 1;
177190
ImageProcessor ip1, ip2;
178191
Calibration cal = imp.getCalibration();
192+
double min = imp.getDisplayRangeMin();
193+
double max = imp.getDisplayRangeMax();
194+
int channels = imp.getNChannels();
195+
LUT[] luts = imp.getLuts();
196+
if ((luts!=null && luts.length!=channels) || cal.calibrated())
197+
luts = null;
179198
for(int i=1; i<=nSlices; i++) {
180199
label = stack1.getSliceLabel(1);
181200
ip1 = stack1.getProcessor(1);
@@ -195,6 +214,11 @@ public void convertToGray32() {
195214
imp.resetDisplayRange();
196215
imp.updateAndDraw();
197216
}
217+
if (imp.isHyperStack() && luts!=null)
218+
((CompositeImage)imp).setLuts(luts);
219+
else if (!cal.calibrated())
220+
imp.setDisplayRange(min, max);
221+
198222
}
199223

200224
/** Converts the Stack to RGB. */

ij/process/TypeConverter.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,13 @@ FloatProcessor convertShortToFloat(float[] cTable) {
235235
if (cTable!=null && cTable.length==65536)
236236
for (int i=0; i<width*height; i++)
237237
pixels32[i] = cTable[pixels16[i]&0xffff];
238-
else
238+
else {
239239
for (int i=0; i<width*height; i++)
240240
pixels32[i] = pixels16[i]&0xffff;
241+
}
241242
ColorModel cm = ip.getColorModel();
242-
return new FloatProcessor(width, height, pixels32, cm);
243+
FloatProcessor fp = new FloatProcessor(width, height, pixels32, cm);
244+
return fp;
243245
}
244246

245247
/** Converts processor to a ColorProcessor. */

release-notes.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

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

0 commit comments

Comments
 (0)