This repository was archived by the owner on Jul 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
wip: fix: resize with interpolationType nearest #453
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e2e8618
wip: fix: resize with interpolationType nearest
tpoisseau 4dc9cd0
wip: refactor: interpolatePosition dependant of interpolation type
tpoisseau 37c135f
wip: test: activate bilinear test
tpoisseau 06ff485
wip: fix: wrong toInt
tpoisseau c5fd4f2
wip: refactor: nx - ny
tpoisseau aefab67
wip: refactor: use transform matrix
tpoisseau bc7664b
chore: remove unused code and add error tolerance
tpoisseau 8268149
refactor: switch from object to indexed parameters
tpoisseau c57b92a
chore: typo and doc
tpoisseau 12dd124
fix: seems default border for bilinear should be replicate
tpoisseau 5c1ecf7
test: reset snapshots
tpoisseau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file modified
BIN
-3.71 KB
(99%)
.../__tests__/__image_snapshots__/align-min-difference-test-ts-id-crops-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-2.02 KB
(99%)
...ts__/__image_snapshots__/align-min-difference-test-ts-other-id-crops-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5.63 KB
(130%)
...__/__image_snapshots__/get-affine-transform-test-ts-crosscheck-false-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+423 Bytes
(100%)
..._tests__/__image_snapshots__/get-affine-transform-test-ts-debug-true-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+4.67 KB
(130%)
..._tests__/__image_snapshots__/get-affine-transform-test-ts-rgb-images-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1 Byte
(99%)
...t-keypoint-patch-test-ts-centroid-patch-diameter-31-scalene-triangle-2-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+2 Bytes
(100%)
...t-keypoint-patch-test-ts-centroid-patch-diameter-31-scalene-triangle-3-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5 Bytes
(100%)
...patch-test-ts-centroid-patch-diameter-31-scalene-triangle-rotated-90-2-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-8 Bytes
(96%)
...patch-test-ts-centroid-patch-diameter-31-scalene-triangle-rotated-90-3-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-10 Bytes
(93%)
...pshots__/get-keypoint-patch-test-ts-default-options-scalene-triangle-2-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+7 Bytes
(100%)
...pshots__/get-keypoint-patch-test-ts-default-options-scalene-triangle-3-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-3 Bytes
(98%)
...t-keypoint-patch-test-ts-default-options-scalene-triangle-rotated-90-2-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1 Byte
(100%)
...t-keypoint-patch-test-ts-default-options-scalene-triangle-rotated-90-3-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5.47 KB
(110%)
...st-ts-various-polygons-centroid-patch-diameter-31-polygon-rotated-10-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+7.25 KB
(110%)
...t-ts-various-polygons-centroid-patch-diameter-31-polygon-rotated-180-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+11.8 KB
(120%)
...ious-polygons-centroid-patch-diameter-31-scalene-triangle-rotated-10-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+6.05 KB
(110%)
...ous-polygons-centroid-patch-diameter-31-scalene-triangle-rotated-180-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+8.62 KB
(110%)
...ious-polygons-centroid-patch-diameter-31-scalene-triangle-rotated-90-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+7.2 KB
(120%)
...osscheck-matches-various-polygons-centroid-patch-diameter-31-polygon-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed
BIN
-33.8 KB
...tches-various-polygons-centroid-patch-diameter-31-polygon-rotated-10-1-snap.png
Binary file not shown.
Binary file removed
BIN
-44.4 KB
...ches-various-polygons-centroid-patch-diameter-31-polygon-rotated-180-1-snap.png
Binary file not shown.
Binary file modified
BIN
+13.6 KB
(120%)
...matches-various-polygons-centroid-patch-diameter-31-scalene-triangle-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+7.68 KB
(120%)
...ches-various-polygons-centroid-patch-diameter-31-scalene-triangle-90-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+37.9 KB
(120%)
...ches-test-ts-alphabet-image-as-source-and-destination-nb-keypoint-10-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+66.3 KB
(110%)
...ts__/__image_snapshots__/draw-matches-test-ts-destination-rotated-10-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+20.2 KB
(100%)
...sts__/__image_snapshots__/draw-matches-test-ts-destination-rotated-2-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+72.8 KB
(110%)
..._tests__/__image_snapshots__/draw-matches-test-ts-show-distance-true-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+65.9 KB
(120%)
...mage_snapshots__/montage-test-ts-draw-keypoints-disposition-vertical-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
-55.4 KB
(94%)
...__tests__/__image_snapshots__/montage-test-ts-draw-keypoints-scale-2-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+63.9 KB
(110%)
..._image_snapshots__/montage-test-ts-draw-matches-disposition-vertical-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
-54.6 KB
(94%)
...e/__tests__/__image_snapshots__/montage-test-ts-draw-matches-scale-2-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+4.47 KB
(110%)
...e/__tests__/__image_snapshots__/overlap-images-test-ts-two-triangles-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
-424 Bytes
(82%)
...y/__tests__/__image_snapshots__/resize-test-ts-has-to-match-snapshot-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
-3 Bytes
(98%)
...sts__/__image_snapshots__/transform-rotate-test-ts-full-image-option-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+38 Bytes
(140%)
...__/__image_snapshots__/transform-rotate-test-ts-rotate-around-center-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+4 Bytes
(100%)
...__/__image_snapshots__/transform-rotate-test-ts-rotate-around-corner-1-snap.png
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,10 +1,6 @@ | ||
import { Image } from '../Image'; | ||
import { getClamp } from '../utils/clamp'; | ||
import { getBorderInterpolation, BorderType } from '../utils/interpolateBorder'; | ||
import { | ||
getInterpolationFunction, | ||
InterpolationType, | ||
} from '../utils/interpolatePixel'; | ||
import { BorderType } from '../utils/interpolateBorder'; | ||
import { InterpolationType } from '../utils/interpolatePixel'; | ||
import { assert } from '../utils/validators/assert'; | ||
|
||
export interface ResizeOptions { | ||
|
@@ -53,36 +49,26 @@ export interface ResizeOptions { | |
* @returns The new image. | ||
*/ | ||
export function resize(image: Image, options: ResizeOptions): Image { | ||
const { interpolationType = 'bilinear' } = options; | ||
const { | ||
interpolationType = 'bilinear', | ||
borderType = 'constant', | ||
borderType = interpolationType === 'bilinear' ? 'replicate' : 'constant', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? Is it OpenCV behavior? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know but bilinear was better with replicate by default. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is probably not the right way to fix it. |
||
borderValue = 0, | ||
} = options; | ||
const { width, height } = checkOptions(image, options); | ||
const newImage = Image.createFrom(image, { width, height }); | ||
const interpolate = getInterpolationFunction(interpolationType); | ||
const interpolateBorder = getBorderInterpolation(borderType, borderValue); | ||
const clamp = getClamp(newImage); | ||
const intervalX = (image.width - 1) / (width - 1); | ||
const intervalY = (image.height - 1) / (height - 1); | ||
for (let row = 0; row < newImage.height; row++) { | ||
for (let column = 0; column < newImage.width; column++) { | ||
const nx = column * intervalX; | ||
const ny = row * intervalY; | ||
for (let channel = 0; channel < newImage.channels; channel++) { | ||
const newValue = interpolate( | ||
image, | ||
nx, | ||
ny, | ||
channel, | ||
interpolateBorder, | ||
clamp, | ||
); | ||
newImage.setValue(column, row, channel, newValue); | ||
} | ||
} | ||
} | ||
return newImage; | ||
const { width, height, xFactor, yFactor } = checkOptions(image, options); | ||
|
||
return image.transform( | ||
[ | ||
[xFactor, 0, 0], | ||
[0, yFactor, 0], | ||
], | ||
{ | ||
width, | ||
height, | ||
borderType, | ||
borderValue, | ||
interpolationType, | ||
}, | ||
); | ||
} | ||
|
||
/** | ||
|
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error: 25
is too much (that's 10% of the range of values 0-255)