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

Brightness/Contrast in Lineart mode #38

Open
yoder375 opened this issue Nov 22, 2016 · 3 comments
Open

Brightness/Contrast in Lineart mode #38

yoder375 opened this issue Nov 22, 2016 · 3 comments

Comments

@yoder375
Copy link

I noticed I was having trouble tweaking brightness and contrast when scanning in Lineart mode. Basically anything below 50% brightness would have no effect and 50% and above would result in a blank white image.

Looking at the debug, I realized that it's because the image that the "convert" command is working with is already in black-and-white (aka depth of 1), so it's already a quantized image that has no range to work within to adjust, except to make an all white image.

The solution is to convert the image to grayscale, perform the adjustments, and convert it back to black and white.

Here is what I've done on my server, and I hope it's useful for you...

Starting on line 1307 of current version of index.php, I changed to the following:

                    if($BRIGHT!="0"||$CONTRAST!="0"){
                            if($MODE=='Lineart'){
                                    exe("convert $SCAN -brightness-contrast '$BRIGHT".'x'."$CONTRAST' -depth 16 $SCAN",true);
                                    exe("convert $SCAN -monochrome -depth 1 $SCAN",true);
                            } else {
                                    exe("convert $SCAN -brightness-contrast '$BRIGHT".'x'."$CONTRAST' $SCAN",true);
                            }
                    }

GM-Script-Writer-62850 added a commit that referenced this issue Nov 22, 2016
Thanks yoder375
@GM-Script-Writer-62850
Copy link
Owner

GM-Script-Writer-62850 commented Nov 22, 2016

Thanks, since you seem to understand more about images then me, mayber you can find a way to make this work feature as expected, see res/main.js lines 746 through 753
there is a css feature to adjust brightness/contrast, but it operates as 0-100 for darkness then 101-inf for brightness, i need to make that match what convert does

@yoder375
Copy link
Author

Hi, thanks for the reply. I'll have a look at it, sure. My math is a bit
rusty, but the answer lies in how the CSS filter computes its values, which
mathematically makes sense...You're adjusting the slope of the color
values, and as the slope goes vertical, that's an infinite value. Now
Imagemagick, OTOH, is calculating it in such a way that an infinite slope
is 100%, which to a user makes sense but in the math world does not.

For reference:

https://www.imagemagick.org/script/command-line-options.php#brightness-contrast
https://www.w3.org/TR/filter-effects-1/#contrastEquivalent

The trick will be to make the math work out the same. One other approach
might be to create your own SVG filter function instead of the contrast
function given in the link above instead of trying to fit the math into the
function.

I'll brush up best I can and give it a shot. Any math geeks around are
probably slapping their foreheads at me right now haha.

On Tue, Nov 22, 2016 at 4:48 AM, GM-Script-Writer-62850 <
[email protected]> wrote:

Thanks, since you seem to understand more about images then me, mayber you
can find a way to make this work feature as expected, see res/main.js lines
74 through 753
there is a css feature to adjust brightness/contrast, but it operates as
0-100 for darkness then 101-inf for brightness, i need to make that match
what convert does


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#38 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AWjha7l4wMHFaq1MjY9BR8l1r6o0BRerks5rAtZxgaJpZM4K5EKK
.

@GM-Script-Writer-62850
Copy link
Owner

If you use the editor and edit a line art image do you have this issue?
please check both edited to line art and scanned as line art

  • it does convert to line art before changing brightness/contrast on line 977 of index.php

if this also affects the editor i will need to find a way to detect line art images

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

2 participants