phulin / rebook

A collection of tools for cleaning up book scans.
132 stars 30 forks source link

Bug in ntirogiannis2014 function, Case of 100% blqck forground #3

Closed ghsama closed 5 years ago

ghsama commented 5 years ago

Hey, In ntigo method, it the contrast estimation is based on the formulat : -50+log10((FG_mean-FG_std)/)BG_mean-BG_std) in the situation where we have a 100% black foreground, it raise an error ( log(0) ), i checked the article, from my understanding they said to use in the extreme case to put FG_mean-FG_std = 2.5, you can check it for more credit: here is the proposed solution.

if not (FG_avg + FG_std) == 0:
        C = -50 * np.log10((FG_avg + FG_std) / (BG_avg - BG_std))
        k = -0.2 - 0.1 * C / 10
    else :#This is the extreme case when the FG is 100% black, check the article explaination page before equation 5
        C = -50 * np.log10((2.5) / (BG_avg - BG_std))
        k = -0.2 - 0.1 * C / 10

PS : i ll do a push request as soon as i can, sorry for that