Using the Gimp to automate “cleaning” of scanned B&W images

Sometimes I play around with translating manga for fun. It doesn’t really seem to get me much of anything except for lots of requests from punks to translate their favorite naruto doujinshi, but it is fun and relaxing with the bonus that I learn some cool casual Japanese.

I like to translate with a program I wrote for manga translation that puts all the text in the bubbles and whatnot, so I need to have scans of the manga to work from. So sometimes I’ll scan manga.

The problem is that the scanner I have now doesn’t do a great job of getting nice clean images. I often use (when I’m not feeling too lazy) pnyxtr’s scan cropping program and his great scan rotation program, but if you have nasty scans that doesn’t help much.

Since I’m both poor and lazy, and have a small amount of moral fiber, I use The Gimp for my image-editing needs. The Gimp has a nice scripting interface using a kind of baby scheme, so I wrote a script that will take a grayscale image, run the despeckle filter on it, re-level the image so that whites are whiter and blacks are blacker, then resizes the image to a reasonable size and converts it to a fixed number of colors. That makes the straight scanner output look just dandy, if you choose proper values for the high and low thresholds, and also automates a lot of clicking that I would have to do otherwise.

So in the off chance that anyone is interested, here is a Gimp script that will do all of that. If you place it in your proper gimp script location – on Linux or Mac OSX that would be ~/.gimp-2.2/scripts/ (or possible ~/.gimp-2.0/scripts/), and on Windows if you use the version of Gimp that I am using you can look in its application folder for something like a share/scripts folder and drop it there. On your next start-up of the Gimp you should see a new Script entry “Manga->DarkenResize” that will pop up a dialog and ask you for some values, with reasonable defaults specified.

You can get the script here: mangaDarkenResize.scm

One thing that annoys me is that I still have to manually set each picture to “Greyscale” mode. I should be able to do this automatically, but I don’t know much about the Gimp, so I’m punting on that for now. It is also possible to use the Gimp in a batch processing mode, which would be totally awesome, but I haven’t had time to make that work with this script. If someone makes any headway on that area, please let me know.


Posted

in

by

Tags:

Comments

14 responses to “Using the Gimp to automate “cleaning” of scanned B&W images”

  1. Douglas Avatar
    Douglas

    I may have to try that, although I don’t use the GIMP much. I’ve got a similar tweak in Photoshop CS that does everything but rotate and crop. I find that I generally have to do that manually because I can’t get my books to stay in the same place on the scanning bed. It would be easier if I cut up my books, but I like them too much!

    Now I feel guilty for not finishing “Shouts of Nothingness” that I started a year and a half ago!

  2. egonist Avatar
    egonist

    U SUCK U SUCK U SUCK U SUCK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1

  3. fugu Avatar

    Well, you’re entitled to your opinion, but I don’t agree.

  4. L Avatar
    L

    How do you figure out what numbers to enter in? I’ve been playing with it for a long time but I haven’t figured out how the numbers relate to how the image should be darkened or lightened.

  5. FuguTabetai Avatar

    I’ve been using

    ;; threshold values
    (low_cutoff 65)
    (high_cutoff 165)

    and that works well for scans when I use my scanner default settings. Basically the higher you make low_cutoff the more white pixels you will have. The lower you make high_cutoff, the more black pixels you will have.

    Since I have changed how I scan, I’ve written a few more versions of the script. Also:

    For things that have lots of black that you might want to touch up by hand, try the Despeckle filter. Create a copy of the entire image, and despeckle with
    Adaptive: off
    Recursive: on
    Radius: 3
    Black Level: -1
    White Level: 256

    Put that layer on top. Layer modes that look good:
    – Burn (Darkens stuff up, you can lose some lights that you might want)
    – Overlay (Not as dark as burn)
    – Darken only (Darkens a lot, but not as much as multiply.)
    – Multiply (Really darkens things up a lot. More than Burn.)
    – Soft light (makes lights lighter and darks darker, but leaves some annoying specks still)

    It looks like this could be automated, but it really does darken up the image a lot. So maybe I will stick with just doing it by hand for some images for now. In general though, this would automate well.

  6. Jack Avatar

    Hello.

    Im an extremely newbie with this GIMP. Had it downloaded and installed yesterday only (‘coz its FREE! ).

    Im interested in learning on how to Clean Manga. And i want to try your automated script. But being i noob, i dont know how to install the script. Do i just copy your script and save it in *.ini format using a NotePad? If i had this done, how to i run it?

    Please give me some advice.

    Thanks.

    Jack

    🙂

  7. Jack Avatar

    Hello again.

    What i newbie i am. I had it figured it out!
    He-he-he!

    Im using windows. I had just right-clicked on your script link and saved it as it is (*.scm) under the following directory:

    C:\Program Files\GIMP-2.0\share\gimp\2.0\scripts

    When i rebooted GIMP, i found the script under “Script-Fu”.

    I really runs very smoothly. So I’ll just be cleaning the dialogs and sounds then. Thanks a lot.

    Jack

  8. Tom Avatar
    Tom

    Hello

    I am having difficulty in getting your script to run on gimp 2.6.11 (i think that is there version I’m using). It appears with this message

    Error: eval: unbound variable:

    Any thoughts on how to fix this?

    Thanks

  9. fugu Avatar

    it looks like it is complaining about an unbound variable, but are you missing another line from the error message? If it doesn’t even say what variable is unboud then I am not sure what is going on.

  10. anon Avatar
    anon

    there is an easier way to do cleaning.Actually this is from my personal
    experience.first,open the scan,then go to color,choose brightness and
    contrast and then move the contrast upward.that’s it! and if u find out
    anything just erase it.im new in using gimp so i dont know anything

  11. Anonymous Avatar
    Anonymous

    my script does that and more. generally playing with contrast is the first step.

  12. stargood Avatar
    stargood

    I made one change to the script by moving the menu address to the “script-fu-menu-register” command which is used in GIMP 2.6. I am using GIMP 2.6.11 and it loads and seems to be functioning well. My results are not too great, but I may just need to play with the settings a bit. I am trying to remove a yellowish background from scans that are otherwise quite good. In any case, thanks for this script. It will certainly help in my learning to write script-fu!

  13. stargood Avatar
    stargood

    Hey, I was just now at your home page. Many congrats on the birth of your son Alan!

  14. FuguTabetai Avatar

    Hope you find the script useful! If the background is yellow, that probably means that you scanned in the image in color? That would be a problem. You should change to grayscale first, then you might see better results. Let me know if you have any questions! I think I listed the settings that I use above, and they work pretty well.

Leave a Reply

Your email address will not be published. Required fields are marked *