Results 1 to 6 of 6

Thread: Split and crop jpg using black background

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    25

    Split and crop jpg using black background

    I'm looking for a way to split and crop scanned images to smaller jpg's using a black background. This way I'd like to devide several shop-tickets scanned together as one jpg, into seperate jpg-files.

    I hoped to do this in Excel-VBA, but I can't seem to find out how. Now maybe I can do this with writing some *.vbs using the build-in Windows API, can I?

    Thanks

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Split and crop jpg using black background

    Splitting an image into smaller images is easy in theory. Determining where to split can be exremely difficult depending on the requirement. If only splitting say "in half" or "in quarters" then that is easy enough. Howver, VB does not support saving to JPG format. So you'd be able to read a JPG file, but not save in JPG format without help. There is a JPG DLL floating about, though I have never used it. Using GDI+ can save in JPG format. If JPG format is not a concern, VB can save in bitmap format without any problems.

    Bottom line, can you be much more specific and descriptive with what you are trying to do, maybe even provide a sample of these shop tickets?

    P.S. I think I can visualize what you are attempting. I think this has potential to be a major undertaking. Hopefully the background the tickets are layed over, compared to the foreground of the actual tickets, is sharply contrasted.
    Last edited by LaVolpe; Sep 13th, 2009 at 09:47 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    25

    Re: Split and crop jpg using black background

    My project:
    I'm trying to automate Excel, putting all my bills, payments, invoices and shop-tickets into one sheet. When I click a line in the sheet the scanned jpg-image pops open.
    I've found a way in Excel-VBA to change jpg's into a readable pdf's using a OCR-shell. Then the pdf's are written with regular expressions using data in a second sheet to create a line for each existing pdf, with company/shop-name, date and total price, .... Atferwards it renames these pdf-files with these found keywords.
    So I get a file like "20090828 Supermarket food 45.12.pdf" linked to a line in the excel-sheet to be calculated with all the other bills and bank-transfers...

    Problem:
    Now I'm trying to also scan many small sales-tickets together with a black background, saving time. Automaticly devide them into smaller jpg's on the darker background found within every jpg scanned. Using my Excel-VBA code with help of the SHELL-commands to standard Windows API's or installed programs and *.vbs-scripts.

    So what shell-instruction or *.vbs can I write to test split, crop and read the color of pixels from a jpg-file. If I know how to read the color of a jpg and know how to crop and save it, then I can try to write some code to find where to crop the image....

    Maybe there is already some code that does this or a small program. But so far I only found Photoshop-Elements which it expensive and not a standard program in Windows.

    Can't I use Paint or some DLL in XP?

    Thanks.

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Split and crop jpg using black background

    Quote Originally Posted by onidarbe
    Can't I use Paint
    If this doesn't need to be automated. Paint is ideal
    1. Open the JPG in Paint
    2. Use the rectangular selection tool
    3. Drag/crop the smaller image with the tool
    4. Use menu: Edit | Copy To
    5. Save the selection to a new jpg file
    6. Repeat for the other images

    Image processing via code is no small task.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    25

    Re: Split and crop jpg using black background

    Well, it has to be automated

    So how can I:
    1) Read a color of a specific pixel
    2) crop a image
    3) save it as a jpg

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Split and crop jpg using black background

    1. Extract the pixels to an array and process the array. Each pixel is a RGB value expressed in either 3 or 4 bytes depending on how you extract those pixels.
    This site is where I began learning about image storage and manipulation. Jump to the lower half of the screen for topics related to bitmaps. JPGs when read by VB are converted to bitmaps internally.

    2. You will need to process the pixels to determine that. You probably want to look for lighter pixels to help distiguish the ticket from the background. You might want to google for Magic Wand to see if you can find any VB examples. Most graphics programs use magic wands for crop selection.

    3. Use GDI+ or locate any 3rd party DLLs to save as JPG. As I already mentioned, VB cannot save images to JPG format.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Posting Permissions

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



Click Here to Expand Forum to Full Width