(ImageProcessor ip)
| 102 | |
| 103 | |
| 104 | public void run(ImageProcessor ip) { |
| 105 | stack = imp.getStack(); |
| 106 | int stackSize = stack.getSize(); |
| 107 | |
| 108 | if (stack.isVirtual()) { |
| 109 | boolean ok = IJ.showMessageWithCancel( |
| 110 | "Image Stabilizer", |
| 111 | "You are using a virtual stack.\n" + |
| 112 | "You will be asked to choose an output directory to save the stablized images.\n" + |
| 113 | "If you did not intend to use a virtual stack, or if you want to view the stablized images in ImageJ directly,\n" + |
| 114 | "please reload the image sequence with the 'Use Virtual Stack' option unchecked."); |
| 115 | if (!ok) return; |
| 116 | DirectoryChooser dc = new DirectoryChooser("Output Directory"); |
| 117 | outputDir = dc.getDirectory(); |
| 118 | if (outputDir == null || outputDir.length() == 0) |
| 119 | return; |
| 120 | File file = new File(outputDir); |
| 121 | VirtualStack virtualStack = (VirtualStack)stack; |
| 122 | String stackDir = virtualStack.getDirectory(); |
| 123 | if (null != stackDir) { |
| 124 | File stackFile = new File(stackDir); |
| 125 | try { |
| 126 | file = file.getCanonicalFile(); |
| 127 | stackFile = stackFile.getCanonicalFile(); |
| 128 | } |
| 129 | catch (IOException e) { |
| 130 | IJ.error("Could not get canonical file path."); |
| 131 | return; |
| 132 | } |
| 133 | if (file.equals(stackFile)) { |
| 134 | IJ.error("Output directory must be difference from the stack directory."); |
| 135 | return; |
| 136 | } |
| 137 | } |
| 138 | stackVirtual = true; |
| 139 | outputNewStack = false; |
| 140 | } |
| 141 | |
| 142 | if (!showDialog(ip)) |
| 143 | return; |
| 144 | |
| 145 | int current = imp.getCurrentSlice(); |
| 146 | ImageProcessor ipRef = stack.getProcessor(current); |
| 147 | |
| 148 | if (outputNewStack) |
| 149 | stackOut = new ImageStack(ip.getWidth(), ip.getHeight()); |
| 150 | |
| 151 | showProgress(0.0); |
| 152 | if (!IJ.escapePressed()) { |
| 153 | process(ipRef, current - 1, 1, -1, 1); |
| 154 | if (!IJ.escapePressed()) |
| 155 | process(ipRef, current, stackSize, 1, current); |
| 156 | } |
| 157 | |
| 158 | if (!outputNewStack) // in-place processing |
| 159 | imp.updateAndDraw(); |
| 160 | else if (stackOut.getSize() > 0) { |
| 161 | // Create new image using the new stack. |
nothing calls this directly
no test coverage detected