-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added complex to the MagickImageCollection.
- Loading branch information
Showing
8 changed files
with
180 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. | ||
Licensed under the Apache License, Version 2.0. | ||
*/ | ||
|
||
/** | ||
* Specifies a kind of complex operator. | ||
*/ | ||
export enum ComplexOperator { | ||
/** | ||
* Undefined. | ||
*/ | ||
Undefined, | ||
|
||
/** | ||
* Add. | ||
*/ | ||
Add, | ||
|
||
/** | ||
* Conjugate. | ||
*/ | ||
Conjugate, | ||
|
||
/** | ||
* Divide. | ||
*/ | ||
Divide, | ||
|
||
/** | ||
* Magnitude phase. | ||
*/ | ||
MagnitudePhase, | ||
|
||
/** | ||
* Multiply. | ||
*/ | ||
Multiply, | ||
|
||
/** | ||
* Real imaginary. | ||
*/ | ||
RealImaginary, | ||
|
||
/** | ||
* Subtract. | ||
*/ | ||
Subtract, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. | ||
Licensed under the Apache License, Version 2.0. | ||
*/ | ||
|
||
import { ComplexOperator } from '../enums/complex-operator'; | ||
import { TemporaryDefines } from '../helpers/temporary-defines'; | ||
|
||
/** | ||
* Settings for the complex operation. | ||
*/ | ||
export class ComplexSettings { | ||
/** | ||
* Initializes a new instance of the {@link ComplexSettings} class. | ||
* @param complexOperator - The complex operator. | ||
*/ | ||
constructor(complexOperator: ComplexOperator) { | ||
this.complexOperator = complexOperator; | ||
} | ||
|
||
/**F | ||
* Gets or sets the complex operator. | ||
**/ | ||
readonly complexOperator: ComplexOperator; | ||
|
||
/** | ||
* Gets or sets the signal to noise ratio. | ||
**/ | ||
signalToNoiseRatio?: number; | ||
|
||
|
||
/** @internal */ | ||
_setArtifacts(temporaryDefines: TemporaryDefines): void { | ||
if (this.signalToNoiseRatio !== undefined) | ||
temporaryDefines.setArtifact('complex:snr', this.signalToNoiseRatio); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. | ||
Licensed under the Apache License, Version 2.0. | ||
*/ | ||
|
||
import { ComplexOperator } from '@src/enums/complex-operator'; | ||
import { ErrorMetric } from '@src/enums/error-metric'; | ||
import { ComplexSettings } from '@src/settings/complex-settings'; | ||
import { TestImages } from '@test/test-images'; | ||
|
||
describe('MagickImageCollection#coalesce', () => { | ||
it('should throw exception when collection is empty', () => { | ||
const settings = new ComplexSettings(ComplexOperator.Add); | ||
|
||
TestImages.emptyCollection.use((images) => { | ||
expect(() => { | ||
images.complex(settings, () => { /* never reached */ }); | ||
}).toThrowError('operation requires at least one image'); | ||
}); | ||
}); | ||
|
||
it('should apply the complex operation', () => { | ||
const settings = new ComplexSettings(ComplexOperator.Divide); | ||
settings.signalToNoiseRatio = 5; | ||
|
||
TestImages.roseSparkleGif.use(images => { | ||
images.complex(settings, (image) => { | ||
expect(image.compare(images[0], ErrorMetric.RootMeanSquared)).toBeCloseTo(0.56843); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. | ||
Licensed under the Apache License, Version 2.0. | ||
*/ | ||
|
||
import { ComplexOperator } from '@src/enums/complex-operator'; | ||
import { TemporaryDefines } from '@src/helpers/temporary-defines'; | ||
import { ComplexSettings } from '@src/settings/complex-settings'; | ||
import { TestImages } from '@test/test-images'; | ||
|
||
describe('ConnectedComponentsSettings', () => { | ||
const settings = new ComplexSettings(ComplexOperator.Multiply); | ||
settings.signalToNoiseRatio = 42; | ||
|
||
describe('#_setArtifacts', () => { | ||
it('should add all defined artifacts to the provided image', () => { | ||
TestImages.Builtin.logo.use((image) => { | ||
TemporaryDefines.use(image, (temporaryDefines) => { | ||
settings._setArtifacts(temporaryDefines); | ||
|
||
expect(settings.complexOperator).toBe(ComplexOperator.Multiply); | ||
expect(image.artifactNames.length).toBe(1); | ||
expect(image.getArtifact('complex:snr')).toBe('42'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |