Coder Social home page Coder Social logo

Comments (1)

ajeb78 avatar ajeb78 commented on June 24, 2024

I haven't got to the bottom of why this happens, but if it's causing you problems a quick and dirty fix is given below. This catches any pixels that are -nan at the end of the 1st and 2nd steps and eliminates the regions of -nan in the output image and replaces them based on nearest neighbours.

Change the end of bm3d_1st_step() to:
//! Final reconstruction
for (unsigned k = 0; k < width * height * chnls; k++) {
img_basic[k] = numerator[k] / denominator[k];
if (isnan(img_basic[k])) {
unsigned count = 0;
img_basic[k] = 0.f;
if (k > chnls-1) {
img_basic[k] += (isnan(img_basic[k-chnls]) ? 0 : img_basic[k-chnls]);
count = count + (isnan(img_basic[k-chnls]) ? 0 : 1);
}
if (k < count-chnls) {
img_basic[k] += (isnan(img_basic[k+chnls]) ? 0 : img_basic[k+chnls]);
count = count + (isnan(img_basic[k+chnls]) ? 0 : 1);
}
if (count != 0)
img_basic[k] /= count;
}
}
}

Change the end of bm3d_2nd_step() to:
//! Final reconstruction
for (unsigned k = 0; k < width * height * chnls; k++) {
img_denoised[k] = numerator[k] / denominator[k];
if (isnan(img_denoised[k])) {
unsigned count = 0;
img_denoised[k] = 0.f;
if (k > chnls-1) {
img_denoised[k] += (isnan(img_denoised[k-chnls]) ? 0 : img_denoised[k-chnls]);
count = count + (isnan(img_denoised[k-chnls]) ? 0 : 1);
}
if (k < count-chnls) {
img_denoised[k] += (isnan(img_denoised[k+chnls]) ? 0 : img_denoised[k+chnls]);
count = count + (isnan(img_denoised[k+chnls]) ? 0 : 1);
}
if (count != 0)
img_denoised[k] /= count;
}
}
}

from bm3d.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.