cartoonist icon indicating copy to clipboard operation
cartoonist copied to clipboard

[Feature request] A flag to change the contrast threshold

Open jakewilliami opened this issue 3 years ago • 3 comments

I'm not sure if this is still being worked on, but I really like the idea. One thing I would love to see is a flag to change the contrast threshold.

For example, consider the following the input image: 1

Currently, this script produces this output: 2

But if one could increase (or decrease?) the contrast threshold, then lighter lines would show up as solid.

I would provide code suggestions but I've no idea if this is possible with the current libraries... Let me know! :-)

jakewilliami avatar Jan 30 '21 03:01 jakewilliami

Hi, this is a great idea! I'm actually fighting the same problem myself, but it didn't occur to me I could add an option to solve this. Currently I'm working around it by preprocessing the images and first giving them the desired threshold in GIMP.

I still use the tool, but it's a while since I created it. Would you be willing to work on such improvement? I don't know from the top of my head how hard it would be to add this. I took a quick look and I see this in the code:

# Threshold
"$src_dir/lib/localthresh" -m 1 -r 65 -b 5 -n yes "$in_file" "$out.png"
"$src_dir/lib/isonoise" -r 3 "$out.png" "$out.png"

Those are scripts from here: http://www.fmwconcepts.com/imagemagick/

  • http://www.fmwconcepts.com/imagemagick/localthresh/
  • http://www.fmwconcepts.com/imagemagick/isonoise/

Both have certain parameters (if you scroll down the respective pages, you'll see full documentation), but I think it would require a bit of trial and error to see what we can do and what would make sense the most.

Ideally the option would be something like cartoonist.sh -t 5? Where I could put different number instead of 5, like on a scale from 1-10, and see which one makes the best output for the picture at hand. What do you think?

honzajavorek avatar Jan 30 '21 20:01 honzajavorek

Hi @honzajavorek. Thanks for the response!

I actually do have some free time today, so I'll make a fork and see what I can do!

jakewilliami avatar Jan 30 '21 21:01 jakewilliami

Awesome! Please report back any findings, even if you end up in a dead end 🚀

honzajavorek avatar Jan 30 '21 22:01 honzajavorek