And then the idea suddenly struck my mind like a bolt of lightning. Looking back at this situation, I realize that this particular idea was probably the smartest thing that ever came to my head. And it let me not just increase the retouchers’ capacity drastically, up to 500 images in a day, but also made the image alignment a very smooth, automatic and precise process. It saved a lot of time for the retouchers, and even now as I am telling you this, the images are being processed with the use of this particular idea, and by now more than two millions of items have been put online and sold.
You must be curious what the idea was, so here it is. I thought: “Okay, so I need to create a selection to align an image. But why do I need to draw it manually in the end? I already have a proper selection when I isolate the object, why not just reuse it for the alignment process?”.
Before we start talking about how this idea was implemented, we need to clarify how Photoshop can save selections, store and restore them. And by a selection I mean not just the marching ants outline. In fact, any selection contains quite a lot of information: for any given pixel of an image, it should be known if it’s selected and how opaque or transparent the selection is. Photoshop can save and store all this information in the
I’ll save the selection that I’ve made into an alpha channel. To do it, I’ll go to the Select Menu and click on the Save Selection command. The only thing I have to do now
The best way to automate alpha channel handling is to let the isolation action create it, which is logical, and let the saving script or the alignment script remove it. You can only remove channels with a script though, don’t try to put it into an action. Because if the image has no alpha channels and you run the action that tries to remove it, it will give you an error. And if you put it in a script, that is done with a single line
It will remove all the alpha channels no matter what their names are and how many channels there are, and if there are none, it will be okay, too, no error.
It's possible to use an action with a conditional, though. Photoshop can run different actions depending on some given conditions, so you can use this feature to avoid scripting, but that would be a rather clumsy solution. But let's get back to the alpha channel based alignment.
When I isolate images using the isolating action, the same selection of the background, that gets filled with white, goes into an alpha channel and stays there. Let’s see how it can be handled by a script, but before that I want you to pay attention to the following fact: to be valid, the selection must come across the border between the object and its shadow. And I have to keep this in mind in the process of isolation, but it’s relatively easy. Now every time I am to isolate an object, I’ll just make a selection with the Marquee Tool in such a way that it will separate the object from its shadow, and then I’ll use the Magic Wand and click on the leftover background. When it’s done and I run the isolating a
The next part is more complicated. We have to modify the script so it can deal with alpha channels. The first thing it has to do is check if there’s an active selection in the document. I want the selection to have a priority over the alpha channel. Why? Because the alpha channel matches the outline of the object, and sometimes I need to be a bit more specific to align an image than just that. Remember the bow tie? Sometimes alignment is not supposed to stick the whole object into the margins, so to be able to control that, we need selections to have a higher priority compared to alpha channels.
In any given situation, there are three possible outcomes. Outcome #1 is when there is an active selection, #2 is when there is no active selection but an alpha channel is present, and #3 is when there is neither a selection nor an alpha channel. If outcome #3 occurs, it means something went wrong and alignment cannot be done, and in this case, the script needs to alert the user. But if there is an alpha channel, the script will load it and turn into a selection. And when it has a selection, no matter if it was there or was loaded from the alpha channel, the script will run the alignment process and we’ll have our image aligned.
With the alpha channel based alignment method, the whole process is very simple and easy. First, we isolate the image, and when we select the background we make sure that the selection comes across the border between the object and its shadow. Then we use the History Brush to bring the shadow back. Then we just run the script and get the image aligned.
What can go wrong? In fact, many things. You can't imagine how many times I've heard from retouchers that my scripts and actions didn't work despite the fact that millions of images were successfully processed with their help. Most of the time the problem is on the user's side, so it's a good idea to tell you when exactly the alpha-channel based aligning method will not work and why.
First of all, as I mentioned before, the selection might not be perfect. If it doesn’t include all the background, and some parts of it such as dirt are left behind, it will affect the alignment process. So you have to be careful about that. If something goes wrong, you’ll have to clean the background. But even if you clean the background, all the dirt will still be present in the alpha channel. We need the script to deal with that, and it does exactly that: after loading the background selection, it grows it with Tolerance 1 to include all the areas that are now white on the Background but not selected in the alpha channel. This is easy and can be achieved by adding a line of code after the selection is loaded from the channel:
Now, what’s growing a selection? Growing is expanding the selection with the tolerance specified. So if you have some trash on the background after running the isolating action, and it causes misalignment, all you have to do is undo the alignment, erase the trash and run the alignment action again. It will correct the alpha channel automatically, and no misalignment will occur this time.
If a script fails to align the object, it doesn't mean that the script is faulty. It's just that the alpha channel is incorrect. And one of the reasons why it can be incorrect is that the background selection failed to include some trash or dirt. Undo the alignment, remove the dirt and you're good to go.
But that's not the only reason. Another one is this: an alpha channel is supposed to represent an outline of an object. What if I retouch it in such a way that the outline is changed? What if I Liquify or Transform it and the new object outline no longer resembles the old one, which is stored in the alpha channel? Well, too bad. If that happens, the script will attempt to align the image and it will fail. So how can we prevent that from happening? If the object didn't move but just became a bit smaller, this is not a problem at all. The same code sequence that grows the selection will resolve this issue. But if the object became bigger or moved, it won't work at all.
What you have to do is control your own workflow. Liquify and transform first, isolate after that. Don’t do anything that can alter the image outline after you’ve isolated the image.
With the use of scripts and actions, you can easily isolate and align all kinds of