Not a member? Register now!
Announcements
Like us on Facebook, follow us on Twitter!
Manga News: Check out these new manga (8/10/15 - 8/23/15).
New Forums: Visit the new forums for Boku no Hero Academia!
Translations: Bleach 639 by cnet128 , Gintama 555 (2) , One Piece 796 by cnet128
New Reply
Results 1 to 4 of 4

Thread: Single Comic Frame Splitter

  1. #1
    Registered User 初心者/ Shoshinsha / Beginner Satanic Cult's Avatar
    Join Date
    Aug 2015
    Location
    Retjewik
    Country
    Germany
    Age
    26
    Gender
    Male
    Posts
    3
    Post Thanks / Like

    WSJ Pirate Single Comic Frame Splitter

    The following is a guide to batch generating single frame images (as single files) from scanned Manga pages.
    Motivation: Yesterday evening, while reading Bakuman on my kindle I became painfully conscious of how small the damned screen was. I thought to myself "wouldn't it be nice, if each and every frame were blown up on one page of my kindle? One could actually appreciate the artwork then..." So I bravely set out on this quest, into the world wide web (port Google).

    You will need:
    Gimp2,
    BIMP batch image plugin (gimp2),
    Divide Scanned Images Plugin (gimp2),
    Autoit3

    Step 1: Renaming Scans
    1.a:The scans must be renamed, such that the two gimp plugins and the autoit scripts can parse the files in the correct order. Assuming your scans are in a folder, already in order, select all files in the folder by left-clicking any file once and pressing CTRL+A. Once all of your scanned files are selected, right-click the FIRST file in the list and in the drop down menu select rename. Name the file "B" (without quotes, just the letter B). This should rename all files in the folder to:

    B (1)
    B (2)
    B (3)
    B (4)
    ...

    1.b: Install Autoit3. Now we must rename our renamed scan files yet again using an Autoit script. Save the following script into the same folder as the scans as "scanRename.au3"

    Code:
    $imgcount = 9999; change this to how many files are in the folder
    $k =0;
    Do
    @workingDir & "\B1 (" & $k & ").jepg")
    	If ($k < 10) Then
    		FileMove(@workingDir & "\A (" & $k & ").jpg",@workingDir & "\IMAGE_000" & $k & ".jpg")
    	ElseIf ($k < 100) Then
    		FileMove(@workingDir & "\A (" & $k & ").jpg",@workingDir & "\IMAGE_00" & $k & ".jpg")
    	ElseIf ($k < 1000) Then
    		FileMove(@workingDir & "\A (" & $k & ").jpg",@workingDir & "\IMAGE_0" & $k & ".jpg")
    	Else
    		FileMove(@workingDir & "\A (" & $k & ").jpg",@workingDir & "\IMAGE_" & $k & ".jpg")
    	EndIf
    	$k=$k+1;
    
    Until $k = $imgcount+1
    Note: You can have at most 9999 Scanned files in the folder for this script to work.
    The Autoit script "scanRename.au3" will rename all files to:

    IMAGE_0001.jpg
    IMAGE_0002.jpg
    IMAGE_0003.jpg
    ...

    Check random images in the scan Folder if they are indeed in the correct order.


    Step 2: Batch Mirroring all images:
    Note: I will explain why we are mirroring all images in step 3. For this we will need to have Gimp 2 installed and also the Plugin BIMP. To install BIMP, follow the instructions on the plugin's website.

    2.a: To batch mirror the correctly named scans, we open up Gimp2. In the main menu of the Gimp2 interface we select File -> Batch Image Manipulation.... This will open up a window called "Batch Image Manipulation Plugin". Select "Add" in the upper left corner of this newly opened window. Then, in the Drop down menu, select "Flip or Rotate". This should open yet another smaller window "Flip or Rotate", select "Horizontally" (the left button) and press the "OK" button.
    Now we add our Scans Folder: Select "Add images", again in the "Batch Image Manipulation Plugin" window, and in the drop down menu select "add folders..." and select the folder with your scans. You should see a list of the scan files, with their full paths in the "Batch Image Manipulation Plugin" window. Now we must specify where the new mirrored images will be saved. First create a folder called "Mirrored Scans". Click the button (should be labeled as your computers username) next to "Output folder". Select the folder "Mirrored Scans" or any other folder. Now press "Apply". This brings up another window with a process bar, and can take a few minutes to compute. After the process is complete, press "Close".

    Step 3: Generating single-frame Files from mirrored Scans
    For this step you must install the second plugin for gimp: Divide Scanned Images Plugin (gimp2). Follow the instructions on the website.
    Open Gimp2. Select "Filters -> Batch tools -> Batch divide Scanned images". In the drop down menu labeled "Load from:" select the folder "Mirrored Scans"
    Set the following values to:

    Selection Threshold to 25.0
    Size Threshold 145.0
    Abort Limit 15.7

    Now , in thedrop down menu labeled "Save Directory:" select a folder to which all the single frames should be saved, for example "Single Image Output".

    3.b: Repeat Step 2 on the "Single Image Output" Scan folder. This way all single mirrored images are flipped back to normal. Note: the reason we do all this mirroring is to "trick" the Divide Scanned Images Plugin, since it parses images from Left to right, top to bottom. By flipping the images, we get the images in the right sequence, but unreadable, because the text is mirrored, but mirroring all these single frames takes care of that.

    Step 4: Corrections [Optional]


    As it happens, the "Batch divide Scanned Images" plugin is not perfect, and occasionally makes mistakes. The parser can get the order wrong, or skip a frame (maybe 1 in 400). You can play around with the Selection Threshold, Size Threshold and Abort Limit since this definitely plays a role, (I still am not entirely sure what the three parameters are doing, and they still could use some fine tuning). This is why I wrote a second Autoit script, which allows us to move images around in the folder. For example:
    There are ten images named IMAGE_0001, IMAGE_0002. IMAGE_0003, ... IMAGE_0010. And lets say that IMAGE_0006 is 4 frames too late, and should actually be IMAGE_0002. If we would manually rename all files correctly then we would have to rename a total of 6 times to iron out this mistake.
    the Autoit script takes care of this. Read the Manga from front to back, note down the images that are in the wrong place, and which image number they should actually be.

    Code:
    #include <WindowsConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <String.au3>
    #include <WinAPI.au3>
    #include <Array.au3>
    #include <File.au3>
    
    Global Const $CSVFILE = @WorkingDir & "\MangaShifterList.csv"
    Global Const $DELIM = ";" ;the delimiter in the CSV file
    Global $rawFile
    Global $vecArt
    Global $fileCount = 0;
    
    Func getList($dir_csv)
    	Local $vecArt ; array to which the list of artists is copied.
    
    	If _FileReadToArray($dir_csv, $rawFile, 1) Then
    
    
    		$vecArt = StringSplit($rawFile[1], $DELIM)
    
    		$fileCount = $vecArt[0]*0.5
    
    		For $w = 1 To $fileCount Step +1
    
    			Shift($vecArt[$w*2-1],$vecArt[$w*2])
    		Next
    
    	Else
    		MsgBox(48, "", "Error opening file!No File in: " & $dir_csv)
    	EndIf
    
    	If Mod(UBound($vecArt), 2) = 0 Then
    		MsgBox(48, "", "Error, uneven number of files specified")
    	EndIf
    
    EndFunc   ;==>getList
    
    getList($CSVFILE)
    
    
    ;//Core Functions
    
    Func Decimal_Place($numb)
    
    	If ($numb < 10) Then
    		Return "\IMAGE_000"
    	ElseIf ($numb < 100) Then
    		Return "\IMAGE_00"
    	ElseIf ($numb < 1000) Then
    		Return "\IMAGE_0"
    	Else
    		Return "\IMAGE_"
    	EndIf
    
    	MsgBox(0, "Error", "Decimal_Place fucked up")
    EndFunc   ;==>Decimal_Place
    
    
    Func RenameTemp($pageNumb)
    	FileMove(@WorkingDir & Decimal_Place($pageNumb) & $pageNumb & ".jpg", @WorkingDir &   Decimal_Place($pageNumb) & $pageNumb & "t.jpg")
    EndFunc   ;==>Rename
    
    Func Rename($pageNumb, $shiftNumb)
    	FileMove(@WorkingDir & Decimal_Place($pageNumb) & $pageNumb & "t.jpg", @WorkingDir & Decimal_Place($shiftNumb) & $shiftNumb & ".jpg")
    EndFunc   ;==>Rename
    
    
    Func Shift($pageNumb, $shiftNumb)
    	$delta = $shiftNumb - $pageNumb
    
    
    
    	If ($delta < 0 ) Then
    		;MsgBox(0,"Shifter","first if")
    		$delta = Abs($delta)
    
    		For $k = 0 To $delta Step +1
    			RenameTemp($pageNumb-$k)
    		Next
    
    		Rename($pageNumb, $shiftNumb)
    
    		For $k = 1 To $delta Step +1
    			Rename($pageNumb-$k, $pageNumb-$k+1)
    		Next
    
    	ElseIf ($delta > 0 ) Then
    
    		For $k = 0 To $delta Step +1
    			RenameTemp($pageNumb+$k)
    		Next
    
    		Rename($pageNumb, $shiftNumb)
    
    		For $k = 1 To $delta Step +1
    			Rename($pageNumb+$k, $pageNumb+$k-1)
    		Next
    
    
    	EndIf
    
    
    
    
    EndFunc   ;==>Shift
    Now create a file called "MangaShifterList.csv"
    in this file you write for example:
    4;3;104;100;309;305

    this means: file 4 must be file 3, file 104 must be 100, file 309 must be 305.
    Save the csv file and execute the Autoit3 script in the same folder as the scanned images. The Script will resort All of the images in the desired sequence.

    This took way too long to write. I hope someone uses this. jesus...

  2. #2
    Scanlator 中級員 / Chuukyuuin / Member Gradonil_Ral's Avatar
    Join Date
    Jun 2008
    Country
    Winterfell
    Gender
    Male
    Posts
    101
    Post Thanks / Like

    Re: Single Comic Frame Splitter

    So does that mean there's no zoom in Kindle? In that case, nice idea. And I'll applaud your effort, but, tbh, I'm not sure how many people would actually go through this whole process...

    Since I do not own a kindle, and my phone screen is big enough to enjoy most of panels (and when it's not I can simply zoom in), especially when I turn it horizontally, I did not read this tutorial word for word. But I think I still got the gist of it.

    Here's how I'd improve it:

    Instead of Autoit + scripts, I'd just use Advanced Renamer - it'll be much easier on less tech-savvy people (and maybe quicker?).

    I'd cut out the whole mirroring thing. If the problem is that manga if read from right to left and the plugin divides from left to right, then why not simply start off by numbering the pages backwards in the first place? After panel division, you'd just reverse the image order again.
    Renaming files in AR is instantaneous, which, I imagine, cannot be said about mirroring the pages, and then the separate panels.


    Also, fixing the order after the panel division should be much easier in AR since, after loading the files, you can turn on viewing thumbnails, which would serve as a panel preview. And you'd only need to drag&drop the files in the list to correct it. No need for noting down the image numbers and writing them into the script.
    Last edited by Gradonil_Ral; August 05, 2015 at 01:37 PM.

  3. #3
    Registered User 初心者/ Shoshinsha / Beginner Satanic Cult's Avatar
    Join Date
    Aug 2015
    Location
    Retjewik
    Country
    Germany
    Age
    26
    Gender
    Male
    Posts
    3
    Post Thanks / Like

    Re: Single Comic Frame Splitter

    Thanks for you feedback. And yea Its quite the process... to save time I usually combine 25 chapters into one folder and let the algorithms do their thing.

    The mirroring step cannot be skipped, since its not the sequence of pages that is in reverse order, but the sequence of panels as I'm sure you're aware of:
    You read the right panel before the left panel. However the Divide Scanned Images plugin parses the images in a document from left to right. For example If I run the plugin on a single Manga page, as seen in the image above, and do not mirror the images before and after, the gimp plugin will save 5 images in the following order: first the panel with text bubble 3 then the panel with text bubbles 1 and 2, then the panel with text bubbles 6, etc.
    What I'm planning on doing though, to get rid of the two mirroring steps, is to modify the plugin such that its engineered for manga panel parsing.

  4. #4
    Scanlator 中級員 / Chuukyuuin / Member Gradonil_Ral's Avatar
    Join Date
    Jun 2008
    Country
    Winterfell
    Gender
    Male
    Posts
    101
    Post Thanks / Like

    Re: Single Comic Frame Splitter

    Right. I didn't think this through ^_^;
    What I thought was that you could divide the pages normally and then reverse the divided pages' order to fix the problem... I guess I was too tired to notice that it would mean starting with the bottom panels first xD

    But yeah, if you could adjust the plugin so that it reads the panels from the right to the left, it would certainly save a lot of time.

New Reply

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts