AdSense Mobile Ad

Showing posts with label filter. Show all posts
Showing posts with label filter. Show all posts

Sunday, August 12, 2012

Adobe Photoshop Lightroom Tutorial - Part XXIV - Organising Your Photo Catalog Using Metadata and Keywords

Part I - Index and Introduction

Metadata, in one of its simplest form, is defined as "data about data". In the case of photography, for example, you may think about EXIF data attached to your image: they provide technical information (camera settings, geolocation information etc.) about the picture. Depending on the tool you use, you can go beyond what's provided by standards (such as EXIF or IPTC) and provide your own metadata.

What's the point of using metadata? The basic idea is organizing your images and thus being able to make searches based on some criteria. For example, you may want to search for images shot with a specific camera, or with a specific lens; or you may looking for pictures taken at a certain shutter speed, aperture or geospatial coordinates. Or you may be willing to search for pictures using non-technical criteria, such as a portrait shot at a wedding and processed in black and white. Can you imagine what your Internet experience would be if search engines didn't exist? You couldn't find a way to the information you're looking for, and the very concept of "Internet" as you know it would be defied. The same thing happens with your photo catalogs. How could you possibly find something if you couldn't search using the criteria you need? Amateur photographers with small catalogs may be able to find the pictures they're looking for manually scanning the catalog, or trying to remember which folder or collection a picture is in. But as soon as your catalogs grow larger and larger things get worse and the problem starts to be insurmountable. That's why some products exist which provide the tools you need to overcome this problem. In fact, there's a dedicated category of such products: image management databases and Adobe Photoshop Lightroom is one of them.

If you're using Lightroom, you already know your images are stored into a catalog which acts as a "proxy" between you and the images managed by Lightroom. The catalog is basically a database which stores additional information (metadata) alongside your images. Such metadata makes the database searchable, so that you can look for images using search criteria. Lightroom, in this respect, is extremely helpful and powerful in that:
  • It comes with out-of-the-box support for an extensive set of well known or frequently used metadata (such as ratings, EXIF and IPTC).
  • It lets you extend the metadata model using your own keywords.
  • It lets you easily build search criteria mixing and matching any type of searchable field.
  • It lets you define smart collections, that is collections of pictures whose content are defined by a search filter and are automatically updated.

These are just the most important features provided by Lightroom, and we'll discover more of them in the following sections.

Flags, Ratings and Labels

The simplest forms of metadata you can catalog your images with are flags, ratings and labels:
  • Flags are used to pick or reject an image.
  • Ratings are used to rate images on a scale from 0 stars to 5.
  • Label is a one of 5 color codes (Red, Yellow, Green, Blue and Purple) that can be assigned to an image.

While the meaning of flags and ratings is pretty well defined, the meaning of labels can be customized by the user. By default, labels are just "colours" but their name, and thus their meaning, can be customized to be meaningful for the user. Lightroom, for example, provides an additional naming scheme for labels, inherited by Adobe Bridge, that uses the following convention:
  • Red: Select
  • Yellow: Second
  • Green: Approved
  • Blue: Review
  • Purple: To Do

You're free, however, to assign your own meanings to colour labels. In my workflow, for example, I just use the common three traffic light colours (red, yellow and green) to transition images from the undeveloped, partially developed and done states.

In the following picture, you can see a screenshot of some pictures in my catalog. Three of them (the first, the second and the third) are flagged because I picked them, rated (with 4, 3 and 4 stars respectively) and labelled green (because I finished processing them). The second image is unflagged (it's neither rejected nor picked), unrated (0 stars) and partially developed (yellow label).

Flags, ratings and labels

The basic rating and labeling metadata are flexible and easy to use and can be largely adjusted to any development workflow. In my workflow, for example, flags are used before starting developing images in order to pick only the pictures eligible for development. Images to be deleted, are marked as rejected and deleted pretty soon. Images I'm not sure about are left unflagged even if, eventually, they'll either be picked or rejected (and thus deleted). Ratings are usually applied at the end of the development process and are usually immutable while colour labels are just a quick visual aid to quickly identify pictures I should be working on. Eventually, when I finish developing a folder (or collection) all pictures will be labeled green.

Metadata

Images can be assigned metadata of many kinds. Lightroom support many kinds of metadata including:
  • EXIF
  • IPTC
  • DNG
  • Location
  • Metadata defined in a custom plugin
Lightroom can also read proprietary metadata (such as proprietary EXIF extensions) found on an image, but in this case it usually gives no way to modify it. In fact, Lightroom won't even read all proprietary metadata: if you're interested in reading a field not visible in Lightroom, you should look at the excellent ExifTool by Phil Harvey (a command line tool I will probably write a post about in the future).

Metadata can be inspected and modified using the Metadata panel in the Library module:

Metadata Panel

As you can see in the previous image, the Metadata panel shows information about the chosen type of metadata (in this case EXIF and IPTC) and lets you modify the writeable fields. At the topmost part of the panel, Lightroom provides some commonly used fields (Rating, Label, Title, Caption, etc.) as a convenience to speed up metadata editing.

To change the currently displayed metadata category, you just need to select the desired one in the list box in the upper left corner of the panel. In my Lightroom setup, these are the available choices:

Metadata Categories

If you're a developer, you could also extend available metadata writing a custom Lightroom plugin using the Lightroom SDK. Most users (even professional ones), however, will be just satisfied with what Lightroom offers out of the box.

Location Metadata

Location metadata is the perfect way to geographically localize where a shot was taken. Nowadays, many cameras populate these fields using data gathered by a GPS device, such as modern smartphones or GPS-equipped cameras. Many DSLR, however, still lack this functionality and their pictures require the user to manually introduce location metadata.

Up to Lightroom 3, location metadata were just made up of text fields, but with the latest Lightroom release (v. 4 at time of writing) you can use the Map module to populate these fields by dragging and dropping images over a map:

Map Module

Once an image is dropped over the map, Lightroom will automatically update its location metadata, as you can see in the following picture:

Location Metadata of a Photo

The Map module also provides the possibility of saving a location, a functionality that can greatly speed up your workflow. To save or load a location, just use the controls found in the Saved Locations panel of the Map module.

Since location metadata may contain sensitive information you're willing to protect, you may want to ensure that information about some locations are never exported. That might be the case of information about your home location, for example. To have Lightroom protect a location, you can add it to the list of saved locations and mark it as private:

New Private Location

In the New Location dialog box, you can specify a radius which will determine the area of the (circular) location you're saving and a checkbox that can be used to mark it as private. If an image is tagged into a private location, the corresponding metadata will never be exported, no matter which export mechanism or publish service is used.

Applying Metadata Changes to Multiple Images

Very often you find yourself applying the same metadata to multiple images. For example, it may often be the case for metadata in the location, copyright, contact and workflow categories. Lightroom offers two ways to perform "bulk" metadata changes:
  • Metadata synchronization.
  • Metadata presets.

Metadata synchronization is very similar to develop settings synchronization: you apply the modification you need to a picture and then sync other pictures with it. To sync metadata with a reference image, just select all the images to be synced paying attention that the reference image be the first image in the selection set. Once the images are select, press the Sync Metadata button in the bottom left corner of the right module panel:

Sync Buttons

Ligthroom will present a form in which fields to be synced can be chosen and copied to the metadata set of the other images.

Metadata presets are a very similar concept, with the difference that metadata values are saved in a preset (instead of copied from a reference image) and applied to a set of images. To create a preset, select the Edit Metadata Preset item in the Metadata menu or in the Preset listbox in the topmost section of the Metadata panel. A form will be presented in which fields to be saved in the preset can be chosen. A saved preset can be applied to one or multiple images simply selecting the corresponding preset in the Preset listbox.

Metadata presets are handy when a set of metadata values is frequently applied to many photos. To speed up my workflow, for example, I created a preset for each of the fixed sets of metadata I commonly use, such as contact information, copyright information and common locations where I use to shoot. Metadata synchronization, on the other hand, is more suitable when many images share a common set of characteristics (same job, same event, same model, etc.) whose value, however, aren't worth creating a preset which will most likely be scarcely reusable.

Keywords

Lightroom lets you apply keywords to an image. Keywords, or tags (an alternate name used in other contexts such as Flickr or Google+), are just text labels that can be searched for: hence, they provide a mean for an user to freely organize the catalog using user defined "keys". In this sense, keywords are the building blocks you use to organize your catalog "your own way". Metadata described so far, in fact, was related to some technical aspects of a picture or some standard attribute set (camera settings, location, etc.). Keywords, on the other hand, are "the words you use to describe a picture" and, hence, to keep your catalog organized using words meaningful to you.

You may want to define, for example, keywords for each style of photography you produce (portraits, landscape, etc.), for treatments you apply (duotone, sepia, black & white, cropped, etc.), names of persons appearing in a photo, etc.

Adding and Removing Keywords

To assign keywords to a picture, just use the Keywording or Keyword List panels of the Library module. The Keywording panel, shown in the following picture, is made up several distinct controls:
  • The Keyword Tags list box, used to change what's shown in the keywords box.
  • The keyword box, where you can see a list of keywords applied to your image whose content depend on the current Keyword Tags selection.
  • A text box that lets you add keywords.
  • Two grids, Keywords Suggestions and Keyword Set, which provide a visual shortcut to two set of keywords.

Keywording Panel

By default, the keyword box shows the keywords currently assigned to the selected picture(s). In case of a multiple selection, a keyword that's only assigned to a subset of images is postfixed by an asterisk (*). To add a keyword, you just need to type it in the keyword text box and press Enter: the keyword will be added to the currently selected image(s) and created (with the default options) if it's the first time you use it. If you want to tweak the behaviour of a keyword, as described in the following section, you maybe want to create it manually before entering it or manually changing its options later. I usually prefer creating them manually in order not to forget changing their options afterwards.

To speed up your workflow, Lightroom lets you quickly select keywords from two 3x3 grids: Keywords Suggestions and Keyword Set. The former contains suggestions based on last used keywords, based on the keywords currently applied to an image; you'll see that adding or removing keywords to the current image triggers a suggestions change as well. The latter, on the other hand, is made up of a static list of keywords you can create, save and use. Using the listbox on the right side of the keyword set grid (showing Outdoor Photography in the previous image) you can select, create, edit and remove your own keyword sets. Lightroom ships with some example sets but you should create your own, reflecting your "keywording habits" for each kind of photography you're interested to.

To remove a keyword, just deselect it from one of the suggestion grids or manually delete it from the keyword list.

Keyword List

The Keyword List panel shows a graphical representation of the current keyword tree. In fact, keywords aren't just a flat set of tags: Lightroom let you organize keywords into a hierarchy, as shown in the following picture:

Keyword List

The quickest way to build is a hierarchy out of already existing keywords is just rearranging them with your mouse. If you drag a keyword over another, the former will convert into a child of the latter.

But what's the point of building and maintaining a hierarchy? It's not only constraining the size of a keyword list that could potentially grow to a considerable size. The keyword hierarchy allows you to organize concepts in a tree establishing an "is a" relationship with the containing keywords. In the picture above, for example, the keyword cat is the leaf of the subtree animal/mammal/cat. That is: in the hierarchy I'm using the cat is a mammal and is an animal. This way, you don't have to tag an image three times (cat, mammal and animal) but just one: cat.

You can tweak how keywords behave in the hierarchy. In the example above, we wanted cat to be a mammal an an animal. There may be cases where you just use the hierarchy for organizational purpose and don't want a picture to automatically acquire all the containing keywords as well. For the same purpose, you may want to organize your catalog using certain keywords (such as names) but you want to prevent those keywords to appear elsewhere, such as in exported or published images. In this case, you can just edit a keyword and specify the behaviour you need (right clicking on it and selecting Edit Keyword Tag):

Edit Keyword Tag

In the Edit Keyword Tag window you can see how the behaviour of a keyword can be tweaked:
  • A keyword can be included in an export (or publish) operation if the Include on Export checkbox is selected.
  • A picture will inherit containing keywords if Export Containing Keywords is selected.
  • A picture will inherit a keywords synonyms (more on this in the following sections) if Export Synonyms is selected.
If you want to prevent a keyword to be exported or published, just deselect Include on Export: no matter how you export or publish image containing this keyword, Lightroom will remove it.

Effective Keywords

We've just seen how the set of keywords applied to an image not only depends on the ones you explicitly added but also on the behaviour and the operation keywords are considered for. If you want to inspect the list of keywords effectively applied to an image you can use the Keywording panel and choose the list you're interested in.

In the Keywords section we've seen that the Keywording panel features a Keyword Tags list box. Depending on your choice, the behaviour of the panel will change:
  • Enter Keywords: the default choice, whose functionality has been described in the Keywords section.
  • Keywords & Containing Keywords: if you choose this option, the panel will turn read-only and will show the list of all keywords inherited by the image (as described in the Keyword List section).
  • Will Export: if you choose this option, the panel will turn read-only and will show the list of all keywords that will be exported with the selected image.

Synonyms

In the Edit Keyword Tag window you may have notice a Synonyms text box whose functionality we haven't described yet. Lightroom lets you associate a set of synonyms to a keyword: synonyms can be thought as an additional list of keywords associated with a keyword, whose primary purpose is search. A synonym, in fact, won't even appear in the keyword list and can only be consulted checking the configuration of each specific keyword.

Many users wonder when a synonym or a keyword should be used. That really depends on how you build your own keyword hierarchy but here are some guidelines. You should try to keep your keywords hierarchy simple, clear and intuitive so that your workflow is smooth. Also, keywords represent concepts and we know that, literally speaking, a pure synonym doesn't offer nothing new, just an alternate spelling. This is a clear case in which a synonym should be created instead of yet another keyword.

Other times, some words just doesn't fit well into your keyword hierarchy. Let's take my animal hierarchy. I defined a cat as a mammal and an animal. What about pet? Or clawed? Or furry? You cannot feasibly build a hierarchy containing all nuances that can possibly come to your mind. Also, a cat can certainly be considered a "pet", but a bird can as well. But in my hierarchy, a cat is a mammal while a bird is not. What should I do? Create a pet keyword for each of them? You can easily see how that hierarchy can become more and more cluttered if we try to introduce these concepts. In this case, you'd better use a synonym. A cat may be a synonym of "pet", of "clawed", as well as a bird may.

If you then want a synonym to be inherited from a keyword, you can select the "Export Synonyms" options of the affected keyword so that it will be explicitly listed in the keyword list of an exported or published photo.

Searching and Filtering

Any kind of metadata can be used to search and filter your catalog images.  In Part V of this tutorial we already described the basic search and filtering facilities of Lightroom, so that we will only summarize them here.

A filter by flags, ratings or labels can easily be built using the Attribute filter bar. As you can see in the next image, you can just select on the graphical user interface the values you're interested in and Lightroom will filter the contents of the currently selected folder (or collection) according to your choices.

Attribute filter

If you want to filter using keywords, you can use multiple techniques. The first is using a Metadata filter. You can configure a Keyword column for such a filter and select the keywords you want to filter with. In the following image you can see how Lightroom intelligently makes things easy including only used keywords in the currently selected folder (or collection).

Metadata Filter (stacked with a Text Filter)

Another way to search using a keyword is using a Text search. You can either freely search on every searchable field or narrowing the choice specifying the field you want to look for (as seen in the following images).

Text Filter

Text Filter - Searchable Field

The last method you can use to filter for a specific keyword is using the Keyword List panel to build a quick filter. When you hover a keyword with your mouse, a small arrow appears on the right of the keyword record, as highlighted in red in the following image. Pressing the arrow control makes Lightroom create a Metadata filter using the selected keyword. If you need to filter with just one keyword, this method is probably the quickest one.

Keyword List

Filters can also be stacked together to build even more complex search queries, mixing and matching criteria built onto any metadata field that Lightroom manages:

Multiple Filters Stacked Together

Conclusions

As we've seen, Lightroom provides excellent management capabilities and you can keep your catalog perfectly organized with very little effort. The point of an image management database is just this: making your ever growing catalog manageable. There would be no point in storing thousands of images if you couldn't effectively use the tool to quickly retrieve what you're looking for.

Some photographers start to use this kind of tools without realising their real potential nor the issues they'll start experiencing when their catalogs overgrows a set of few hundreds images. Lightroom, furthermore, is an excellent tool to develop your RAW files and it's easy to forget about it being a catalog manager as well.

That's why is very important to learn about these feature soon and start applying them to your regular workflow. The sooner, the better.

Protect Your Privacy

I want to stress once more how Lightroom can help you protect sensitive data (keywords and location information) so that you don't accidentally publish them.

Protecting the location information is probably easier because, even if geolocation data is often added automatically and you may forget about it, Lightroom gives a simple solution to this problem: just create a private location specifying its centre and its radius and just forget about it.

In the case of keywords, marking them as not exportable is up to you and you may easily forget, especially if you get used to creating them automatically from the Keywording panel. Lightroom, furthermore, does not separately manage subject names as other tools do and this fact induces users to define a keyword hierarchy for it. If you forget to configure each and every keyword according to your needs, private data may unexpectedly leak.

If you want to help me keep on writing this blog, buy your Adobe Photoshop licenses at the best price on Amazon using the links below.

Thursday, March 1, 2012

Adobe Photoshop Lightroom Tutorial - Part XIX - Graduated Filters

Part I - Index and Introduction
Part XX - Exposure vs. Brightness

The second Lightroom tool I'd like to talk about is the graduated filter.

Physical graduated filters are devices commonly used by photographers, usually to darken the filtered parts of an image whose luminance level wouldn't otherwise fall into the dynamic range of the film or the sensor.

Adobe Lightroom brings the same concept into the post-production domain and further enhances it. Lightroom's graduated filters are fully configurable and let you apply different kinds of adjustments:
  • Color temperature and tint.
  • Basic tone controls: Exposure, contrast, highlights and shadows.
  • Clarity.
  • Saturation.
  • Sharpness.
  • Noise.
  • Moiré.
  • Color.

Furthermore, they allow you to apply both positive and negative adjustments, contrary to what can usually be done with physical graduated filters which can only darken the filtered image.

To add a graduated filter to an image, or modify an existing one, you can use one of the following techniques:
  • Select the Tools/Graduated Filter menu item.
  • Select the graduated filter icon on the tool strip in the Develop module (described in the previous post).
  • Use the 'M' keyboard shortcut.

The graduated filter panel will open as shown in the following screenshot.

Graduated Filter Panel

In the upper part of the panel (called Mask) you can choose whether you're adding a new filter (New, the default choice when you open the panel) or if you want to modify an existing one (Edit). Graduated filters are fully configurable using the adjustment sliders you can find on the main panel window.

You don't need to always start a filter configuration from scratch, though. You can choose an existing filter from the Effect drop-down menu (Lightroom bundles some of them) and even create your own saving the current configuration of a filter into a new preset, using the Save the current settings as a new preset menu item. That's a pretty handy feature if you use similar settings over and over again.
Also, since you will often need to fine tune the filter settings after applying it, you can safely add a configured filter, check the results and fine tune its adjustments according to your needs.

How a Graduated Filter Works

A graduated filter is defined not only by its effect settings, but also by the following parameters:
  • Its position on the image and its inclination.
  • Its direction, or its orientation.
  • Its width.
The meaning of each of these terms is summarized in the following picture and is explained in detail in the following sections:

Characteristics of a Graduated Filter

The position of a filter just indicates where it's located on the image. Its "centre", indicated by the grey handle, is just a convenience for you to spot the existing filters on an image: as far as you move it along the filter axis (the middle line), the results won't change.

As most physical filters, a Lightroom's graduated filter applies effects whose intensity depends solely on the distance of a point from the filter axis (on other words, the intensity is the same along a line that is parallel to the filter axis). The inclination of the filter is the angle between its axis and the horizon and it's a critical parameter that determines how the chosen effect is applied to the image.

The width, determined by the distance between the filter axis and either of the other two lines that define the filter, is the width of the graduated zone of the filter. The larger the graduated zone, the softer the edges of the filter and the smoother degradation of the filter effect from one of its sides to the other.

In fact, a graduated filters applies its effect in three different ways on three different zones of the image that are determined by the its axis and its graduated zone of the filter. When you lie a filter on an image, its axis divides the image into two sides, that we will label inner and outer sides: the inner side is the side of the image that contains the point you started dragging the filter from, the other one being the outer. The filter behaviour outside the graduated zone is the following:
  • In the inner side the effect is applied with full intensity. In the previous image, for example, this zone is identified by the blue arrow.
  • In the outer side, the filter has no effect.
Inside the graduate zone, the intensity of the filter linearly falls off from 100% to 0% moving along the line perpendicular to the filter axis from the inner side to the outer side. This line, and the direction of the falloff, is indicated on the previous image with a yellow arrow.

Modifying a Graduated Filter

Any parameter of an existing graduated filter can be modified. To select a filter to modify, you've got to perform the following operations:
  • Open the graduated filters panel as explained above.
  • Select the filter you want to modify by clicking on its handle (the grey circle in its center).
  • Apply any modification you want to the effect sliders.

Similarly, you can modify the geometric characteristics of a filter by clicking and dragging:

  • Its handle, if you want to move it.
  • Its axis, if you want to rotate it.
  • Its graduated zone boundaries, if you want to change its width.

Common Uses

Historically, physical graduated filters have been used to reduce the light intensity in selected parts of an image so that all of it falls into the dynamic range of the film or the sensor being used and avoid burning it out. A common case is using a filter to reduce the intensity of the light coming from the sky. Since data from a  clipped channel cannot be recovered in post production, this type of filters is still widely used on camera. Nevertheless, it's often convenient to apply an exposure correction with a graduated filter in post production, provided your channel is not burnt out.

In the following image, I used two graduated filters: the first one was used to slightly darken the exposure of the sky and give it a soft gradient, the other one to recover detail in the shadows that were projected over the square by the building behind me:

Final Image

The first graduated filter is configured to increase the exposure by 1 f/stop and, as you can see in the following screenshot, its axis lays just along the border of the shadow and its graduated zone is very narrow.

Graduated Filter - Exposure: +1

The second graduated filter is configured to decrease the exposure of the sky only slightly, by approximately 1/3 f/stop and, as you can see in the following screenshot, its axis lays just along the border of the building in foreground and its graduated zone is very wide, so that the gradient in the sky is very smooth and soft.

Graduated Filter - Exposure: -0.3

The original picture without graduated filters is the following:

Original Image

As you can, the underexposure of the shadows couldn't have been corrected using the tones controls: since their effect is global, shadows on the other parts of the image, such as the foreground building, would have been compromised.

Please notice that there are two color temperatures on the image: the temperature of the sunny part and the temperature of the shady part. On one hand, the graduated filter I used to raise the exposure of the shadows has emphasized the details on that part of the image. On the other hand, however, it has also accentuated the difference between the two different temperatures and now you can clearly see a blue dominant in it. This problem, before Lightroom 4 was available, could only be corrected using an external image editing program. Instead, Lightroom 4 allow us to apply non global color temperature adjustments by means of both graduated filters and adjustment brushes.

Conclusion

Graduated filters are a very convenient way to apply an effect to a section of an image whose boundary is  a straight line, such as horizons, straight buildings, rectilinear shadows, and so on.

In this tutorial, we've explored how a graduated filter works and how it can be used to fix the exposure in part of an image. However, as stated in the previous sections, Lightroom will let you apply many kinds of adjustments through a graduated filter giving you a great flexibility when it comes to post processing your images.

In the cases in which a graduated filter isn't suitable, an adjustment brush can be used instead, as I will explain in the upcoming part of this tutorial.

If you want to help me keep on writing this blog, buy your Adobe Photoshop licenses at the best price on Amazon using the links below.

Sunday, December 11, 2011

Give Your Photos a Dreamy Haze Simulating a Diffusion Filter

You've just finished tweaking a great photo of yours: you think it's great but you feel it's missing something. You think that the image conveys a feeling of peace and relax and that it would really benefit from that dreamy haze you've often seen in somebody else's portraits. But you don't know how to do it.

One of the commonly used tools to achieve to give that look and feel to an image is a diffusion filter. Dreamy wedding pictures or studio portraits (such as newborn babies') are probably done that way.
The problem is:
  • You need such a filter.
  • You need a lens which you can put that filter on.
  • You need to carefully plan such a shot in advance.

Fortunately, it's not difficult to simulate such an effect in post production: you only need a photo editing tool with basic filters and layer support (such as Adobe Photoshop, Adobe Photoshop Elements or The Gimp). In this blog post, we're using a technique that's particularly suitable to portrait photography. If you're trying to tweak some landscape image, however, I suggest you take a look to the blog post about the Orton effect and see which technique best suits your image.

Beware: as usual, this isn't an advice not to try and get things right out of the camera.

The Basics

To simulate the diffusion pattern provided by a diffusion filter, we're going to blur the image with a blurring filter. The blurred image itself isn't sufficient, because you're going to lose too much detail. Instead, we'll blend it with your original image to achieve the diffusion effect.

The original image we'll use in this tutorial is the following:

Original Image

I don't think this image needs an additional dreamy look and feel: in fact, this is the final post processed shot and I'm keeping it as is. However, I chose it because it's a good candidate to show you some problems you may encounter on the way.

The first thing we'll do is duplicating the background layer:

Duplicate Layer

The next thing we'll do is blurring the new layer using the Gaussian Blur filter. The rule of thumb we discussed in the blog post about the Orton effect still holds: you need to use a blur radius sufficiently wide to blur the image while preserving overall detail. In this case (the image size is 4208x3264 pixels), I'll use a 30 pixel radius to achieve the following blurred effect:

Blurred Layer - Radius: 30 px

As you can see, the image is blurred but overall detail is not lost: in the eyes, for example, you can clearly see the iris edges and most of the features of the kid's face.

Now we're ready to blend the two layers. Depending on the image, we're probably going to use one of the following blending modes:
  • Screen.
  • Overlay.
  • Multiply.

If you recall the discussions on the previous blog posts, these three blending modes act differently on the image:
  • Screen will produce a brighter image, since it brightens a pixel according to its brightness.
  • Multiply will produce a darker image, since it darkens a pixel according to its darkness.
  • Overlay will both Screen and Multiply the image, according to a pixel brightness, producing a more contrasted image and preserving highlights and shadows.

As a rule of thumb:
  • Assuming the exposure of the image is already correct, we're going to use the Overlay blending mode.
  • If your image is a bit underexposed, it may benefit from using Screen instead.
  • If your image is a bit overexposed, it may benefit from using Multiply instead.

As usual, you've got to try and decide yourself. In this case, since I'm happy with the image exposure, we'll use the Overlay blending mode. The result is:

Final Result - Layers Overlaid
You can clearly perceive the diffusion pattern and the dreamy haze it shed over the image.

Fine Tuning

This is just the beginning. In this case, I find the image is much too dark now. The quickest way to fix it is modifying the overlaid layer opacity. This is the result setting its opacity to 80%:

Overlaid Layer - Opacity: 80%

Beware that setting the opacity too low will also remove the dreamy haze: in this case, I usually won't go below 80% and would try to fix the image exposure by fixing the original layer instead.

Using the same technique, you can control the quantity of "blur" that you're going to add to the image.

Obviously, you could also add an additional layer below the blurred one and fix exposure on it. You could use an adjustment layer, if available, or just use the Screen blending mode to raise the image exposure. The following picture is the result of 3 blended layers (from bottom to top):
  • The original.
  • A copy of the original, using the Screen blending mode and 50% opacity.
  • A copy of the original, gaussian blurred, using the Overlay blending mode.


Three Layers

But The Image Is Over-Saturated

The biggest problem of the images we're producing, however, is not exposure: it's color saturation. This is a common problem when using some blending modes such as Overlay. Raising the contrast of an image, in general, will boost color saturation as a side effect. This may be good in some kinds of photography, such as landscape, but it may be bad in others, such as portrait photography. A more saturated flower may look good but... do you notice the orange hue of the kid's hue in the final images we got so far? That's something you should always try to avoid. Ultimately, this is the reason why I chose this image for this tutorial.

Fortunately, this is again very easy to fix. Assuming once more that we're happy with the initial image color saturation, I usually reduce the saturation in the blurred layer until I'm happy with it. If the photo editing tool that you're using supports adjustment layers, this is really easy: just add a saturation adjustment layer and play with it until you like the result. If your editing tool does not supports it, you're going to use the Saturation tool back and forth until you're happy with it.

However, especially in portrait photography, I usually convert the upper layer to black and white, thus removing all of the color saturation from the overlaid layer. Once more, depending on the tool you're using, you may also be able to achieve better results fine tuning the black and white conversion. Adobe Photoshop, for example, lets you adjust the RGB channels intensity during the conversion:

Abode Photoshop Elements - Black and White Conversion Window

If you're not happy with the result, you can tweak the channel intensities. Depending on the image, I'm usually pushing up or down the red channel intensity until I like the end result.

This is the final image, using a black and white blurred layer:

Final Image - Black and White Blurred Layer Overlaid

It's far more natural, even if still very contrasted.

Conclusion

We've seen how you can use very simple layer manipulations to achieve a variety of effects. So far, we've only used the Screen and Overlay blending modes, and there's a world of possibilities for you to discover.

As a rule of thumb, you've also seen as the Overlay blending mode affects your image contrast and color saturation. Although I recognize that "punchy" images may look appealing at first, I don't really like excessive color saturation in portraits and I always end up with cooler images. That's just a matter of taste, however.

Also, I find that the dreamy haze best suits less contrasted and brighter images.

If you want to help me keep on writing this blog, buy your Adobe Photoshop licenses at the best price on Amazon using the links below.

Wednesday, July 15, 2009

Java EE: Filters. An example: reading HTTP headers.

You would not need to read HTTP headers so frequently during the development of your Java EE web modules. You aren't probably writing servlets any longer. Nevertheless, it might happen one day that you need to explore what's there, inside the HTTP headers that go to your servlet or your JSP. That's easy enough, though: just use the getHeader method (and its brothers) of the HttpServletRequest interface.

But if you're using HTTP headers you're not moving information to be used by the business logic. At least, I hope you don't. That's why you might also be interested in not polluting your business logic (servlets' code, JSPs' and so on). The solution to such problems may be a filter, as specified in the Java Servlet Specification, chapter SRV.6.

What's a filter?

Good question, that's why the servlet specification is there! Filters interpose during the call to a web resource between the client and the resource itself and the container executes them before the resource is invoked. With a filter you could, for example:
  • Intercept a call to a web resource to perform logic which is orthogonal to the code into the resource itself.
  • Modify the request content before it gets accessed by the web resource.
  • Deny access to the resource, by redirecting the user to another resource or by launching an exception.
The Servlet Specification is the place where you'll find all the details about filters. Here I'll just write down a little example so that you know what a filter is and how to use it.


As far as it concerns the code, a filter is a class which implements the javax.servlet.Filter interface. There clearly are two life-cycle management methods:
  • init(FilterConfig fc)
  • destroy()
The third method of the interface is where filter logic will be executed:
  • doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
So, let's write the body of our shiny little filter. That's pretty easy with NetBeans: it has templates for web module filters.

Coding the filter


Coding the init and destroy methods.

Coding the init and the destroy methods is straightforward, unless you really put logic in them, such as custom filter configuration, external resources initialization and so on. A basic implementation for these method is the following:

private FilterConfig filterConfig = null;
private static final boolean debug = false;

public void destroy() {
}

public void init(FilterConfig filterConfig) {
this.filterConfig = filterConfig;
if (filterConfig != null) {
if (debug) {
// the log method is implemented elsewhere
// and relies on the ServletContext instance
// to log its messages.
log("DPErrorFilter:Initializing filter");
}
}
}

Coding the filter logic

That's pretty straightforward, too. Maybe the only thing you should remember is just... invoking the other filters in the chain. That's why the method signature has that FilterChain in it. This is NetBeans' doFilter prototype

public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws IOException, ServletException {

if (debug) {
log("DPErrorFilter:doFilter()");
}

doBeforeProcessing(request, response);

Throwable problem = null;
try {
chain.doFilter(request, response);
} catch (Throwable t) {
// If an exception is thrown somewhere down the filter chain,
// we still want to execute our after processing, and then
// rethrow the problem after that.
problem = t;
t.printStackTrace();
}

doAfterProcessing(request, response);

// If there was a problem, we want to rethrow it if it is
// a known type, otherwise log it.
if (problem != null) {
if (problem instanceof ServletException) {
throw (ServletException) problem;
}
if (problem instanceof IOException) {
throw (IOException) problem;
}
sendProcessingError(problem, response);
}
}

Reading HTTP headers

The last piece of code you miss is the logic itself. Here it is:
private void doBeforeProcessing(ServletRequest request, ServletResponse response)
throws IOException, ServletException {
if (debug) {
log("DPErrorFilter:DoBeforeProcessing");
}

// wrapping the servlet request
if (!(request instanceof HttpServletRequest)) {
log("Request isn't an instance of HttpServletRequest, skipping...");
return;
}

HttpServletRequestWrapper req =
new HttpServletRequestWrapper((HttpServletRequest) request);

// read your headers here
}

The only trick here is wrapping your ServletRequest (which lacks HTTP-related functionality) parameter into an HttpServletWrapper. I also do an instanceof check before doing it, just in case, and return if the object type isn't the expected.

Using the filter

To use the filter, you have to deploy it and configure your deployment descriptor, the web.xml file. The required steps are:
  • Declare the filter.
  • Map the filter.
The filter declaration is a typical declaration: you define a name for your filter class. The filter mapping defines when the filter execution is triggered; you can specify an URL pattern and an optional dispatcher type. The dispatcher type also specifies when the filter has to be triggered, depending on the request type being executed:
  • REQUEST (the default value)
  • FORWARD
  • INCLUDE
  • ERROR
Here's a typical XML fragment from web.xml:
<filter>
<filter-name>DPErrorFilter</filter-name>
<filter-class>
es.trafico.datapower.exceptions.filters.DPErrorFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>DPErrorFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

In this case the filter is triggered at every request because of the /* URL pattern.