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

Picture auto enhancement #2906

Closed
mathias22osterhagen22 opened this issue Sep 23, 2021 · 7 comments
Closed

Picture auto enhancement #2906

mathias22osterhagen22 opened this issue Sep 23, 2021 · 7 comments
Labels

Comments

@mathias22osterhagen22
Copy link

I'm sorry if this question seems silly but I didn't see anywhere an "auto" mode other than for the rotation function.

What are you trying to achieve?
We have a lot of documents arriving in our system that are scanned and often not easily readable, we are looking to auto enhances (if necessary) the picture, the contrast, and the luminosity (like the filter of windows).
image

By "if necessary" I mean: that we don't want to apply a luminosity + 10 on an image already too bright or a - 10 on one already too dark.

Have you searched for similar questions?
Yes, but I didn't found.

Are you able to provide a minimal, standalone code sample that demonstrates this question?
An example:

  1. Input:
    input

  2. Output:
    output

Are you able to provide a sample image that helps explain the question?
(Yes see the two above)

@lovell
Copy link
Owner

lovell commented Sep 23, 2021

Hi, did you see the clahe and normalise operations?

@mathias22osterhagen22
Copy link
Author

Hello @lovell , thank you a lot for your answer!
I tried this morning the two functions you recommended but It doesn't seem to make a major improvement:
image

Do I'm doing something wrong ?

const fs = require("fs");
const sharp = require("sharp");

let files = fs.readdirSync('./input');
console.log("Input files: ", files);
if (fs.existsSync('./output'))
    fs.rmdirSync('./output', { recursive: true, force: true });
fs.mkdirSync('./output');

files.forEach(fileName => {
    console.log('Convert: ./input/' + fileName + " -> ./output/" + fileName + " ...");
    let image = sharp('./input/' + fileName);
    image.metadata()
        .then(metadata => {
            image.clahe({ width: metadata.width, height: metadata.height })
                .normalise()
                .withMetadata()
                .toFile('./output/' + fileName);
        })
});

@lovell
Copy link
Owner

lovell commented Sep 25, 2021

Perhaps try using CLAHE with a smaller local region.

https://en.wikipedia.org/wiki/Adaptive_histogram_equalization

For example using the following code with the above input:

sharp(input)
  .clahe({ width: 21, height: 21 })
  .normalise()
  ...

produces:

@mathias22osterhagen22
Copy link
Author

Thank you @lovell, yes in fact with a smaller local region made it look better.

Is there a way to make it automatically brighter or darker?

@lovell
Copy link
Owner

lovell commented Nov 7, 2021

The normalise operation will already have spread luminosity over the full range, so if you always want it to be brighter you'll need to use modulate and pass either lightness (additive) or brightness (multiplicative).

@mathias22osterhagen22
Copy link
Author

Then there is no way to detect it automatically? :/

@lovell
Copy link
Owner

lovell commented Aug 24, 2022

Let's track this at #200, which is about improving normalise and should help with this kind of scenario.

@lovell lovell closed this as completed Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants