@@ -149,20 +149,16 @@ def iterator(image, mask=None, index=None):
149149 return ImageIterator (image )
150150
151151
152- def iterator_ij (image , mask = None , index = None ):
152+ def iterator_ij (mask , index = None ):
153153 '''
154154 Returns an iterator over image pixel coordinates for a given mask.
155155
156156 Arguments:
157157
158- `image` (ndarray or :class:`spectral.Image`):
159-
160- An image over whose pixels will be iterated.
161-
162158 `mask` (ndarray) [default None]:
163159
164- An array of integers that specify over which pixels in `image`
165- iteration should be performed .
160+ An array of integers that specify which coordinates should
161+ be returned .
166162
167163 `index` (int) [default None]:
168164
@@ -173,29 +169,19 @@ def iterator_ij(image, mask=None, index=None):
173169 An iterator over image pixel coordinates. Each returned item is a
174170 2-tuple of the form (row, col).
175171
176- If neither `mask` nor `index` are defined, iteration is performed over all
177- pixels. If `mask` (but not `index`) is defined, iteration is performed
178- over all pixels for which `mask` is nonzero. If both `mask` and `index`
179- are defined, iteration is performed over all pixels `image[i,j]` for which
180- `mask[i,j] == index`.
172+ If `index` is not defined, iteration is performed over all non-zero
173+ elements. If `index` is defined, iteration is performed over all
174+ coordinates for whch `mask[i,j] == index`.
181175 '''
182176
183- if mask is None and index is None :
184- # Iterate over all pixels
185- (nrows , ncols ) = image .shape [:2 ]
186- for r in range (nrows ):
187- for c in range (ncols ):
188- yield (r , c )
177+ if mask .ndim != 2 :
178+ raise ValueError ('Invalid mask shape.' )
179+ if index is None :
180+ mask = mask != 0
189181 else :
190- if mask .shape != image .shape [:len (mask .shape )]:
191- raise ValueError ('Mask shape does not match image.' )
192-
193- if index is None :
194- mask = mask != 0
195- else :
196- mask = mask == index
197- for rc in np .argwhere (mask ):
198- yield tuple (rc )
182+ mask = mask == index
183+ for rc in np .argwhere (mask ):
184+ yield tuple (rc )
199185
200186
201187def mean_cov (image , mask = None , index = None ):
0 commit comments