---
title: DIP Lab 2
tags: DIP
---
# DIP Lab 2
105042015 沈冠妤 外語20
### 1. Proj03-01 - Image Enhancement Using Intensity Transformations (30%)
* **Explanation:**
* Change class of input image to double before processing, and scale back to 0~255 to obtain grey-scale image.
* c is a constant given by user. In this report, c is fixed as 1.
```
% Log transformation:
% Log in matlab is natural log (base e)
img_new = c * log(1+double(img_orig));
% Scale the new image to 0~255
img_new = uint8(255 * mat2gray(img_new));
% Power-law transformation:
img_new = c * double(img_orig).^pow;
img_new = uint8(255 * mat2gray(img_new));
```
* **Result:**
<img src="https://i.imgur.com/qd7VoNX.png" height="375" width="85%"/>
* **Comparison:**
Log transformation enhance the intensity of low-level values, while the high-level values are compressed. The result is as predicted, for the fraction of the spine shown in low-level values can be seen clearly after the transformation.
In power-law transformation, if the power of the equation > 1, it maps high-level values to a wider range, clearify the bright parts of the image; if the power < 1, it maps low-level values to a wider range, clearify the dark parts of the image. For this input image, we want to clearify the dark parts to see the fraction of the spine. Hence, **we tried power=0.1, 0.3, 0.4, 0.6, 0.8** to see which obtains the best result. For this case, **pow=0.4 seems the best**.
We use **c=1** for both results to maintain consistency. The curves of both intensity transformation functions (pow=0.4 for power-law transformation) seem similar, so the output result images are also similar. The higher-level values of log transformation seems to be compressed more.
---
### 2. Proj03-02 – Histogram Equalization (30%)
* **Explanation:**
Draw histogram and implement histogram equalization.
Histogram: x axis indicates the intensity of the pixels. For grey scale image, x ranges from 0 to 255; y axis indicates the frequecy of a given intensity
For histogram equalization, calculate PDF, CDF, and round the values to obtain transition table.
* **Result:**
<img src="https://i.imgur.com/tpyefP9.png" height="375" width="85%"/>
<img src="https://i.imgur.com/SSCVOTP.png" height="375" width="85%"/>
* **Comparison:**
The original image is composed mostly by low-level values, and mostly black (intensity=0), which is shown by the histogram.
The CDF of original image also shows that the intensity of pixels are mostly low, the slope is higher in low-level x axis. There are also some white (intensity=255) pixels, so the slope rises in x=255.
The new image after image equalization has a more uniform distribution of histogram. Hence the result new image is clearified.
---
### 3. Proj03-03 & Proj03-05 – Spatial Filtering, Unsharp Masking (40%)
* **Explanation:**
Implement a spatial filtering function, and then use it for unsharp masking.
Method for unsharp masking:
* Blur the original image with 3x3 average filtering
* Subtract the blurred image from the original to obtain the mask
* Add the mask to original image to unsharp: G = F + k * mask
* **Result:**


* **Comparison:**
Image after unsharp masking is more clear as expected. We use **k=10** to emphasize the unsharp effect. To unsharp more, we can use a larger mask for blurring (3x3 for current result), or larger k constant.