GM-Script-Writer-62850 / PHP-Scanner-Server

Allows you to use your Linux install as a web based scanner server thus allowing you to scan with any web enabled device; Now supports server side printing! (As of 1.4.11)
59 stars 17 forks source link

Brightness/Contrast in Lineart mode #38

Open yoder375 opened 7 years ago

yoder375 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 < notifications@github.com> 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 https://github.com/GM-Script-Writer-62850/PHP-Scanner-Server/issues/38#issuecomment-262220941, or mute the thread https://github.com/notifications/unsubscribe-auth/AWjha7l4wMHFaq1MjY9BR8l1r6o0BRerks5rAtZxgaJpZM4K5EKK .

GM-Script-Writer-62850 commented 7 years ago

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

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