(ImagePlus imp, int xshrink, int yshrink, int zshrink, int method)
| 46 | } |
| 47 | |
| 48 | public ImagePlus shrink(ImagePlus imp, int xshrink, int yshrink, int zshrink, int method) { |
| 49 | this.xshrink = xshrink; |
| 50 | this.yshrink = yshrink; |
| 51 | this.zshrink = zshrink; |
| 52 | int w = imp.getWidth()/xshrink; |
| 53 | int h = imp.getHeight()/yshrink; |
| 54 | ColorModel cm=imp.createLut().getColorModel(); |
| 55 | ImageStack stack = imp.getStack(); |
| 56 | ImageStack stack2 = new ImageStack (w, h, cm); |
| 57 | int d = stack.size(); |
| 58 | if (method==SUM) { |
| 59 | int bitDepth = imp.getBitDepth(); |
| 60 | if (bitDepth==8) |
| 61 | maxValue = 255; |
| 62 | else if (bitDepth==16) |
| 63 | maxValue = 65535; |
| 64 | else |
| 65 | maxValue = 0; |
| 66 | } |
| 67 | for (int z=1; z<=d; z++) { |
| 68 | IJ.showProgress(z, d); |
| 69 | ImageProcessor ip = stack.getProcessor(z); |
| 70 | if (ip.isInvertedLut()) |
| 71 | ip.invert(); |
| 72 | ImageProcessor ip2 = shrink(ip, method); |
| 73 | if (ip.isInvertedLut()) ip2.invert(); |
| 74 | stack2.addSlice(stack.getSliceLabel(z), ip2); |
| 75 | } |
| 76 | int channels = imp.getNChannels(); |
| 77 | int slices = imp.getNSlices(); |
| 78 | int frames = imp.getNFrames(); |
| 79 | if (zshrink>1) { |
| 80 | if (imp.isHyperStack()) { |
| 81 | if (channels>1 && (slices==1||frames==1)) { |
| 82 | imp.setStack(stack2); |
| 83 | ImagePlus[] images = ChannelSplitter.split(imp); |
| 84 | for (int i=0; i<images.length; i++) { |
| 85 | ImageStack tstack = shrinkZ(images[i].getStack(), zshrink); |
| 86 | images[i].setStack(tstack); |
| 87 | } |
| 88 | ImagePlus img = RGBStackMerge.mergeChannels(images, false); |
| 89 | stack2 = img.getStack(); |
| 90 | if (slices>1) slices /= zshrink; |
| 91 | if (frames>1) frames /= zshrink; |
| 92 | } |
| 93 | } else |
| 94 | stack2 = shrinkZ(stack2, zshrink); |
| 95 | } |
| 96 | ImagePlus imp2 = null; |
| 97 | if (imp.isHyperStack()) { |
| 98 | imp2 = imp; |
| 99 | imp2.setStack(stack2, channels, slices, frames); |
| 100 | } else { |
| 101 | imp2 = imp.createImagePlus(); |
| 102 | imp2.setStack("Reduced "+imp.getShortTitle(), stack2); |
| 103 | } |
| 104 | Calibration cal2 = imp2.getCalibration(); |
| 105 | if (cal2.scaled()) { |
no test coverage detected