Saturday, October 28, 2006

Stitching In Photoshop


This is a three image Photoshop stitch from my 90 ts-e using the shift facility of the lens to create a left, centre and right shift image. Alignment isn't perfect since you have to loosen the tripod's grip on the camera and slide it along and reclamp but usually the variation is small enough that it's not difficult to blend the images.

Below is a description of how to use Photoshop to stitch images. While Photoshop has a stitching utility in 'automate' in the file menu, it seldom produces perfectly invisible seams and I never use it. Instead, I do it manually. In theory I could use the following technique with ordinary lenses and when the camera has been rotated between images, but as PTMac will take care of perspective and pin cushion and barrel distortion and morph the images for the best possible stitch, I reserve Photoshop for lens shift stitching.

In taking the images, I move the camera the opposite direction to the lens shift so that as close as possible the lens stays stationary and the 'film' slides over.

My technique is to first select all three images in Bridge, then command-O (control-O on a PC) to open the three into Camera Raw. There I select all and then synchronize. Note that while synchronize all should in theory make the images match perfectly in colour, contrast, etc. , in fact, if you leave the colour balance as 'as shot', then if you used auto white balance in camera, each image will have it's own white balance despite your efforts to set everything the same. It's simple to move the colour temperature slider slightly, even if you then move it back to the original position - now it's 'custom' in stead of 'as shot' and all three images will have the same colour temperature.

You may yet have differences amongst the images. You will of course have used manual exposure and manual focus so those don't explain differences, but what about differences in lighting - even the thinnest cloud will change the image brightness and even colour. Don't forget too that if you are doing a stitch in which you rotate the camera between images (ie. you aren't using a shift lens) polararizers will prevent a good match as you swing the camera to a different position relative to the sun thus affecting the amount of polarizing.

Getting back to the process however, I make the changes in Camera Raw (or whatever raw processor you are using) and open the images in Photoshop (had I been rotating the lens, I wouldn't even consider using Photoshop to do the stitch, I'd save the images as TIFF's and then bring them into a dedicated stitching programme.. Anyway, this time we are using the shift capabilities of my lens and so into Photoshop they go.

I find the rightmost image and use that as my base. I use 'Canvas Size' in the Image menu to double the size of the image. Most often I'm stitching horizontally in which case I will locate the anchor in the third column, middle row, set the units to percent and select 100 as the amount. This will double the canvas size, growing to the left.

I then find the centre image, use command-A (control-A for PC) to select all, command-C (ditto) to copy the image and once it is copied, I get rid of the image and paste by command-V after reselecting the rightmost image.

The middle image is added as a layer to the newly grown right image. I do the same with the left image, automatically placing into a third layer when I do command-V.

Use the move tool (top row, second column) to move the overlying images around. What I do is turn off the left most image so I only have two to work with. I click into the second image and just under the layers sign where it says 'normal' I select 'difference' instead. This first of turns the middle image into a negative, but more importantly, when the second image is aligned exactly over the right image, the two cancel each other out and the overlapping section becomes black. Since alignment is never perfect, I simply aim for the blackest possible alignment, while the image is magnified to about 50% size. I look for the best alignment in the middle of the join both vertically and horizontally. I do initial movement with the mouse and final alignment with the keyboard arrows. Lastly I convert the layer back to normal.

Once aligned, I add a white mask to the middle image layer, select the brush, set the brush hardness to 80, opacity to 100%, shrink the image so it all fits on screen, select black as the painting 'colour' and paint the right part of the mask so that the image underneath shows through. In practice it shows through anyway because of the way Photoshop pastes smaller canvases into larger ones but what I'm looking to do is find the edge between the two images. In painting all of the right side of the mask, as I go towards the left eventually some of the middle image will disappear (because I'd painted black into it's mask. This tells me where the edge of the rightmost image is. Having painted all of the right part of the mask and showing a thin line of the middle image out, I magnify the image on screen to 50% again, shrink my paint brush and carefully create the seam between the two images. I go round lines where I can and find places where lines blend best if I can't. The end result is a careful blend of the two images which won't show, no matter how big a print I make.

To do the same with the top image, I first turn it back on (which doesn't select it), then select it, set it to difference, move it, create the white mask and paint to blend it and now I have all three images aligned and careful seams created. At this point I have to be sure that the three images really do match in colour, brightness and contrast. Sometimes an image is soft enough it isn't obvious there is a difference. I can increase contrast with a temporary curve layer and increase saturation with a temporary hue/saturation layer.

If these steps show any miss-match, then I go to the Layers menu and select 'adjustment layer' and levels or colour balance as needed. When you do so a window appears with the name of the adjustment layer and just underneath a check box which ties the effect of this layer specifically to the layer below. In selecting this box, you make any changes in colour or contrast apply only to the layer below (based on it's mask). I then use the white, black and middle adjustments in the levels settings to match brightness throughout the seam, and adjust colours with the colour balance adjustment layer. I should now have the seam completely invisible, even with the temporary contrast and saturations layers. I can now throw those away(or just turn them off).

If I am confident I did a good job with stitching, I flatten the image. If I have any doubts, I save the image first. I found it handy to use a function key to flatten the image as I use this a lot.

And that's how I stitch images in Photoshop. The process to combine images that have been stitched with PTMac is a little different in that the canvas is already large and the surround of each modified image is black. I still use white masks and black paint to create the seams but I don't have to move the images around since they already have the optimum alignment (as created by the stitching programme). I could have PTMac do this for me but there are times when even a 3 pixel error in stitching would show so I prefer to manually select my seams.

1 comment:

George Barr said...

Roger:

downloaded the trial version and managed to stitch near perfectly some very difficult prev. stitches - I was impressed enough to pay for PTGui and will do some more work with it and if it continues to impress, write about it. Thanks!