0

I have almost 700 small images of glyphs which are anti-aliased black on white backgrounds. All the files have excess whitespace and I wanted to use the trim function in Photoshop to batch resize all the images using an action. However, it turns out there are some non-perfectly white pixels throughout all the files causing very inconsistent trimming. By using the paintbucket tool with a tolerance of 1 I am able to manually fix the backgrounds but I don't want to do that 700 times. Is there a way to clean up these backgrounds using an action in batch processing?

  • 3
    Couldnt you use levels to blew the whites out to then trim? – joojaa Apr 30 at 19:37
  • Yes, that is solving a lot of them. – Pablo Vadear May 2 at 21:58
0

Create an action with the following steps.

  1. Levels: Boost the white point enough to handle most, if not all, of the images.
  2. Select Pixels: From the Channels panel, Ctrl+click to select the active pixels in the black channel. Or, if in RBG, select the active pixels in R, then Shift+select the active pixels in G as well as B.
  3. Selection: Invert the selection so that the marquee is around the black. (Invert the marquee SELECTION, not the actual pixels)
  4. Selection: Expand the selection by a few pixels to create a safe zone. This helps round shapes to not have flattened sides at the boundary.
  5. Crop: Crop to the expanded selection. This will ensure that the glyph is centered with an even white space around the glyph.
  • This seems to get me a lot of the way there but the last step isn't behaving the way I expect. It doesn't seem to crop all the way down to the selection. Here is an example. For some reason it's not cropping off the white space on the right. I don't see how to embed this. i.imgur.com/U3ZsM5U.jpg – Pablo Vadear May 2 at 21:46
  • The crop step isn't going to work unless all of the "white" area is completely white. Be sure to adjust the levels so that there are no pixels with gray or color in the white area. A good way to do this would be to find a darker example from among your source images. – 13ruce May 3 at 11:49
  • Alternatively, you could add a pair of steps just before the Crop step as follows: 4.1 Selection: Contract the selection by 10 pixels. 4.2 Selection: Expand the selection by 10 pixels. This will have the effect of deselecting any areas that are 10 pixels or smaller, leaving only larger selection, then the expansion will set the marquee back to the full size (hopefully without the scattered darker pixels.) It shouldn't matter if the end marquee doesn't conform exactly to the shape you are cropping, because the crop function only looks at top, bottom, and side extremes of the selection. – 13ruce May 3 at 11:56
  • Well, I never could get this to work properly. In the example I used I had already changed the white level to 220 which was working with a trim. What worked in the end was changing to gray scale, adjusting white level, and then just trimming. I followed that with a canvas bump to get a margin. That worked for all images. – Pablo Vadear May 6 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.