nothings / stb

stb single-file public domain libraries for C/C++
https://twitter.com/nothings
Other
25.77k stars 7.66k forks source link

The output of `stbir_resize_uint8_linear` function is competely wrong #1626

Closed ardeal closed 3 months ago

ardeal commented 3 months ago

Hi,

I call the stbir_resize_uint8_linear function with the following code and parameters, but the output of stbir_resize_uint8_linear function is competely wrong.

is there any doc about the explanation of those parameters of stbir_resize_uint8_linear function? or could you please help to tell me how to fill those parameters of stbir_resize_uint8_linear functions?

using namespace cv;

#define STB_IMAGE_RESIZE_IMPLEMENTATION
#include "stb_image_resize2.h"

const char* path = "C:\\doc\\000002.jpg"; // image rows=height=445, image cols=width=295
Mat image = imread(path, -1);
Mat smallimage;

resize(image, smallimage, Size(506, 666)); // This is opencv resize fuction which works correctly

Mat smallimage_mine(666, 506, CV_8UC3);

stbir_resize_uint8_linear(image.data, 295, 445, 3, smallimage_mine.data, 506, 666, 3, STBIR_BGR); // STBIR_RGB, STBIR_BGR
jeffrbig2 commented 3 months ago

The stride parameters specify the number of bytes between the start of each scanline. So, you definitely don't want "3" for those. Should be at least 3*width...

ardeal commented 3 months ago

Thank you @jeffrbig2 ! Your solution works.

2 more questions are: question 1: Your current code works for 3 channel image. how to customized it for N(N>3) channel tensor?

question 2: the output of your code is a little bit different from OpenCV resize function. Please check the following picture. Do you have any ideal about how to make the output of your code the same as OpenCV?

image

jeffrbig2 commented 3 months ago

There are dozens of reasons they would differ - not the least of which is you calling the linear color function. What on earth makes you think they'd match? If you want to get them close, then you need to do some reading about what OpenCV does. This isn't an issue at all, so I'm going to have @nothings close this issue.