-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes: #427
- Loading branch information
Showing
2 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
src/stack/align/utils/__tests__/computeCropOrigins.test.ts
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,59 @@ | ||
import { Image } from '../../../../Image'; | ||
import { Stack } from '../../../../Stack'; | ||
import { computeCropOrigins } from '../computeCropOrigins'; | ||
import { findCommonArea } from '../findCommonArea'; | ||
|
||
const image1 = new Image(4, 4); | ||
const image2 = new Image(3, 4); | ||
const image3 = new Image(6, 5); | ||
const image4 = new Image(4, 2); | ||
const absoluteTranslations = [ | ||
{ column: 0, row: 0 }, | ||
{ column: 2, row: -2 }, | ||
{ column: 1, row: 1 }, | ||
{ column: -1, row: 1 }, | ||
]; | ||
test('stack of 2 images', () => { | ||
const stack = new Stack([image1, image2]); | ||
const absTranslations = absoluteTranslations.slice(0, 2); | ||
|
||
const commonArea = findCommonArea(stack, absTranslations); | ||
|
||
const result = computeCropOrigins(stack, commonArea, absTranslations); | ||
|
||
expect(result).toStrictEqual([ | ||
{ column: 2, row: 0 }, | ||
{ column: 0, row: 2 }, | ||
]); | ||
}); | ||
|
||
test('stack of 3 images', () => { | ||
const stack = new Stack([image1, image2, image3]); | ||
const absTranslations = absoluteTranslations.slice(0, 3); | ||
|
||
const commonArea = findCommonArea(stack, absTranslations); | ||
|
||
const result = computeCropOrigins(stack, commonArea, absTranslations); | ||
|
||
expect(result).toStrictEqual([ | ||
{ column: 2, row: 1 }, | ||
{ column: 0, row: 3 }, | ||
{ column: 1, row: 0 }, | ||
]); | ||
}); | ||
|
||
test('stack of 4 images', () => { | ||
const stack = new Stack([image1, image2, image3, image4]); | ||
const absTranslations = absoluteTranslations.slice(0, 4); | ||
|
||
const commonArea = findCommonArea(stack, absTranslations); | ||
|
||
const result = computeCropOrigins(stack, commonArea, absTranslations); | ||
|
||
expect(result).toStrictEqual([ | ||
{ column: 2, row: 1 }, | ||
{ column: 0, row: 3 }, | ||
{ column: 1, row: 0 }, | ||
{ column: 3, row: 0 }, | ||
]); | ||
}); |
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 |
---|---|---|
@@ -1,13 +1,29 @@ | ||
import { Stack } from '../../../Stack'; | ||
import { Point } from '../../../geometry'; | ||
import { difference } from '../../../utils/geometry/points'; | ||
|
||
import { CommonArea } from './findCommonArea'; | ||
|
||
/** | ||
* Compute the origins of the crops relative to the top left corner of each image in order | ||
* to crop the common area of each of the images of an aligned stack. | ||
* @param stack - Stack to process. | ||
* @param commonArea - The data of the common area of the stack. | ||
* @param absoluteTranslations - The absolute translations of the images of the stack (relative to the first image). | ||
* @returns The origins of the crops. | ||
*/ | ||
export function computeCropOrigins( | ||
stack: Stack, | ||
commonArea: CommonArea, | ||
): Point[] {} | ||
absoluteTranslations: Point[], | ||
): Point[] { | ||
const cropOrigins: Point[] = []; | ||
let currentCropOrigin = commonArea.origin; | ||
cropOrigins.push(currentCropOrigin); | ||
for (let i = 1; i < stack.size; i++) { | ||
currentCropOrigin = difference(commonArea.origin, absoluteTranslations[i]); | ||
cropOrigins.push(currentCropOrigin); | ||
} | ||
|
||
return cropOrigins; | ||
} |