Would like to automate and capture only the map part and save it to a different file i.e. any thing outside the rectangle is removed.
I tried exploring Photoshop’s magic wand and refine edge tools but not sure if I am missing anything in my approach. Looks like Crop or Trim may not work to automate since dimensions vary for each image.
Note: The rectangle border is not exact for every image i.e. the border width on each side may vary and also the dimensions of rectangle may vary. I have 1000+ maps and automate will speed up the tasks.
Thanks in advance for any inputs, recommendation![enter image description here][1]s etc.
2
Answers
Updated Answer
Ok, I have done some work on this and can extract the map automatically using the script below which does more or less as I suggested below:
You would save the script above in a file called
extractMap
, then run the following (just once) to make it executableNow you can pass it the name of a survey like this and it will extract the map into a subdirectory called
extracted
followed by the original filename:The main steps are:
If you have a whole directory full of images, please back them up first then you can process the whole directory of thousands of files like this:
Orignal Answer
I am away without access to my computer for the weekend, so I can only suggest in general terms how to do it… will check back Sunday evening to see if anyone has developed the idea.
I would use ImageMagick which is available for Windows, Linux and OSX via commandline or with Perl, PHP, .NET and other bindings.
Then squeeze the image to a tall, 1 pixel wide image, using this command
Now look at the image, and you will see a short solid line corresponding to the image title block at top left, then another short line corresponding to the longitudes and then a LONG solid line corresponding to the sides of the map. This is readily identifiable and gives you the top and bottom of the map.
Now squidge the image to 1 pixel high with this
and do it again to find the width of the map.
Then extract the map with
where X=map width, Y=map height, M=x offset to top left corner of map, N=y offset to top left corner of map.
You can change the output image name to
txt:-
and it will list the pixel colours as text so you can parse them easily.Thinking a little more, it would be better to crop the top and bottom of the image off after finding the longest vertical line and BEFORE squidging the image down to 1 pixel high – this would mean the header at the top and key at the bottom would not interfere with determining the width of the map.
It looks like you’re only going to be able to partially automate this process. Here is what I would do:
1) Save all your images/maps into a folder.
2) Open the first image/map in Photoshop.
3) Use the “Rectangular Marquee Tool” to draw a selection of the part of the map you want to keep.
4) Now go to the Actions panel and click the “Create new action” icon at the bottom of the panel.
5) Give the action a name and set a “Function Key” – something like F5 will work nicely. Then hit “Record”
6) Select the “Image” menu from the top of the screen and select “Crop”.
7) Select “File”, “Save for web”, choose your format (JPG, GIF, PNG) and quality settings, hit “Save” and save it into a separate folder (different from your source images)
8) Close your original map (you can select Yes or No to save your changes depending on your needs)
9) In the Actions panel, hit “Stop” to stop recording.
10) Now you can open a bunch of your maps (maybe 20-30) make your rectangular marquee selection and hit your action shortcut key (F5 in this example).
This method will take some time, but will mostly automate the process and will go very quickly.