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

Excluding darkest pixels from calculation #2667

Closed
dmitrizzle opened this issue Apr 21, 2021 · 3 comments
Closed

Excluding darkest pixels from calculation #2667

dmitrizzle opened this issue Apr 21, 2021 · 3 comments
Labels

Comments

@dmitrizzle
Copy link

What are you trying to achieve?

I'm reversing negatives which sometimes include film borders. The borders sometimes mess up the inversion algorithm since their blackpoint does not always match the image's blackpoint (i.e. they're darker than the darkest point of a photograph should be).

I am hoping to remove them from my calculations.

Have you searched for similar questions?

Yes.

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

// reverse negative
const reversed = await sharp(input)
  .toColorspace("rgb16")
  .flatten()
  .negate()
  .toBuffer();

// make a small copy to make calculations -- this is where I'd like to get rid of the borders
const data = await sharp(reversed).clone().resize(500).toBuffer();

// I then split `data` into 3 colour channels run `stats` and normalize histogram using `linear` with the number from `stats`

Are you able to provide a sample image that helps explain the question?

This is the negative that's been processed using the method above. Notice that it's a "half-frame," meaning that there are two photographs taken on what is usually takes up a "full frame." The scanner scans the entire frame so the black border isn't just around the photo but is also running through the middle. This isn't always the case. Point being that the blackpoint should be taken from the image, and not the border around it. A possible complication may occur when the photograph's blackpoint does match the blackpoint in the frame.
Screen Shot 2021-04-20 at 10 08 58 PM

Below, I've applied the Photoshop Curves adjustment which as you can see simply cuts the black point on each channel individually. This is what the final image should look like, minus having to rely on expensive Adobe software and manual labour.
Screen Shot 2021-04-20 at 10 09 05 PM

Thanks!

@lovell
Copy link
Owner

lovell commented Apr 25, 2021

Future possible enhancement #200 might provide what you're looking for, which relates to improving the normalise operation by ignoring the very darkest and lightest values.

@dmitrizzle
Copy link
Author

Amazing, thank you. I'd like to add my contribution to this library in the near future with this enhancement and #1066. I'll begin by getting familiar with some C++ basics and this lib code. Pls let me know if you have any recommendations on where to get started first.

@lovell
Copy link
Owner

lovell commented May 7, 2021

Let's track this at #200

@lovell lovell closed this as completed May 7, 2021
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