Showing posts with label Photo Editing. Show all posts
Showing posts with label Photo Editing. Show all posts

Sunday, May 1, 2011

Seeing The Difference With JPEG Compression



JPEG Compression and Image Quality: Two document windows open in Photoshop, each displaying a copy of the same photo.

But are they really the same image? Appearances can be deceiving, especially on a computer screen. The truth is, they're not the same. The one on the right is the original, uncompressed photo, as if it was downloaded directly from a digital camera. The one on the left is a copy of the photo saved in Photoshop at 60% image quality, which is a fairly typical setting. This means that the image on the left has been compressed.

I realize it's a little difficult to tell in the screenshot above, but if you were to look at both of these images on my screen in Photoshop, you'd have trouble telling which one is compressed and which one isn't. If we were to print them, the differences would become clear, but on a computer screen, which has a much lower resolution than a printed image would have, the differences are not so easy to spot. At least, not without using Photoshop's Difference blend mode to help us out.

I said a moment ago that the Difference blend mode looks for differences between two layers, and that any areas between the two layers that are exactly the same appear as pure black. Let's put this to the test. I'm going to select my original, uncompressed photo, and I'm going to duplicate its Background layer in the Layers palette by pressing Ctrl+J (Win) / Command+J (Mac). I now have two layers in the Layers palette - the original Background layer on the bottom and a copy of the Background layer, which Photoshop has named "Layer 1", above it:

Adobe Photoshop tutorial image.
JPEG Compression and Image Quality: The Layers palette for the original, uncompressed photo showing the Background layer and the copy of the Background layer above it.

Since "Layer 1" is a copy of the Background layer, both layers should be identical. We can use the Difference blend mode to prove that they are. I'm going to go up to the blend mode option at the top of the Layers palette and change the blend mode for "Layer 1" from "Normal" to Difference:

Adobe Photoshop tutorial image.
JPEG Compression and Image Quality: Changing the blend mode of "Layer 1" to "Difference".

With "Layer 1" set to the Difference blend mode, if I look at the image in the document window, I see that the entire image is now filled with solid black, which is the Difference blend mode's way of telling me that both layers are in fact identical:

Adobe Photoshop tutorial image.
JPEG Compression and Image Quality: The image is now completely filled with solid black, indicating that both "Layer 1" and the Background layer are identical in every way.

Let's take things even further to be absolutely certain that all we're seeing now in the image is nothing but pure black. To do that, we'll use a Levels adjustment layer. I'm going to click on the New Adjustment Layer icon at the bottom of the Layers palette:

Adobe Photoshop tutorial image.
JPEG Compression and Image Quality: Clicking the "New Adjustment Layer" icon at the bottom of the Layers palette in Photoshop.

Then I'll choose Levels from the list of adjustment layers that appears:

Adobe Photoshop tutorial image.
JPEG Compression and Image Quality: Clicking the "New Adjustment Layer" icon at the bottom of the Layers palette in Photoshop.

This brings up the Levels dialog box. I can use the Histogram in the center of the dialog box to see exactly what tonal information is being displayed in my image. If every single pixel in the image is displaying pure black, which should be the case if both of my layers are identical, then all I should see in my Histogram is a single vertical bar on the far left, which just happens to be exactly what I'm seeing:

Adobe Photoshop tutorial image.
JPEG Compression and Image Quality: The Histogram in the center of the Levels dialog box is displaying a single vertical bar on the far left, telling me that every pixel in my image is pure black.

The Histogram confirms that there are currently no other colors being displayed in my image except pure black, which means that "Layer 1" and the Background layer are 100% identical. So far, so good. We've now proven what most of us already knew, that when we make a copy of a layer, the copy is identical in every way to the original. Exciting stuff, right? Let's move on.

I'm going to click the Cancel button in the top right corner of the Levels dialog box to exit out of it for now, and I'm going to delete "Layer 1" from my Layers palette by clicking on it and dragging it down on to the trash bin icon:

Adobe Photoshop tutorial image.
JPEG Compression and Image Quality: Dragging "Layer 1" down on to the trash bin icon at the bottom of the Layers palette to delete it.

I'm now left with just my original Background layer once again:

Adobe Photoshop tutorial image.
JPEG Compression and Image Quality: The Layers palette showing the original Background layer.

Now let's see what happens when we use the exact same method to compare the uncompressed version of the photo with the compressed version of it. As I mentioned, it's not easy to see any differences between them simply by looking at them on the computer screen, but let's find out what the Difference blend mode has to say about it. With each version of my photo open in its own document window, I'm going to click inside the compressed version's document window (the one on the left) with my Move Tool and drag the image into the uncompressed version's document window (the one on the right):

Adobe Photoshop tutorial image.
JPEG Compression and Image Quality: Using the Move Tool and dragging the compressed version of the image on the left into the uncompressed version's document window on the right.

Since both images have exactly the same pixel dimensions (width and height), I'm going to hold down my Shift key and then release my mouse button, which will align the two images perfectly inside the document window:

Adobe Photoshop tutorial image.
JPEG Compression and Image Quality: Both images are now aligned perfectly one above the other in the same document window.

If I look in my Layers palette, I can see that I now have two layers once again. The uncompressed version of the image is on the Background layer, and the version that was saved at 60% image quality is now above it on "Layer 1":

Adobe Photoshop tutorial image.
JPEG Compression and Image Quality: The Layers palette showing the uncompressed version on the Background layer and the compressed version on "Layer 1".

I'm going to once again change the blend mode of "Layer 1" from "Normal" to "Difference":

Adobe Photoshop tutorial image.
JPEG Compression and Image Quality: Changing the blend mode of "Layer 1" to "Difference".

And now, with the blend mode of "Layer 1" set to "Difference", if there truly is no difference between the compressed and uncompressed versions of the photo, I should be seeing nothing but pure black when I look at my image in the document window:

Adobe Photoshop tutorial image.
JPEG Compression and Image Quality: The document window after changing the blend mode of "Layer 1" (the compressed version of the photo) to "Difference".

Hmm. Can you see all that faint noise in the image above? It will depend on how you have your monitor set up. You may just be seeing black, but I can see on my screen that it's definitely not pure black like it was before when we were comparing the Background layer with an identical copy of it. There's something else there, and that "something else" is telling us that the compressed and uncompressed versions of the photo are not the same. But just how different are they? Does jpeg compression really make that much of a difference?

Let's use a Levels adjustment layer once again and let the Histogram answer that question for us. I'll click on the New Adjustment Layer icon at the bottom of the Layers palette and choose Levels from the list:

Adobe Photoshop tutorial image.
JPEG Compression and Image Quality: Selecting a "Levels" adjustment layer in the Layers palette.

This again opens the Levels dialog box. Recall from last time that the Histogram displayed a single vertical bar on the far left, which told us that there was absolutely nothing else in our image except pure black. This time, we're seeing something a bit different:

Adobe Photoshop tutorial image.
JPEG Compression and Image Quality: The Histogram is no longer just a single vertical bar.

There seems to be a lot more going on this time on the far left of the Histogram, which confirms that my eyes weren't playing tricks on me. There's definitely something else there in the image. The single vertical bar has been replaced by a larger area of black, which means the image itself now contains more than just pure black, and that means there's areas in the two versions of the photo that are no longer identical.

So what's different about them? Simple - garbage. By compressing one version of the image, we've taken the pure, untouched image information and added a whole lot of garbage to it. Noise, junk, call it what you like. The bottom line is, we've damaged the photo. How much garbage did the jpeg compression add? It may not look like much just yet, and it's still hard to see in the image itself, so I'm going to click on the small, white slider on the bottom right of the Histogram and drag it all the way over to the left until it's under the spot where the black slope begins:

Adobe Photoshop tutorial image.
JPEG Compression and Image Quality: Dragging the white slider from the bottom right of the Histogram over to the left to the point where the black slope begins.

Without getting into a lengthy discussion of how the Levels dialog box works, what I've just done is taken all that faint noise in the image and made it much brighter so we can see it more easily. Remember, any strange colors you see represent areas that are different between the original, uncompressed version of the photo and the version that was saved with jpeg compression:

Adobe Photoshop tutorial image.
JPEG Compression and Image Quality: The noise is now much more visible in the image.

Not a pretty sight, is it? Now that we can see things more easily, all of those weird colors represent all the damage we've done to the image by compressing it. The image is now filled with what are commonly referred to as "compression artifacts", which is just a fancy way of saying "we took your perfectly good image information and messed it all up". Compressing a jpeg image can greatly reduce your file size, but as the Difference blend mode is showing us, it can also greatly reduce image quality. Again, it's not always easy to see how much damage your image has suffered by looking at it on your computer screen, but you'll definitely notice the difference when printing in high resolution.

So now that we've seen how much damage we can do to a digital photo by compressing it, what can we do about it? Unfortunately, not much. The jpeg format is still your best bet for saving digital photos, and when file size is an issue, we really have no choice but to compress them. If you're working on a project for the web, you can usually get away with quite a bit of compression before image quality becomes an issue, but if your project is going to print, you'll want to use the original, uncompressed images whenever possible.

And there we have it!

An Easy Way To Find Neutral Gray In An Image


Step 1: Add A New Layer

With our photo open inside Photoshop, the first thing we need to do is create a new blank layer, so click the New Layer icon at the bottom of the Layers panel to create a new blank layer above the Background layer:

The New Layer icon in the Layers panel in Photoshop. Image © 2010 Photoshop Essentials.com
Click on the New Layer icon.

Nothing will happen in the document window, but we can see in the Layers panel that Photoshop has added a new blank layer named "Layer 1":

A new layer has been added in the Layers panel. Image © 2010 Photoshop Essentials.com
Photoshop adds the new layer and names it "Layer 1".

Step 2: Fill The New Layer With 50% Gray

Next, we need to fill our new layer with 50% gray, the same gray we're looking for in our image. To do that, go up to the Edit menu at the top of the screen and choose Fill:

Selecting the Fill command in Photoshop. Image © 2010 Photoshop Essentials.com
Go to Edit > Fill.

This opens Photoshop's Fill dialog box. Select 50% Gray from the drop-down list at the top of the dialog box:

Setting the Use option to 50% Gray in the Fill dialog box in Photoshop. Image © 2010 Photoshop Essentials.com
Set the Use option to 50% Gray.

Click OK when you're done to close out of the dialog box. Photoshop fills the new layer with gray, temporarily hiding the photo below it from view in the document window:

The Photoshop document is filled with 50% gray. Image © 2010 Photoshop Essentials.com
The new layer is now filled with 50% gray.

Step 3: Change The New Layer's Blend Mode To 'Difference'

Go up to the Blend Mode option in the top left of the Layers panel and change the blend mode for Layer 1 from Normal to Difference:

Selecting the Difference blend mode in the Layers panel in Photoshop. Image © 2010 Photoshop Essentials.com
Change the blend mode for Layer 1 to Difference.

The Difference blend mode isn't one that's used too often since it tends to make images look, well, different (some may even say frightening), as we see with my image after changing the blend mode to Difference:

The photo after changing the blend mode to Difference in Photoshop. Image © 2010 Photoshop Essentials.com
The Difference blend mode certainly makes photos look different.

Believe it or not though, there is a method to the madness. The way the Difference blend mode works is that it compares the layer with the layer(s) below it and looks for differences between them (hence the name). Any areas in the layer which are different from the layer(s) below it show up as strange colors in the image, which is where the purples, blues and yellows are coming from, but any areas which are identical between the layers show up as black, or at least almost black if they're not 100% identical but still pretty darn close to it. In other words, with the Difference blend mode, any areas between the layers which are identical become the darkest parts of the image, and we can now use that to locate any areas that are supposed to be neutral gray!

How? Simple! We're now comparing our image on the Background layer with the layer above it that's filled with 50% neutral gray, which means that any areas in our image which are closest to that midtone gray color will now appear as the darkest parts of our image. So now, finding a midtone gray area is as easy as finding the darkest part of the image!

Step 4: Add A Theshold Adjustment Layer

Click on the New Adjustment Layer icon at the bottom of the Layers panel:

The New Adjustment Layer icon in the Layers panel in Photoshop. Image © 2010 Photoshop Essentials.com
Click on the New Adjustment Layer icon.

Choose Threshold from down near the bottom of the list of adjustment layers:

Selecting a Threshold adjustment layer in Photoshop. Image © 2010 Photoshop Essentials.com
Choose "Threshold".

If you're using Photoshop CS5 as I am, the Threshold controls will appear in the Adjustments Panel, new to CS5. In Photoshop CS4 or earlier, the Threshold dialog box will appear. Click on the little white triangle at the bottom and drag it all the way to the left:

Photoshop Threshold image adjustment. Image © 2010 Photoshop Essentials.com
Drag the white slider all the way to the left.

This will turn the image in the document window completely white:

The image is now completely white in the document window. Image © 2010 Photoshop Essentials.com
The document window now appears filled with white.

Now slowly drag the triangle towards the right until you begin to see black areas appearing in your image. The first black areas that appear are the neutral gray areas you're looking for (assuming, as I mentioned at the beginning of the tutorial, that there actually are areas of gray in the photo). Continue dragging the triangle until an area of black becomes just big enough that you'll be able to click on it to select it, which we'll be doing in a moment. This is the exact same way you would normally find the darkest parts of the image when you're removing any color casts from the shadow areas, but now, thanks to the Difference blend mode, these darkest areas represent the areas closest to midtone gray. Click OK when you're done to exit out of the Threshold dialog box (Photoshop CS5 users can simply leave the Adjustments Panel open):

The small black area represents the midtone grays in the image. Image © 2010 Photoshop Essentials.com
Drag the white slider towards the right until a small area of black appears.

Step 5: Click On The Black Area With The Color Sampler Tool

Select Photoshop's Color Sampler Tool from the Tools panel. By default, it's nested behind the Eyedropper Tool, so click and hold on the Eyedropper Tool for a second or two until a fly-out menu appears, then select the Color Sampler Tool from the list:

The Color Sampler Tool in Photoshop. Image © 2010 Photoshop Essentials.com
Select the Color Sampler Tool.

With the Color Sampler Tool selected, click on an area of black in the image to add a marker. Zoom in on the area first if it makes it easier to select your black area, as I've done here:

Clicking on an area of black with the Color Sampler Tool. Image © 2010 Photoshop Essentials.com
A small target symbol will appear at the spot you click on with the Color Sampler Tool.

Step 6: Delete The 50% Gray and Theshold Layers

Our layer filled with 50% gray and our Theshold adjustment layer have served their purpose and are no longer needed, so with the Threshold adjustment layer currently selected in the Layers panel, hold down your Shift key and click on Layer 1 below it to select both layers at once. Then drag them down on to the Trash Bin icon at the bottom of the Layers panel to delete them:

Dragging the top two layers onto the Trash Bin in the Layers panel. Image © 2010 Photoshop Essentials.com
Drag the top two layers onto the Trash Bin.

Step 7: Add A Levels Or Curves Adjustment Layer

Click once again on the New Adjustment Layer icon at the bottom of the Layers panel and this time, select either Levels or Curves, you're choice. Either one will do. I'll use Levels:

Selecting a Levels adjustment layer in Photoshop. Image © 2010 Photoshop Essentials.com
Choose either Levels or Curves from the list of adjustment layers.

Step 8: Select The 'Set Gray Point' Eyedropper

As with the Threshold adjustment layer, Photoshop CS5 users will find the controls for Levels or Curves in the Adjustments Panel, while CS4 and earlier users will see the Levels or Curves dialog box appear. Click on the Set Gray Point eyedropper to select it (it's the middle of the three eyedropper icons):

The Set Gray Point eyedropper in the Levels dialog box in Photoshop. Image © 2010 Photoshop Essentials.com
The Set Gray Point eyedropper is the middle of the three.

Step 9: Click With The Eyedropper On The Marker In The Image

With the Set Gray Point eyedropper selected, simply click directly on the small marker in the image (the one we added a moment ago with the Color Sampler Tool) and Photoshop will neutralize the colors in that spot, effectively removing any color cast from the midtones.

Personally, I don't find the eyedropper icon to be very helpful when trying to click on a marker, so you may want to press the Caps Lock key on your keyboard which will change the icon from an eyedropper to a target symbol, identical to the marker's icon, making it easy to line them up over top of each other and then click. I'll leave mine set to the eyedropper icon here just to make it easier to see in the screenshot:

Clicking on the gray point marker in the image. Image © 2010 Photoshop Essentials.com
Click directly on the marker to neutralize the midtones in the image.

And with that one click, any color cast in the image's midtones has been neutralized:

The color cast in the midtones has been removed. Image © 2010 Photoshop Essentials.com
Any midtone color cast has been removed.

Step 10: Remove The Marker

To remove the color sampler marker from the image when you're done, with the Color Sampler Tool selected, simply click on the Clear button in the Options Bar at the top of the screen (don't worry if you forget to remove the marker since it won't print anyway):

The Clear button for the Color Sampler Tool in Photoshop. Image © 2010 Photoshop Essentials.com
Click the Clear button to remove the color sampler marker.