|
20 | 20 | ''' |
21 | 21 | #import time |
22 | 22 | #@PrefService prefs |
23 | | -from fiji.util.gui import GenericDialogPlus |
24 | | - |
| 23 | +from fiji.util.gui import GenericDialogPlus |
| 24 | +# rest of imports below on purpose (otherwise searchRoi lost) |
| 25 | + |
25 | 26 | ## Create GUI |
26 | 27 | Win = GenericDialogPlus("Multiple Template Matching") |
27 | 28 | Win.addImageChoice("Template", prefs.get("Template","Choice")) |
|
108 | 109 |
|
109 | 110 |
|
110 | 111 | ## Import modules |
111 | | - from ij import IJ |
| 112 | + from ij import IJ, ImagePlus |
112 | 113 | from ij.gui import Roi |
113 | 114 |
|
114 | 115 | ## Import HomeMade modules |
|
123 | 124 | elif template.height>image.height or template.width>image.width: |
124 | 125 | raise Exception('The template is larger in width and/or height than the searched image') |
125 | 126 |
|
126 | | - ### Initialise outputs ### |
| 127 | + ### Initialize outputs ### |
127 | 128 | if show_table: |
128 | 129 | from ij.measure import ResultsTable |
129 | 130 | from utils import AddToTable |
|
141 | 142 |
|
142 | 143 |
|
143 | 144 | # Loop over the images in the stack (or directly process if unique) |
144 | | - ImageStack = image.getStack() |
| 145 | + imageStack = image.getStack() |
145 | 146 | nSlice = image.getStackSize() |
146 | | - imageBis = image.duplicate() # duplicate full stack to be sure to not mess around with ROI display |
147 | 147 |
|
148 | 148 | for i in xrange(1,nSlice+1): |
149 | 149 |
|
150 | 150 | if IJ.escapePressed(): |
151 | 151 | IJ.resetEscape() # for next call |
152 | 152 | raise KeyboardInterrupt("Escape was pressed") |
153 | 153 |
|
154 | | - imageBis.setSlice(i) # for stacks (important for both with/without searchRoi) for single image no adversial effect |
| 154 | + searchedImage = imageStack.getProcessor(i) # of slice i |
155 | 155 |
|
156 | | - if Bool_SearchRoi: |
157 | | - imageBis.setRoi(searchRoi) |
158 | | - searchedImage = imageBis.crop() # Single image -> crop to ROI - Stack -> crop the slice to the ROI (in this case) |
159 | | - |
160 | | - elif nSlice>1: # no SearchRoi, but with Stack still crop to isolate the slice |
161 | | - |
162 | | - # Remove any ROI and crop |
163 | | - imageBis.killRoi() |
164 | | - searchedImage = imageBis.crop() |
165 | | - |
166 | | - else: # no ROI and not a stack |
167 | | - searchedImage = imageBis |
168 | | - |
169 | | - |
170 | | - # Fix the name for imageBis |
| 156 | + if Bool_SearchRoi: |
| 157 | + searchedImage.setRoi(searchRoi) |
| 158 | + searchedImage = searchedImage.crop() |
| 159 | + |
| 160 | + |
| 161 | + # Fix the name for searchImage |
171 | 162 | if nSlice>1: |
172 | | - SliceLabel = image.getStack().getSliceLabel(i) |
| 163 | + SliceLabel = imageStack.getSliceLabel(i) |
173 | 164 |
|
174 | 165 | if SliceLabel: # sometimes the slicelabel is none |
175 | 166 | Title = SliceLabel.split('\n',1)[0] # split otherwise we get some unecessary information |
176 | 167 | else: |
177 | 168 | Title = image.getTitle() |
178 | 169 |
|
179 | 170 | else: |
180 | | - Title = image.getTitle() |
181 | | - |
182 | | - searchedImage.setTitle(Title) |
183 | | - |
184 | | - |
| 171 | + Title = image.getTitle() |
| 172 | + |
185 | 173 | # Do the template(s) matching |
186 | 174 | #Start = time.clock() |
187 | | - Hits_BeforeNMS = getHit_Template(template, searchedImage, flipv, fliph, angles, Method, n_hit, score_threshold, tolerance) # template and image as ImagePlus (to get the name together with the image matrix) |
| 175 | + Hits_BeforeNMS = getHit_Template(template, |
| 176 | + ImagePlus(Title, searchedImage), |
| 177 | + flipv, fliph, |
| 178 | + angles, |
| 179 | + Method, |
| 180 | + n_hit, |
| 181 | + score_threshold, |
| 182 | + tolerance) # template and image as ImagePlus (to get the name together with the image matrix) |
188 | 183 | #Stop = time.clock() |
189 | 184 | #IJ.log("getHit_Template took " + str(Stop-Start) + " seconds") |
190 | 185 |
|
|
0 commit comments