Skip to content

Commit

Permalink
2020.06.02 (1.53c3; Duplicator bug fixes)
Browse files Browse the repository at this point in the history
  • Loading branch information
rasband committed Jun 3, 2020
1 parent b24916c commit d8d921a
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 25 deletions.
2 changes: 1 addition & 1 deletion ij/ImageJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,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.53c";
public static final String BUILD = "1";
public static final String BUILD = "3";
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
28 changes: 14 additions & 14 deletions ij/ImagePlus.java
Original file line number Diff line number Diff line change
Expand Up @@ -2402,7 +2402,7 @@ public ImagePlus crop() {
}

/** Returns a cropped copy this image or stack, where 'options'
* can be "stack", "slice" or a range (e.g., "20-30").
* can be "stack", "slice", "whole-slice" or a range (e.g., "20-30").
* @see #duplicate
* @see #crop
* @see ij.plugin.Duplicator#crop
Expand All @@ -2412,7 +2412,13 @@ public ImagePlus crop(String options) {
int stackSize = getStackSize();
if (options==null || options.equals("stack"))
return (new Duplicator()).run(this);
else if (options.equals("slice") || stackSize==1)
else if (options.contains("whole") || stackSize==1) {
Roi saveRoi = getRoi();
deleteRoi();
ImagePlus imp2 = crop();
setRoi(saveRoi);
return imp2;
} else if (options.equals("slice") || stackSize==1)
return crop();
else {
String[] range = Tools.split(options, " -");
Expand Down Expand Up @@ -2899,30 +2905,24 @@ public void updatePosition(int c, int z, int t) {
position[2] = t;
}

/** Returns a "flattened" version of this image, in RGB format. */
/** Returns a "flattened" version of this image, or stack slice, in RGB format. */
public ImagePlus flatten() {
if (IJ.debugMode) IJ.log("flatten");
ImagePlus imp2 = createImagePlus();
ImagePlus impCopy = this;
if (getStackSize()>1)
impCopy = crop("whole-slice");
ImagePlus imp2 = impCopy.createImagePlus();
imp2.setOverlay(impCopy.getOverlay());
imp2.setTitle(flattenTitle);
ImageCanvas ic2 = new ImageCanvas(imp2);
imp2.flatteningCanvas = ic2;
imp2.setRoi(getRoi());
if (getStackSize()>1) {
imp2.setStack(getStack());
imp2.setSlice(getCurrentSlice());
if (isHyperStack()) {
imp2.setDimensions(getNChannels(),getNSlices(),getNFrames());
imp2.setPosition(getChannel(),getSlice(),getFrame());
imp2.setOpenAsHyperStack(true);
}
}
Overlay overlay2 = getOverlay();
if (overlay2!=null && imp2.getRoi()!=null) {
imp2.deleteRoi();
if (getWindow()!=null) IJ.wait(100);
}
setPointScale(imp2.getRoi(), overlay2);
imp2.setOverlay(overlay2);
ImageCanvas ic = getCanvas();
if (ic!=null)
ic2.setShowAllList(ic.getShowAllList());
Expand Down
14 changes: 14 additions & 0 deletions ij/gui/Overlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,20 @@ else if (toTStack)
}
}

public void crop2(int firstC, int lastC, int firstZ, int lastZ, int firstT, int lastT) {
for (int i=size()-1; i>=0; i--) {
Roi roi = get(i);
int c = roi.getCPosition();
int z = roi.getZPosition();
int t = roi.getTPosition();
IJ.log("crop: "+i+" "+c+" "+z+" "+t+firstC+" "+lastC+" "+firstZ+" "+lastZ+" "+firstT+" "+lastT);
if ((c>0&&(c<firstC||c>lastC)) || (z>0&&(z<firstZ||z>lastZ)) || (t>0&&(t<firstT||t>lastT))) {
remove(i);
IJ.log(" remove");
}
}
}

/** Returns the bounds of this overlay. */
/*
public Rectangle getBounds() {
Expand Down
7 changes: 5 additions & 2 deletions ij/plugin/Clipboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,11 @@ public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorExcepti
if (imp==null)
return null;
Roi roi = imp.getRoi();
if (roi!=null && !roi.isLine())
imp = imp.crop();
if (roi!=null && !roi.isLine()) {
Rectangle bounds = roi.getBounds();
if (!(bounds.x==0&&bounds.y==0&&bounds.width==imp.getWidth()&&bounds.height==imp.getHeight()))
imp = imp.crop();
}
boolean overlay = imp.getOverlay()!=null && !imp.getHideOverlay();
if (overlay && !imp.tempOverlay())
imp = imp.flatten();
Expand Down
32 changes: 25 additions & 7 deletions ij/plugin/Duplicator.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void run(String arg) {
return;
}
ImagePlus imp2;
Roi roi = imp.getRoi();
Roi roi = imp.getRoi();
if (duplicateStack && (first>1||last<stackSize))
imp2 = run(imp, first, last);
else if (duplicateStack || imp.getStackSize()==1) {
Expand Down Expand Up @@ -258,8 +258,9 @@ public ImagePlus run(ImagePlus imp) {
return imp2;
}

/** Returns a copy the current stack image, cropped if there is a selection.
/** Returns a copy the current image or stack slice, cropped if there is a selection.
* @see ij.ImagePlus#crop
* @see ij.ImagePlus#crop(String)
*/
public ImagePlus crop(ImagePlus imp) {
//if (imp!=null) throw new IllegalArgumentException();
Expand All @@ -268,6 +269,8 @@ public ImagePlus crop(ImagePlus imp) {
int t = imp.getFrame();
return run(imp, 1, imp.getNChannels(), z, z, t, t);
}
boolean hyperstack = imp.isHyperStack();
int displayMode = imp.isComposite()?imp.getDisplayMode():0;
ImageProcessor ip = imp.getProcessor();
ImageProcessor ip2 = ip.crop();
ImagePlus imp2 = imp.createImagePlus();
Expand All @@ -287,7 +290,10 @@ public ImagePlus crop(ImagePlus imp) {
}
if (imp.isComposite()) {
LUT lut = ((CompositeImage)imp).getChannelLut();
imp2.getProcessor().setColorModel(lut);
if (displayMode==IJ.GRAYSCALE)
imp2.getProcessor().setColorModel(null);
else
imp2.getProcessor().setColorModel(lut);
}
} else {
String label = (String)imp.getProperty("Label");
Expand All @@ -297,10 +303,19 @@ public ImagePlus crop(ImagePlus imp) {
Overlay overlay = imp.getOverlay();
if (overlay!=null && !imp.getHideOverlay()) {
Overlay overlay2 = overlay.crop(ip.getRoi());
if (imp.getStackSize()>1)
overlay2.crop(imp.getCurrentSlice(), imp.getCurrentSlice());
if (imp.getStackSize()>1) {
if (hyperstack) {
int c = imp.getC();
int z = imp.getZ();
int t = imp.getT();
overlay2.crop(c,c,z,z,t,t);
} else
overlay2.crop(imp.getCurrentSlice(), imp.getCurrentSlice());
}
imp2.setOverlay(overlay2);
}
if (displayMode>0)
imp2.setDisplayMode(displayMode);
return imp2;
}

Expand Down Expand Up @@ -382,7 +397,7 @@ public ImagePlus run(ImagePlus imp, int firstC, int lastC, int firstZ, int lastZ
imp2.setStack("DUP_"+imp.getTitle(), stack2);
imp2.setDimensions(lastC-firstC+1, lastZ-firstZ+1, lastT-firstT+1);
if (imp.isComposite()) {
int mode = ((CompositeImage)imp).getMode();
int mode =imp.getDisplayMode();
if (lastC>firstC) {
imp2 = new CompositeImage(imp2, mode);
int i2 = 1;
Expand All @@ -400,7 +415,10 @@ public ImagePlus run(ImagePlus imp, int firstC, int lastC, int firstZ, int lastZ
}
} else if (firstC==lastC) {
LUT lut = ((CompositeImage)imp).getChannelLut(firstC);
imp2.getProcessor().setColorModel(lut);
if (mode==IJ.GRAYSCALE)
imp2.getProcessor().setColorModel(null);
else
imp2.getProcessor().setColorModel(lut);
imp2.setDisplayRange(lut.min, lut.max);
}
}
Expand Down
5 changes: 4 additions & 1 deletion release-notes.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</head>
<body>

<li> <u>1.53c 1 June 2020</u>
<li> <u>1.53c2 2 June 2020</u>
<ul>
<li> Thanks Jerome Mutterer, added the rainbow progress bar
easter egg, activated by switching to the angle tool and running
Expand All @@ -15,6 +15,9 @@
when measuring line selections created by <i>Edit&gt;Selection&gt;Area to Line</i>
from particle analyzer selections touching the right or
bottom edge of the image.
<li> Thanks to Norbert Vischer, fixed a bug that caused hyperstacks
with a "select all" selection to not be correcty copied to
the system clipboard.
</ul>

<li> <u>1.53b 31 May 2020</u>
Expand Down

0 comments on commit d8d921a

Please sign in to comment.