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

Is that result expected? #157

Open
ghost opened this issue Mar 19, 2023 · 0 comments
Open

Is that result expected? #157

ghost opened this issue Mar 19, 2023 · 0 comments

Comments

@ghost
Copy link

ghost commented Mar 19, 2023

Hi,
Trying to test the denoiser on an input.

Before showing the code, I get much much darker result than expected.
So I prepared a really small 4x4 example of how I use the lib, maybe there is something I am doing wrong.

Please have a look at the following code:

// =========================
// Image setup
// =========================
Magick::Image img;
Magick::Geometry geom;
const uint32_t size_ = 4;

geom.height( size_ );
geom.width( size_ );

img.size( geom );
img.magick( "png" );

// =========================
// Magick specific setup
// =========================

auto *k = img.getPixels( 0, 0, size_, size_ );
auto sp_magick = std::span <Magick::PixelPacket> ( k, size_ * size_ );

// =========================
// OIDN specific setup
// =========================
oidn::DeviceRef device = oidn::newDevice();

device.commit();
u32 final_out_size = size_ * size_ * 3 * sizeof( float );
auto buffer = device.newBuffer( final_out_size );
auto sp_oidn = std::span <std::array <float, 3> > ( std::bit_cast <std::array <float, 3> *> ( buffer.getData() ), size_ * size_ );

// =========================
// One gray pixel at each corner
// =========================
auto l = [&sp_oidn]( u32 idx, float r, float g, float b ){

        sp_oidn[idx][0] = r;
        sp_oidn[idx][1] = g;
        sp_oidn[idx][2] = b;

};

l( 0, 0.5, 0.5, 0.5 );
l( 3, 0.5, 0.5, 0.5 );
l( 12, 0.5, 0.5, 0.5 );
l( 15, 0.5, 0.5, 0.5 );

// =========================
// Filters
// =========================
oidn::FilterRef filter = device.newFilter( "RT" );

filter.setImage( "color", buffer, oidn::Format::Float3, size_, size_ );
filter.setImage( "output", buffer, oidn::Format::Float3, size_, size_ );
filter.set( "hdr", false );
filter.set( "srgb", false );
filter.commit();
filter.execute();

// =========================
// Set values to image magick : 16 bits per channel -> [0;65536[
// =========================

u32 sp_offset = 0;

for ( u32 row = 0; row < size_; row += 1 ){

        for ( u32 col = 0; col < size_; col += 1 ){

                sp_magick[sp_offset].red = sp_oidn[sp_offset][0] * std::numeric_limits <u16>::max();
                sp_magick[sp_offset].green = sp_oidn[sp_offset][1] * std::numeric_limits <u16>::max();
                sp_magick[sp_offset].blue = sp_oidn[sp_offset][2] * std::numeric_limits <u16>::max();
                sp_magick[sp_offset].opacity = std::numeric_limits <u16>::max();

                sp_offset += 1;

        }
}

img.syncPixels();
img.write( "my_file.png" );

Like I said, this code leads to a way too dark image. The colors are way too influenced by the dark colors.

I would like to be able to tell the algorithm that the pixels are not set and should not influence the calculation in any way. Right now, black/unset pixels will have a way too strong influence on the result.

The gray pixels are like the ray information, and they should be kept intact or almost intact. Not blended that much with the unsets.

How may I do?

thanks,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants