"**Instructions** Edit this **notebook** and submit it for each group (binome) of the session, name it **LabX_Name1_Name2**, with X the number of the lab session and **Name1,2** your surnames. Upload it in the folder corresponding to your group and lab in **Chamilo**.\n",
"**Instructions** Take and edit this **notebook** and submit it for each group (binome) of the session, name it **LabX_Name1_Name2**, with X the number of the lab session and **Name1,2** your surnames. Upload it in the folder corresponding to your group and lab in **Chamilo**.\n",
"\n",
"**Deadline submission** The material report should be submitted within a week from the lab work. The preparation has to be done individually and will be collected at the **beginning** of the lab.\n",
"\n",
...
...
%% Cell type:markdown id: tags:
# Lab session of Image Analysis
## BE 2. Image filtering, edge detection, object detection
### Duration: 2h
**Instructions**Edit this **notebook** and submit it for each group (binome) of the session, name it **LabX_Name1_Name2**, with X the number of the lab session and **Name1,2** your surnames. Upload it in the folder corresponding to your group and lab in **Chamilo**.
**Instructions**Take and edit this **notebook** and submit it for each group (binome) of the session, name it **LabX_Name1_Name2**, with X the number of the lab session and **Name1,2** your surnames. Upload it in the folder corresponding to your group and lab in **Chamilo**.
**Deadline submission** The material report should be submitted within a week from the lab work. The preparation has to be done individually and will be collected at the **beginning** of the lab.
**Objectives** The objectives of this lab work are:
- Evaluate the performances of image denoising
- Object detection by phase correlation
**Pay attention** to the following:
- always check the image types and ranges (e.g., (-1,1) or (0,255), ...)
- always check the packages documentation in order to be sure of the function signature
- always prefer working with float images when manipulating over them. You can use the function `skimage.util.img_as_float` and `skimage.util.img_as_ubyte` for representing the image as float in the range (-1,1) and as uint8 in the range (0,255), respectively. NOTE: these function will not work when the ranges of variability of the pixels are different from the ones above (i.e., if you adjust the saturation, etc...). When this arises, use the function `cv2.normalize(...)` jointly with numpy's `astype(...)` as shown in section 1.1.
To evaluate the performances of image denoising, we artificially add noise to images and try to remove it. This way, we can compare the denoised image to the reference one.
## 1.1 Noise simulation
- Add Gaussian noise to the images **cameraman**, **baboon** and **cafe**.
Note: use `Inoisy = Iin + sigma * numpy.random.normal(size=img1.shape)`, where `Iin` is the input image and `sigma` the standard deviation of the noise.
- Comment on the image histogram before and after adding noise, with different values of the noise level `sigma`.
- Add *salt & pepper* noise to the image with the function `Inoisy2=skimage.util.random_noise(Iin, mode='s&p', amount=dens)`, where `dens` represents the noise density.
For the above denoising procedures, assess the "objective" quality of the image by comparing the original $I_{in}$ and the denoised image $I_{den}$ through PSNR; we remind here its definition:
where $d$ is the maximum possible value of the image ($d = 255$ for 8-bit images) and MSE represents the mean square error among the two images. What are the possible disadvantages of using this quality index?
%% Cell type:code id: tags:
``` python
# To-Do
```
%% Cell type:markdown id: tags:
# 2. Edge detection
- How would you find the edge of an image?
- Get the magnitude of the gradient of the images cameraman, baboon and cafe, using the Sobel filters (in the horizontal and vertical direction; then take the mean square of the two results to summarize the results in both directions). You can use the function `cv2.Sobel(...)` (doc: https://docs.opencv.org/3.4/d4/d86/group__imgproc__filter.html#gacea54f142e81b6758cb6f375ce782c8d) or `scipy.ndimage.sobel(...)` (recommended).
Open the image `tokens.tif` as `Iin`. The goal is to detect the position of tokens, specifically a black image with a white dot at the center of each token. For this, implement the phase correlation method using a simulated disk $I_d$ as the element to detect. We briefly recall here that the requested map $R$ may be obtained as: