Week5Histograms&Curves

advertisement
CSC 192: The Art and Science of Digital Images
Week 5 Lesson: Histograms and Curves
Purpose
 Image Processing: Basics
 Image Processing: Histograms
 Image Processing: Curves
Lesson Outline


Image Processing: Basics
o Image transform: a process of changing the color or grayscale values of image pixels
 Often done to invoke a certain mood, emotion or feeling
o Two types of image transformation
 Pixel point processing: a pixel value is changed based only on its original value
without referencing surrounding pixels
 Spatial filtering: a pixel value is changed based on the value of bordering pixels
Image Processing : Histograms
o A discrete function that describes frequency
distribution. In a histogram of pixel colors, for
each possible color the histogram shows the
number of pixels there are of that color in the
image.
o Ex) A grayscale image would have values
extending from 0 to 255 along the horizontal axis,
and each of those values would have a
corresponding line extending above it
representing how many pixels in the image have that value.
o RGB images have three separate histograms for each of the colors since each pixel has a
separate red, green and blue value. When you look at the pixel, the eye blends the
three separate colors channels into one.
o Clipped areas of the image
 Pixels whose values fall outside the sensitivity range of the camera or sensor.
For grayscale images, these pixels become pure black or white. For RGB images,
one or more of the color channels become 0 or 255.
o Note: If the histogram has most of its values and peaks in the middle or has a bell curve
shape, the picture does not have a wide dynamic range and does not have much
contrast as a consequence. This is not what you usually want, as contrast helps give the
image a sharper look.
o Using the histogram
 GIMP: Select Colors  Brightness – Contrast  On the new window, select the
button Edit these Settings as Levels.
 PaintShop Pro: Select Adjust  Brightness and Contrast  Histogram
Adjustment…
 Under the histogram, move the triangle markers underneath to modify the
brightness levels.
 How it works
CSC 192: The Art and Science of Digital Images



As you move the left marker closer to the middle, all pixel values to the
left of or at the new marker position become pure black.
As you move the right marker closer to the middle, all pixel vales to the
right of or at the new marker position become pure white.
The middle pixels values are scaled to account for the new range
between black and white.
GIMP Histogram

PaintShop Pro Histogram
To experiment with the histogram sliders, follow the instructions:
o Open the file called ‘GirlOnDockGS.tif’ in GIMP. It’s a grayscale file, so all the pixel values
are between 0 and 255.
o Hover the cursor over the picture at some random spot. Write down the pixel location
and the pixel value.
 I choose the pixel at row 127 column 161. It has pixel value 192. Choose a
different pixel of your own and write down its location and value:
row_____
o
column _____
grayscale value _____
Now let’s adjust the picture’s contrast.
 From the menu select Colors  Brightness-Contrast…. In the BrightnessContrast dialog, select Edit these Settings as Levels, so that you see this view.
CSC 192: The Art and Science of Digital Images

o
o
o
Note: Make sure the Pointer window is open so that when you move the cursor
around on the picture, you can see the pixel value in the Pointer window.
(Windows  Dockable Dialogues Pointer)
 Move the left slider of the histogram over to pixel value 50. Move the right
slider of the histogram to pixel value 222.
 Now pixel value 50 becomes 0 (black), pixel value 222 becomes 255 (pure white),
and all the values in between are spread out evenly. Notice that this means that
relatively dark pixels (< 128) become darker and relatively light pixels (> 128)
become lighter.
A function is something that takes an input value and gives you an output value. The
function that takes a pixel value as input and changes the value for an effect like
brightening or increasing contrast is called a transfer function.
Can you imagine a transfer function that would have effect we want for increasing
contrast so that values that are < 128 are made smaller, and values > 128 are made
larger? The graph of such a function would look something like this:
Transfer functions whose graphs have this ‘S’ shape are called sigmoid functions. An
example of a sigmoid function is this:
𝑓(𝑥) =
1
1 + 𝑒 −𝑡𝑥
where e is the exponential constant with value approximately 2.718 and t is a value that
you can set to affect the shape of the S curve. If we set 𝑡 = 3, the graph of the function
is this:
o
Let’s see if we can apply this function to get an approximation of the midrange grayscale
values after we adjust the histogram. For this example, the pixel we looked at before
CSC 192: The Art and Science of Digital Images
the contrast-change had a grayscale value of 172. To input the pixel value into the
sigmoid function, we first have to put it on a scale of 1 to 1 rather than 0 to 255
because that’s what the function expects. We can do this as follows:
172
(
∗ 2) − 1 ≈ 0.35
255
o
Now let’s input 0.35 into the function:
𝑓(0.35) =
o
o
1
1 + 𝑒 −3∗0.35
≈ 0.7408
Now we have to scale that number back to a number between 0 and 255 because this is
the scale used by GIMP. Since the outputs of the sigmoid function range from 0 to 1, we
can simply multiply 0.7408 by 255 to get about 189.
Go back to your picture and try to find the same pixel position whose value you wrote
down before changing the contrast. See what its pixel value is after the change. Mine
is 191. I estimated with the sigmoid function that it would be 189. Not a bad estimate.
How does yours come out?
grayscale value predicted by sigmoid function _____
actual grayscale value after contrast is adjusted _____

o GIMP doesn’t use exactly the sigmoid function that I used, but it’s pretty close.
Image Processing: Curves
o The curves tool allows you to create a transfer function for contrast with a handy
graphical user interface.
o It is most commonly used with modifying brightness and contrast levels. The graph
option gives you more control.
o For an RGB image, these modifications can be applied to each of the different color
levels or to the composite of all three of them.
o Using curves
 GIMP: Select Colors  Curves  On the new window, select the button Edit
these Settings as Levels  on the new window, select the button Edit these
Settings as Curves
 PaintShop Pro: Select Adjust  Brightness and Contrast  Curves…
 Click on the line to create a point, and drag it around until you reach the desired
effect. Multiple points can be added to the curve. You can move the curve’s end
points as well, but we usually keep these in place so we don’t get any more pure
white or black pixel values.
 How it works
 These curve modifications creates a new function which is then applied
to every pixel in the image.
CSC 192: The Art and Science of Digital Images
GIMP Curves
o
PaintShop Pro Curves
Undo changes you made through the histogram. Then see if you can adjust the contrast
in a similar way by shaping the graph in the Curves dialog box.
Reading


Why do we care?
o Text: 3.1 Tools for Digital Image Processing (3rd paragraph)
Image Processing  Histograms
o Text: 3.7.1 Histograms
Videos

Histograms
o https://www.youtube.com/watch?v=Ek8jbor1iWY
Assignment
 Prepare for Presentation
 Practices on Histograms and Curves
Download