In [1]:

```
%run load_lib_ch1.py
```

Point operations are functions performed on each pixel of an image, regardless of the other pixels. They can be ** unary** or

In [2]:

```
def no_operation(x):
return x
```

In [3]:

```
image_function_graph(no_operation)
```

A typical point operation applies a mathematical function on each pixel. The cell below defined a function $T(x,y) = f(x,y)/2$ which halves the intensity of each pixel. The resulting image appears as a darker version of the original.

In [4]:

```
def fn_1(x):
x = np.asarray(x)
return (x/2).astype(np.uint8)
```

In [5]:

```
compare_result(img, apply_point_op(img, fn_1))
```

In [6]:

```
image_function_graph(fn_1)
```

Another typical example for a point operation is *thresholding* where each pixel is compared to a threshold and processed accordingly. Thresholding is often used to binarize an image to a black and white image, or to mask out details of a photo.

**Bottom threshold**:

$T(x,y) = $

$0$, for $f(x,y) < threshold$

$f(x,y)$, for $f(x,y) > threshold$

In [7]:

```
def fn_thresh_bot (x):
thresh = 75
y = fn.rgb2luma(x)
if (y < thresh):
return [0,0,0]
else:
return x
```

In [8]:

```
compare_result(img, apply_point_op(img, fn_thresh_bot))
```

In [9]:

```
image_function_graph(fn_thresh_bot)
```

**Binarization**:

$T(x,y) = $

$0$, for $f(x,y) < threshold$

$255$, for $f(x,y) > threshold$

In [10]:

```
def fn_thresh_both (x):
thresh = 80
y = fn.rgb2luma(x)
if (y < thresh):
return [0,0,0]
else:
return [255, 255, 255]
```

In [11]:

```
compare_result(img, apply_point_op(img, fn_thresh_both))
```

A

In [12]:

```
image_function_graph(fn_thresh_both)
```

Virtually **any function** of pixel intensity can be applied to produce a processed point operation.

Gamma correction is a type of point operation that follows the formule $f(x,y) = c.r^\gamma$, where $c$ and $\gamma$ are the tuning parameters and $r$ is the normalized intensity. Gamma correction is widely used to correct the input radiance mapping of the camera pixels and display the image properly on monitors.

In [27]:

```
def fn_gamma_correction (x):
x = np.asarray(x)
gamma = 2.2
r = 1
y = r*np.power(x/255.0,gamma)*255
return y.astype(np.uint8)
```

In [28]:

```
image_function_graph(fn_gamma_correction)
```

Point Operations: Roger Easton, Basic Principles of Imaging Science II, Chapter 15 Point Operations