Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resize method doesn't work properly #452

Open
targos opened this issue Apr 26, 2024 · 2 comments
Open

resize method doesn't work properly #452

targos opened this issue Apr 26, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@targos
Copy link
Member

targos commented Apr 26, 2024

It somehow "zooms" in the image. This is especially visible on the nearest-neighbor version of the test.

There's probably a bug in how we iterate on the pixels.
Implementation: https://github.com/image-js/image-js-typescript/blob/main/src/geometry/resize.ts#L55-L86

We need to fix it so these tests can be enabled:

test.skip('compare result of resize with opencv (nearest)', () => {
const img = testUtils.load('opencv/test.png');
const resized = img.resize({
xFactor: 10,
yFactor: 10,
interpolationType: 'nearest',
});
expect(resized).toMatchImage('opencv/testResizeNearest.png');
});
test.skip('compare result of resize with opencv (bilinear)', () => {
const img = testUtils.load('opencv/test.png');
const resized = img.resize({
xFactor: 10,
yFactor: 10,
});

Reference created by

# Image resizing by 10.
dst = cv.resize(img, (80, 100), interpolation=cv.INTER_NEAREST)
cv.imwrite('testResizeNearest.png', dst)
dst = cv.resize(img, (80, 100), interpolation=cv.INTER_LINEAR)
cv.imwrite('testResizeBilinear.png', dst)

@targos targos added the bug Something isn't working label Apr 26, 2024
@targos
Copy link
Member Author

targos commented Apr 26, 2024

Current result:

diff --git a/src/geometry/__tests__/resize.test.ts b/src/geometry/__tests__/resize.test.ts
index df8c0e21..d95281d8 100644
--- a/src/geometry/__tests__/resize.test.ts
+++ b/src/geometry/__tests__/resize.test.ts
@@ -1,6 +1,6 @@
-import { encodePng } from '../../save';
+import { encodePng, writeSync } from '../../save';
 
-test.skip('compare result of resize with opencv (nearest)', () => {
+test('compare result of resize with opencv (nearest)', () => {
   const img = testUtils.load('opencv/test.png');
 
   const resized = img.resize({
@@ -9,6 +9,8 @@ test.skip('compare result of resize with opencv (nearest)', () => {
     interpolationType: 'nearest',
   });
 
+  writeSync('test.png', resized);
+
   expect(resized).toMatchImage('opencv/testResizeNearest.png');
 });
 

test

@tpoisseau tpoisseau self-assigned this Apr 26, 2024
tpoisseau added a commit that referenced this issue Apr 26, 2024
@tpoisseau tpoisseau linked a pull request Apr 26, 2024 that will close this issue
tpoisseau added a commit that referenced this issue May 2, 2024
chirurgical fix, rework of #453

Closes: #452
tpoisseau added a commit that referenced this issue May 2, 2024
chirurgical fix, rework of #453

Refs: #452
targos pushed a commit that referenced this issue May 3, 2024
targos added a commit that referenced this issue May 6, 2024
@targos
Copy link
Member Author

targos commented May 6, 2024

targos added a commit that referenced this issue May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants