Solved

How can I use Photoshop to remove frames added to images through Photoshop?

Posted on 2011-03-02
14
351 Views
Last Modified: 2012-05-11
I have several hundred images that I have added a standard sized frame to, via Photoshop. While using a software application that detects duplicate images, it has become apparent that because of the frame, the algorithms in the software application do not function very well.

I'm wondering if there is a relatively easy way to automate the process of removing the frame from several hundred JPEG images. The same frame was applied to each image, although the size of each image varies. I have attached a screenshot of one of the images.

My first thought was to use a standard crop, which for example, would be positioned 5 pixels from each side. However, I have no idea how to accomplish this and to automate it, if in fact it is even possible.

Any suggestions would be greatly appreciated.
Frame-1.jpg
0
Comment
Question by:photoman11
  • 5
  • 4
  • 3
  • +1
14 Comments
 
LVL 57

Expert Comment

by:Pete Long
ID: 35019533
just resize one (whilt recording what you do) then batch reset all of them this is for resizing but the process will be the same http://shapeshed.com/journal/batch_resizing_in_photoshop/
0
 
LVL 26

Expert Comment

by:David Brugge
ID: 35020769
@PeteLong,

I'm not sure that this will work. The problem is that the borders are proportional to the images. If you double the size of an image, what started out as a 5 pixel border is now a 10 pixel border.

Resizing the image resizes the border.

Instead I would set up an action where you use the Image>Trim... and select either "Top Left Pixel Color", or "Bottom Right Pixel Color".

Depending on the antialiasing, this may not work either, but is worth a try.

The next method that I would try is an action where you used the Magic Wand with a relative low tolerance to select the border, and then used Select>Modify>Expand by... to add another pixel, then Select>Inverse the selection and then Image>Crop. You don't want the Magic Wand setting so high that it selects part of the image as well as the border.

ALWAYS work on duplicates of the files, NEVER on the originals.  (But you knew that)
0
 

Author Comment

by:photoman11
ID: 35021296
D_Brugge,

I've never used the Trim function before so I followed your instructions and read about what it does in the Help. I must be missing something because I tried it about 4 different ways, including creating a duplicate layer, and after each time of doing it, the original image looked exactly the same as it did before I did it.

Do you have any idea what I'm missing?
0
 
LVL 26

Accepted Solution

by:
David Brugge earned 250 total points
ID: 35021687
The trim function looks at the color of the pixel in the corner and crops away all of that color. Where this can go wrong is if the image is saved as a jpeg and what started out as a single color border is now made up of a series of pixels that are very close in color, but not exact. Unfortunately, the trim function does not have any "fuzzyness" settings. It only looks for adjacent colors that are exactly the same.

In which case, my second suggestion should work. As I hinted at, this will not work if the border touches on an area of the image that is very close in color such as someones dark pants. This might take a little experimenting to get the settings correct, OR, there may be only a few images that this DOESN'T work on and you can do those by hand.

Wish I had a better solution, but that's about it.

Another thought occurred to me. Have you tried cropping the frame off of a single image and tested your duplication algorithm? It's possible that the cropped image won't show as a match, in which case, there's no point going to the trouble of cropping the frames.
0
 

Author Comment

by:photoman11
ID: 35021828
That was a great suggestion. I will definitely experiment before I go through all the effort. Good idea. I guess that's why you are call the expert!
0
 
LVL 38

Assisted Solution

by:BillDL
BillDL earned 250 total points
ID: 35022132
I cannot afford Photoshop, but if it is of any help to you in translating the theory into a batch process in photoshop, here's how I would do what you are asking using the tools I have available.  My general choice for batch processing images is the free image viewer/editor IrfanView (http://www.irfanview.com) simply because the command line options are quite intuitive.  There are other free image editing applications out there that support batch processing from the command line, such as The Gimp (http://www.gimp.org), Image Magick (http://www.imagemagick.org), XnView and nConvert (http://www.xnview.com/en), but I haven't done much with them.

First off, IrfanView allows you to create a report about each image, and in that image you have the image dimensions and orientation, amongst other values.  It is easy enough to capture the height and width of an image from the report data using a batch file.

The second useful IrfanView command line switch is the "crop" one which uses  parameters like this:
/crop=(x,y,w,h) - crop input image: x-start, y-start, width, height
eg.
i_view32.exe c:\test.jpg /crop=(10,10,300,300)
which does this:
Opens "c:\test.jpg" and crops image to: (x-start=10, y-start=10, width=300, height=300)

So you could have a batch file walk through a directory and sub-directories, starting from wherever you tell it to start, doing as follows for each JPG file it finds:
1. Create a report as a temporary file
2. Search the report for the line containing "Image dimensions" and store the Height and Width pixel dimensions as variables for re-use
3. Using the dimensions, calculate the area you want to keep (which for a 5 pixel border would mean deducting 10 pixels from the overall dimensions)
3. Tell IrfanView to crop the image, starting from 5 pixels across and 5 pixels down, to your new image size that will be minus the 5 pixel border.
4. Optionally output the cropped images as a new ones with names to indicate they have been cropped.

For example, say the current image is reported by IrfanView as being 800 wide by 600 high.  Your starting points will always be  (x-start=5, y-start=5).  To crop out the 4 pixel border your mage needs to be cropped by 10 pixels on all sides, so your new image will be 790 Wide by 590 High.  The command to crop that image would be:
i_view32.exe c:\test.jpg /crop=(5,5,790,590)

I tested the following batch file on your attached image and it correctly trimmed off 5 pixels from each side and saved it out as a new file with "_cropped" added as a suffix.  If you don't want to use IrfanView, then maybe you can translate the theory to some other application that supports command line batch processing.

As I said, this is just how I would do it in the absence of Photoshop.

 
@echo off

SetLocal EnableDelayedExpansion

set BaseDir=C:\Images
set IVIEW=C:\Program Files\IrfanView\i_view32.exe
set XStart=5
set YStart=5
set Borders=10
set CurrDir=%~dp0
set CurrDir=%CurrDir:~0,-1%
set TmpReport=%CurrDir%\_tmpReport.txt

if exist "%TmpReport%" del "%TmpReport%" > nul

for /f "tokens=* delims=" %%a in ('dir /on /b /s "%BaseDir%\*.jpg"') do (
    set ImgName=%%a
    set ImgPath=%%~dpna
    "%IVIEW%" "!ImgName!" /info="%TmpReport%" /killmesoftly
    for /f "tokens=4,6 delims= " %%A in ('type "%TMPREPORT%" ^| find /i "Image dimensions = "') do (
    set WIDTH=%%A
    set /a NewWidth=!WIDTH!-%Borders%
    set HEIGHT=%%B
    set /a NewHeight=!HEIGHT!-%Borders%
    "%IVIEW%" "!ImgName!" /crop=^(%XStart%,%YStart%,!NewWidth!,!NewHeight!^) /convert="!ImgPath!_cropped.jpg" /killmesoftly
    del "%TmpReport%" > nul
    )
)   
pause

Open in new window

0
 

Author Comment

by:photoman11
ID: 35022877
That is very impressive. I didn't know that application had commandline capability. I'll have to look into it. Thank you very much.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 38

Expert Comment

by:BillDL
ID: 35024828
Remember, it was just an alternative suggestion that steers away from your request for a solution using Photoshop.  I don't know much about photoshop, if the truth be told, but it seems a real shame to have such powerful, expensive, and fully featured software that isn't capable of being contralled this way when there is free software that is. Photoshop supports the creation of Macro Scripting, but that's where my knowledge ends.  I suppose sometimes there have to be different tools for different jobs.

A couple of other things to be aware of if you do test this out using IrfanView:
IrfanView can be used as a "portable" application that runs from a USB Flash Drive.  You either have to install it to the hard drive and then copy the program folder to your Flash Drive, or download the ZIP version and extract the contents to the Flash drive.  It stores its settings in an *.INI file in the program folder.  Some of the "batch" processing options available in the user interface are not available as explicit command line switches, but the last used batch settings from the INI file are used.

I am not sure if you need to keep the "metadata" that Photoshop writes to images that it has encoded.  I know that it writes a bunch of its own unique tags into image files that can be used by the program, but whether you need these tags or not is something to consider.  Irfanview may strip out some of the tags in processing an image file.

Like many other free programs these days, you will probably be prompted during setup to install the Google Toolbar or similar.  Just de-select that and proceed.  You should also be aware that even though it can be run as a "portable" application, it can still write to your registry.  Go to the Options menu > "Properties/Settings" > open the "Extensions" section.  The check-boxes in that section will write to your registry if checked.  I suggest that if you are just testing the program, DON'T check any of the file extension boxes.  That way it won't assume an association with any of the image file types probably assigned to Photoshop already.

Full command line usage can be found in the Help dialog and also in the "i_options.txt" file in the program folder.

If you need an explanation of any parts of my batch file, then all you need to do is ask.

The only lines in the batch file you need to change is:
set BaseDir=
I had it set as:
set BaseDir=C:\Images  
but the master folder of your images will no doubt be different.  I suggest that you fist test this on a folder containing COPIES OF your originals just in case something goes strangely wrong.

If you want to change the "_cropped" suffix that is applied to names of files processed, then you only change it in one place where you see:
/convert="!ImgPath!_cropped.jpg"
onthe line that starts with "%IVIEW%"

Hopefully it will work for you, but there have been odd results recently with a couple of my batch files run on Windows Vista and 7 machines.
0
 
LVL 38

Expert Comment

by:BillDL
ID: 35024843
I meant to attach your image I cropped using my batch file, just for you to check out.  The little boy is really cute in his camouflage trousers and "commando" haircut.  It's a good photo, apart from the fact that you hacked off the top of the attractive lady's head ;-)
 5 pixel border cropped out using above batch file
0
 

Author Comment

by:photoman11
ID: 35031749
Thanks for all the help. Actually this is not one of my photos but I need to use it as part of a product line.
0
 
LVL 38

Expert Comment

by:BillDL
ID: 35034259
Thank you photoman11
0
 
LVL 57

Expert Comment

by:Pete Long
ID: 35042227
Nice one Bill :)
0
 
LVL 38

Expert Comment

by:BillDL
ID: 35043200
Cheers Pete.  I'm considering wrinting an article entitled "Get things done with long-winded batch files and free programs when you're broke and can't afford to buy any software." ;-)  Do an internal E-E search for "BillDL IrfanView" and you'll see what I mean. Seems I've posted to 94 questions (mine and others) mentioning IrfanView!
0
 
LVL 57

Expert Comment

by:Pete Long
ID: 35043894
:)
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

The standard (non-Professional) edition of PaperPort (http://www.nuance.com/for-individuals/by-product/paperport/index.htm) from Nuance Communications (http://www.nuance.com/) (previously known as ScanSoft) is limited to five Scanning Profiles, but …
I. Introduction In a previous article (http://www.experts-exchange.com/Web_Development/Document_Imaging/A_6537-PaperPort-Upgrade-How-to-download-and-install-updated-versions-of-PaperPort-11-and-12.html) (now deprecated), I discussed how to upgrad…
The goal of this is to tech the user how to export photos out of Lightroom and the different options they have. Select which photos you want to export : Select where you want to export and with which options : Export :
The goal of the tutorial is to teach the user how to import photos into Adobe Lightroom efficiently and to keep everything organized.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now