-
Notifications
You must be signed in to change notification settings - Fork 5
wip: fix: resize with interpolationType nearest #453
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
Changes from all commits
e2e8618
4dc9cd0
37c135f
06ff485
c5fd4f2
aefab67
bc7664b
8268149
c57b92a
12dd124
5c1ecf7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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, | ||
}, | ||
); | ||
} | ||
|
||
/** | ||
|
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)