Jump to content

Remove black bars on 100+ images


Recommended Posts

We recently had a football camp for kids and we have roughly 100+ images with a black bar above and below each image. Is there a way to crop out the top and bottom black bars as a batch process? I've been cropping each image with paint so far but I've been at this for a few days. I've searched google & google+autoit for cropping images but I didn't find anything that removes the bars. The images seem to have different heights.

IMG_2398.JPG

IMG_2360.JPG

Edited by aa2zz6
Link to comment
Share on other sites

Try this code whereas this loads only one image and crop it by seaching for 0xFF000000 (black) color. If the cropping is not fully proper because of still black borders then increate the $iTolerance value.

#include <GDIPlus.au3>
_GDIPlus_Startup()
Global $sFile = @ScriptDir & "\Images\IMG_2360.JPG"
Global $hImage = _GDIPlus_ImageLoadFromFile($sFile)
Global $sDLL = @ScriptDir & "\_GDIPlus_BitmapGetCropArea.dll"
If Not FileExists($sDLL) Then _CropDLL(True)
Global $hDLL = DllOpen($sDLL)
Global $tPos = DllStructCreate("int iPosX;int iPosY;int iPosW;int iPosH"), $iSeachColor = 0xFF000000, $iTolerance = 32
DllCall($hDLL, "bool", "_GDIPlus_BitmapGetCropArea", "ptr", $hImage, "struct*", $tPos, "uint", $iSeachColor, "ubyte", $iTolerance)
ConsoleWrite($tPos.iPosX & ", " & $tPos.iPosY & ", " & $tPos.iPosW & ", " &  $tPos.iPosH & @CRLF)
Global $hBitmap_Cropped = _GDIPlus_BitmapCloneArea($hImage, $tPos.iPosX, $tPos.iPosY, $tPos.iPosW, $tPos.iPosH, $GDIP_PXF32ARGB)
_GDIPlus_ImageSaveToFile($hBitmap_Cropped, StringTrimRight($sFile, 4) & "_cropped.jpg")
DllClose($hDLL)
_GDIPlus_ImageDispose($hBitmap_Cropped)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()

;Code below was generated by: 'File to Base64 String' Code Generator v1.20 Build 2016-12-01

Func _CropDLL($bSaveBinary = False, $sSavePath = @ScriptDir)
    Local $CropDLL
    $CropDLL &= 'TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA='
    Local $bString = _WinAPI_Base64Decode($CropDLL)
    If @error Then Return SetError(1, 0, 0)
    $bString = Binary($bString)
    If $bSaveBinary Then
        Local Const $hFile = FileOpen($sSavePath & "\_GDIPlus_BitmapGetCropArea.dll", 18)
        If @error Then Return SetError(2, 0, $bString)
        FileWrite($hFile, $bString)
        FileClose($hFile)
    EndIf
    Return $bString
EndFunc   ;==>_CropDLL

Func _WinAPI_Base64Decode($sB64String)
    Local $aCrypt = DllCall("Crypt32.dll", "bool", "CryptStringToBinaryA", "str", $sB64String, "dword", 0, "dword", 1, "ptr", 0, "dword*", 0, "ptr", 0, "ptr", 0)
    If @error Or Not $aCrypt[0] Then Return SetError(1, 0, "")
    Local $bBuffer = DllStructCreate("byte[" & $aCrypt[5] & "]")
    $aCrypt = DllCall("Crypt32.dll", "bool", "CryptStringToBinaryA", "str", $sB64String, "dword", 0, "dword", 1, "struct*", $bBuffer, "dword*", $aCrypt[5], "ptr", 0, "ptr", 0)
    If @error Or Not $aCrypt[0] Then Return SetError(2, 0, "")
    Return DllStructGetData($bBuffer, 1)
EndFunc   ;==>_WinAPI_Base64Decode

 

What you have to do is to read all images to an array to crop these images. :D

I wrote the DLL using FreeBasic to speed up this process. ;)

Edited by UEZ
Added tolerance parameter

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Another example.

#include <GDIPlus.au3>
#include <ScreenCapture.au3>
#include <File.au3>
#include <Array.au3>

Local $aFiles = _FileListToArray(@ScriptDir, "IMG_*.jpg", 1) ; $iFlag = $FLTA_FILES (1) = Return files only
;_ArrayDisplay($aFiles)
For $i = 1 To UBound($aFiles)-1
    $FileOut = @ScriptDir & "\" & StringRegExpReplace($aFiles[$i], "([^\.]+).([^\.]+)", "${1}Modified.${2}")
    ;ConsoleWrite($FileOut & @CRLF)
    _TrimBlackTopBottom(@ScriptDir & "\" & $aFiles[$i], $FileOut)
Next


Func _TrimBlackTopBottom($sFileIn, $sFileOut)
    Local $hBitmap, $hClone, $hImage, $iX, $iY
    _GDIPlus_Startup()
    $hImage = _GDIPlus_ImageLoadFromFile($sFileIn)

    ; ---------------- Get Black boundaries -------------------------------
    Local $iW = _GDIPlus_ImageGetWidth($hImage), $iH = _GDIPlus_ImageGetHeight($hImage) ;get width and height of the image
    Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
    Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsDrawImageRect($hContext, $hImage, 0, 0, $iW, $iH)

    Local $tBitmapData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $iW, $iH, BitOR($GDIP_ILMWRITE, $GDIP_ILMREAD), $GDIP_PXF32ARGB) ;locks a portion of a bitmap for reading and writing. More infor at http://msdn.microsoft.com/en-us/library/windows/desktop/ms536298(v=vs.85).aspx
    Local $iScan0 = DllStructGetData($tBitmapData, "Scan0") ;get scan0 (pixel data) from locked bitmap
    Local $tPixel = DllStructCreate("int[" & $iW * $iH & "];", $iScan0)
    Local $iPixel, $iRowOffset

    For $iY = 1 to $iH / 2
        $iRowOffset = $iY * $iW + 1
        $iPixel = DllStructGetData($tPixel, 1, $iRowOffset + $iW / 2) ;get pixel color
        ;If StringRegExp(Hex($iPixel), "FF0[0-4]0[0-4]0[0-4]") = 0 Then
        If StringRegExp(Hex($iPixel), "FF0[0-9A-F]0[0-9A-F]0[0-9A-F]") = 0 Then ; Get not so dark as above line.
            $iTop = $iY
            ExitLoop
        EndIf
    Next
    For $iY = $iH -1 To $iH / 2 step - 1
        $iRowOffset = $iY * $iW + 1
        $iPixel = DllStructGetData($tPixel, 1, $iRowOffset + $iW / 2) ;get pixel color
        ;ConsoleWrite(Hex($iPixel) & "  " & $iY & @CRLF)
        ;If StringRegExp(Hex($iPixel), "FF0[0-4]0[0-4]0[0-4]") = 0 Then
        If StringRegExp(Hex($iPixel), "FF0[0-9A-F]0[0-9A-F]0[0-9A-F]") = 0 Then
            $iBottom = $iY
            ExitLoop
        EndIf
    Next
    _GDIPlus_BitmapUnlockBits($hBitmap, $tBitmapData) ;unlocks a portion of a bitmap that was locked by _GDIPlus_BitmapLockBits
    ConsoleWrite($iTop & "  " & $iBottom & @CRLF)
    ; ---------------- End of Get Black boundaries -------------------------------

    ; Create 24 bit bitmap clone
    $iX = _GDIPlus_ImageGetWidth($hImage)
    $iY = _GDIPlus_ImageGetHeight($hImage)
    ;ConsoleWrite($iX & " x " & $iY & @CRLF)
    $hClone = _GDIPlus_BitmapCloneArea($hImage, 0, $iTop, $iX, $iBottom - $iTop, $GDIP_PXF24RGB)

    ; Save bitmap to file
    _GDIPlus_ImageSaveToFile($hClone, $sFileOut)
    ;sleep(500)
    ;ShellExecute("GDIP_Image.jpg")

    ; Clean up resources
    _GDIPlus_ImageDispose($hClone)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_GraphicsDispose($hContext)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()
EndFunc   ;==>_TrimBlackTopBottom

 

 

Edited by Malkey
Instead of searching for the black from centre to top and bottom where black in the centre will give a false reading of the black border. Change searching for "not black" from top and bottom towards centre of image.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...