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

[Feature] Inter-panel White Space Cropping #804

Open
WirlyWirly opened this issue Jan 7, 2025 · 8 comments
Open

[Feature] Inter-panel White Space Cropping #804

WirlyWirly opened this issue Jan 7, 2025 · 8 comments

Comments

@WirlyWirly
Copy link

WirlyWirly commented Jan 7, 2025

Hello,

I'm coming to KCC as a long-time user of MangAi, which unfortunately has been EOL since the developer developed a sickness.

Therefore, I've found KCC and so far it's been working great! However, I don't see an option to perform inter-panel cropping to remove white-space.

As an example, I've attached a few comparison images; The first is the original image, secondly the KCC output, and finally the MangAi output with an example of horizontal white-space cropping.

Device: Kobo Forma (1440x1920)

While the images appear to be the same size, this is only because GitHub stretches them to fit your display. Only the third image is actually representative of what you'd see on the screen of an eReader (Kobo Forma @ 1440x1920)

Original (2138x3038)
original

KCC (1285x1920) | CroppingPower=3.0
kcc

MangAi (1440x1920) | Horizontal cropping, no option to remove page numbers
mangai

Notice that the panels in the third image have been horizontally cropped of white-space, a small threshold was left so that the images don't touch, and finally it was all blown-up as needed to fill the screen (while maintaining the correct aspect-ratio).

MangAi will also perform vertical white-space cropping, not just the margin white-space. Meaning it essentially passes over the entire image twice; First horizontally and then again vertically to remove all white-space. I couldn't find an image with vertical white-space between panels to use as an example, but it's essentially the same thing as horizontal cropping but done vertically.

While not a dramatic difference here, with certain pages it can definitely increase the used real-estate when all horizontal and vertical white-space has been removed... Also, MangAi uses ImageMagick, which seems to do a sharper job of resizing, but that's just me...

Thoughts?

@WirlyWirly WirlyWirly changed the title [Feature] Horizontal White Space Cropping [Feature] Inter-panel White Space Cropping Jan 7, 2025
@axu2
Copy link
Collaborator

axu2 commented Jan 8, 2025

@neyney10 in case you are interested

@neyney10
Copy link
Contributor

neyney10 commented Jan 9, 2025

Sounds interesting.
@WirlyWirly I couldnt run the MangAi as it requires a license. How does it work exactly - do u have a way to control how much space from horizontal/vertical white lines to remove? Like, in your example, you have shown that the app reduced the distance between the panels, but still kept some distance - do u have a way to control this distance? And is it an important feature?

Also - how does it work while also cropping the margins of a page? Is there any unique behavior?

@WirlyWirly
Copy link
Author

WirlyWirly commented Jan 9, 2025

@neyney10

You can request a 30-day trial license from the gui. Launch mangai_gui.jar and go to Help > Get license > Request trial license. I think this still works, just enter a valid e-mail for the trial-license to be sent to.

The eReader configuration and image-editing optionas are saved in a koboForma.properties file inside the mangai\data directory. This .properties file is used by both the gui mangui_gui.jar and the headless mangai.jar

As for how the inter-panel cropping works, I can't say exactly because it's a closed-source program. However, since it's using ImageMagick's convert.exe command for all the image edits, I believe MangAi leverages the -chop flag to perform the inter-panel cropping (A.K.A, "chopping").

For the page margins, that is a separate option from the inter-panel chopping. Again, looking through the ImageMagick docs for convert.exe, I believe it's leveraging the -trim flag to handle the margins.

Looking in my koboForma.properties file, these are the lines referencing the margins and inter-panel chopping...


#    @auto_trim          Determines whether to auto trim the white space around the edges of the manga pages
#                        Acceptable values: true, false
#                        Recommended: true

...

auto_trim = true

...

#    @chop_white_rows       Chops horizontal white bars within a scan (i.e. finds white rows, removes them, shifts sections of image to cover the empty space).
#                           Uses @trim_cancel to prevent too much chopping.
#                           Acceptable values: true, false
#                           Recommended: true (if using 6" or smaller ereader), false (if using large screen ereader, no need to waste time on this)
#    @chop_white_columns    Chops vertical white bars within a scan (i.e. finds white columns, removes them, shifts sections of image to cover the empty space).
#                           This is especially useful if you are processing classic 4 or 6 panel manga as most manga will not contain white columns (other than the borders which are handled by @auto_trim).
#                           Uses @trim_cancel to prevent too much chopping.
#                           Acceptable values: true, false
#                           Recommended: true (if using 6" or smaller ereader), false (if using large screen ereader, no need to waste time on this)
#    @chop_fuzz             If @chop_white_rows or @chop_white_columns is enabled, this is the fuzz value to use when chopping.
#                           Acceptable values: an integer between 0 and 100, inclusive
#                           Recommended: 25 (or 15 if you want to play it safe)

...

chop_white_rows = true
chop_white_columns = true
chop_fuzz = 15

If you'd like to try the program yourself, you'll need convert.exe from ImageMagick. However, like I said MangAi is dead, so it won't work with the latest version of ImageMagick. You'll need v7.0.10-34 Q16.

$ ./ImageMagick/convert.exe --version
Version: ImageMagick 7.0.10-34 Q16 x64 2020-10-08 http://www.imagemagick.org

Also, this python library for the ImageMagick API looks quite established. Haven't tried it myself though: wand

@neyney10
Copy link
Contributor

Like this?
(Without margin crop, chop only 95% of the empty section)

inter_ex1n001
inter_ex2bl002

@WirlyWirly
Copy link
Author

WirlyWirly commented Jan 10, 2025

Yeah, looks perfect to me.

Out of curiosity, what did you use to make that .gif? I'm assuming Pillow, but maybe Share X?

@neyney10
Copy link
Contributor

I saved the images from the algorithm to the disk (Pillow). And then merged them into a gif using the site: https://ezgif.com/.

Do you know of any edge cases for this inter-panel cropping that I should look out for and check?

@WirlyWirly
Copy link
Author

Only thing that comes to mind is when the scans are poor and there's speckling.

Don't see that as much these days, but I suppose that's what fuzzy detection is for.

@WirlyWirly
Copy link
Author

WirlyWirly commented Jan 10, 2025

Actually, one thing I remembered is that with some freeform artwork, it will get mashed together when the spacing is chopped.

Think of like a dude throwing a basketball, there's space that would be lost there.

Not much you can do about that I suppose, just something to be aware of when using the option.

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

3 participants