I'm trying to use open image denoise. Here's the code:

int main() {
    int width, height, nrChannels;
    unsigned char* image = stbi_load("img_cornell_box.png", &width, &height, &nrChannels, 0);
    unsigned char* resultImage = new unsigned char[width*height*nrChannels];
    oidn::DeviceRef device = oidn::newDevice();
    std::cout << nrChannels << std::endl;
    oidn::FilterRef filter = device.newFilter("RT");
    filter.setImage("color", image, oidn::Format::Float4, width, height);
    filter.setImage("output", resultImage, oidn::Format::Float4, width, height);
    filter.set("hdr", false);
    filter.set("srgb", true);

    const char* errorMessage;
    if (device.getError(errorMessage) != oidn::Error::None) {
        std::cout << "Error: " << errorMessage << std::endl;
    else {
        stbi_write_png("img.png", width, height, nrChannels, resultImage, width * nrChannels);

I'm getting an error saying that the image format is unsupported.

If I use jpg, and change Format::Float4 to Format::Float3 I get this error:

Exception thrown at 0x00007FFC5588E1F5 (OpenImageDenoise.dll) in oidntest.exe: 0xC0000005: Access violation reading location 0x0000021D9C42FA70.

Am I doing something wrong? This is the image I'm using: https://drive.google.com/open?id=1uSjsyWCRisXNFUJG6R8iL5AdVbM7_18u


As far as I remember, you need to input data in float array. Right now your input is unsigned char array. To quick check this, try loading any HDR image in float array & pass it on to the setImage functions, this seems to work.

In your case, you would need to read individual image channel data & cast it to float. If your image color is stored in [0-255] range, you would then need to bring it to [0-1] range (Not completely sure about this stage!) & then pass the data in float array to denoiser functions.

Hope this helps.

  • $\begingroup$ this worked but I had to change Float4 to Float3 and had to use a jpg instead of png. Float4 format still gives me an error saying that the image format is unsupported. $\endgroup$ – Karthik Dec 15 '19 at 17:10
  • $\begingroup$ I feel it's not supported as per official doc: openimagedenoise.github.io/documentation.html $\endgroup$ – TheOrestes Dec 16 '19 at 5:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.