Skip to content

Commit 0faabc9

Browse files
authored
Merge pull request #6 from multi-template-matching/duplicateSlice
Dont duplicate full stack
2 parents fb36881 + 5925f66 commit 0faabc9

File tree

1 file changed

+24
-29
lines changed

1 file changed

+24
-29
lines changed

Fiji/scripts/Plugins/Template_Matching/Template_Matching_Image.py

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
'''
2121
#import time
2222
#@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+
2526
## Create GUI
2627
Win = GenericDialogPlus("Multiple Template Matching")
2728
Win.addImageChoice("Template", prefs.get("Template","Choice"))
@@ -108,7 +109,7 @@
108109

109110

110111
## Import modules
111-
from ij import IJ
112+
from ij import IJ, ImagePlus
112113
from ij.gui import Roi
113114

114115
## Import HomeMade modules
@@ -123,7 +124,7 @@
123124
elif template.height>image.height or template.width>image.width:
124125
raise Exception('The template is larger in width and/or height than the searched image')
125126

126-
### Initialise outputs ###
127+
### Initialize outputs ###
127128
if show_table:
128129
from ij.measure import ResultsTable
129130
from utils import AddToTable
@@ -141,50 +142,44 @@
141142

142143

143144
# Loop over the images in the stack (or directly process if unique)
144-
ImageStack = image.getStack()
145+
imageStack = image.getStack()
145146
nSlice = image.getStackSize()
146-
imageBis = image.duplicate() # duplicate full stack to be sure to not mess around with ROI display
147147

148148
for i in xrange(1,nSlice+1):
149149

150150
if IJ.escapePressed():
151151
IJ.resetEscape() # for next call
152152
raise KeyboardInterrupt("Escape was pressed")
153153

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
155155

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
171162
if nSlice>1:
172-
SliceLabel = image.getStack().getSliceLabel(i)
163+
SliceLabel = imageStack.getSliceLabel(i)
173164

174165
if SliceLabel: # sometimes the slicelabel is none
175166
Title = SliceLabel.split('\n',1)[0] # split otherwise we get some unecessary information
176167
else:
177168
Title = image.getTitle()
178169

179170
else:
180-
Title = image.getTitle()
181-
182-
searchedImage.setTitle(Title)
183-
184-
171+
Title = image.getTitle()
172+
185173
# Do the template(s) matching
186174
#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)
188183
#Stop = time.clock()
189184
#IJ.log("getHit_Template took " + str(Stop-Start) + " seconds")
190185

0 commit comments

Comments
 (0)