nothings / stb

stb single-file public domain libraries for C/C++

Home Page:https://twitter.com/nothings

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The output of `stbir_resize_uint8_linear` function is competely wrong

ardeal opened this issue · comments

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

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...

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

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.