File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed
Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -448,7 +448,7 @@ def principal_components(image):
448448
449449 Arguments:
450450
451- `image` (ndarray or :class:`spectral.Image`):
451+ `image` (ndarray, :class:`spectral.Image`, :class:`GaussianStats `):
452452
453453 An `MxNxB` image
454454
@@ -478,9 +478,10 @@ def principal_components(image):
478478 '''
479479 from numpy import sqrt , sum
480480
481- (M , N , B ) = image .shape
482-
483- stats = calc_stats (image )
481+ if isinstance (image , GaussianStats ):
482+ stats = image
483+ else :
484+ stats = calc_stats (image )
484485
485486 (L , V ) = numpy .linalg .eig (stats .cov )
486487
Original file line number Diff line number Diff line change @@ -88,6 +88,17 @@ def test_ppi_centered(self):
8888 p2 = spy .ppi (data_centered , 4 )
8989 np .all (p == p2 )
9090
91+ def test_pca_runs (self ):
92+ '''Should be able to compute PCs and transform data.'''
93+ data = self .data
94+ xdata = spy .principal_components (data ).transform (data )
95+
96+ def test_pca_runs_from_stats (self ):
97+ '''Should be able to pass image stats to PCA function.'''
98+ data = self .data
99+ stats = spy .calc_stats (data )
100+ xdata = spy .principal_components (stats ).transform (data )
101+
91102def run ():
92103 print ('\n ' + '-' * 72 )
93104 print ('Running dimensionality tests.' )
You can’t perform that action at this time.
0 commit comments