CSCI 3290 Assignment 3: Tone Mapping solved

$35.00

Category: You will receive a download link of the .ZIP file upon Payment

Description

5/5 - (1 vote)

1 Assignment description
Tone mapping is a technique used in image processing to map one set of colors to another to approximate
the appearance of high-dynamic-range (HDR) images in a medium that has a more limited dynamic
range. Tone mapping operators can be divided into two main types:
• global operators: non-linear functions based on the luminance and other global variables of the
image.
• local operators: the parameters of the non-linear function change in each pixel, according to
features extracted from the surrounding parameters.
In this assignment, you’ll need to implement these two types of tone mapping with 2 operators
respectively: global logarithmic operator and Durand’s local operator.
2 Assignment details
2.1 Overview
Given the path of an HDR image, the tone mapping procedure can be described as follows:
2.2 ToneMap functions
The algorithm of a generic 𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇 can be described as follows:
We will discuss the implementation details in next several subsections.
procedure 𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇(𝐻𝐻𝐻𝐻𝐻𝐻_𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼_𝑃𝑃𝑃𝑃𝑃𝑃ℎ, 𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇)
1. Load 𝐻𝐻𝐻𝐻𝐻𝐻_𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼 from 𝐻𝐻𝐻𝐻𝐻𝐻_𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼_𝑃𝑃𝑃𝑃𝑃𝑃ℎ. [provided]
2. Apply 𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇 to 𝐻𝐻𝐻𝐻𝐻𝐻_𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼, get tone mapped 𝐿𝐿𝐿𝐿𝐿𝐿_𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼.
3. Apply gamma correction to the result 𝐿𝐿𝐿𝐿𝐿𝐿_𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼. [provided]
4. Convert the 𝐿𝐿𝐿𝐿𝐿𝐿_𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼 to 8-bit. [provided]
5. Save the 𝐿𝐿𝐿𝐿𝐿𝐿_𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼. [provided]
procedure 𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇(𝐻𝐻𝐻𝐻𝐻𝐻_𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼)
1. Compute the Luminance 𝐿𝐿 of each pixel in the 𝐻𝐻𝐻𝐻𝐻𝐻_𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼.
[compute_luminance()]
2. Apply 𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇 to 𝐿𝐿, compute the Display Luminance 𝐷𝐷 =
𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇(𝐿𝐿). [tone mapping operators]
3. Map Display Luminace 𝐷𝐷 on the 𝐻𝐻𝐻𝐻𝐻𝐻_𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼 to compose the 𝐿𝐿𝐿𝐿𝐿𝐿_𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼.
[map_luminance()]
4. Return 𝐿𝐿𝐿𝐿𝐿𝐿_𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼.
2.3 Operators
2.3.1 Logarithmic operator
We can use the following function to map the luminance 𝑳𝑳 of the 𝐻𝐻𝐻𝐻𝐻𝐻_𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼 to display luminance 𝑫𝑫:
𝐷𝐷 = log(𝐿𝐿 + 𝜏𝜏) − log (𝐿𝐿𝑚𝑚𝑚𝑚𝑚𝑚 + 𝜏𝜏)
log(𝐿𝐿𝑚𝑚𝑚𝑚𝑚𝑚 + 𝜏𝜏) − log (𝐿𝐿𝑚𝑚𝑚𝑚𝑚𝑚 + 𝜏𝜏)
where 𝐿𝐿𝑚𝑚𝑚𝑚𝑚𝑚 and 𝐿𝐿𝑚𝑚𝑚𝑚𝑚𝑚 are the minimum and maximum luminance of the scene, 𝜏𝜏 = 𝛼𝛼(𝐿𝐿𝑚𝑚𝑚𝑚𝑚𝑚 − 𝐿𝐿𝑚𝑚𝑚𝑚𝑚𝑚 ),
𝛼𝛼 ≥ 0. This equation ensures that the maximum and minimum luminance values of the scene are
respectively mapped to the maximum and minimum luminance of the display device. Here the range of
display luminance is [0,1]. Adjusting 𝛼𝛼 will appropriately tune the overall brightness of the reproduced
image. In this assignment, we set 𝛼𝛼 = 0.05.
This part is related to the function log_tonemap().
2.3.2 Durand’s operator
Beside the above two global tone mapping operators, you’ll need to implement a local tone mapping
operator in this assignment. You’ll be implementing a simplified version of Durand’s operator. The steps
are roughly as follows:
where 𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐 is a user-controllable parameter. We set 𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐 = 50.
The above part is related to the function durand_tonemap().
Since the base layer is computed by the bilateral filter, you may need to implement the filter:
𝐼𝐼filtered(𝑥𝑥) = 1
𝑘𝑘(𝑥𝑥) � 𝑓𝑓𝑠𝑠(𝑥𝑥, 𝑥𝑥𝑖𝑖; 𝜎𝜎𝑠𝑠)𝑔𝑔𝑟𝑟(𝐼𝐼(𝑥𝑥𝑖𝑖) − 𝐼𝐼(𝑥𝑥); 𝜎𝜎𝑟𝑟)𝐼𝐼(𝑥𝑥𝑖𝑖)
𝑥𝑥𝑖𝑖∈Ω
𝑘𝑘(𝑥𝑥) = � 𝑓𝑓𝑠𝑠(𝑥𝑥, 𝑥𝑥𝑖𝑖; 𝜎𝜎𝑠𝑠)𝑔𝑔𝑟𝑟(𝐼𝐼(𝑥𝑥𝑖𝑖) − 𝐼𝐼(𝑥𝑥); 𝜎𝜎𝑟𝑟)
𝑥𝑥𝑖𝑖∈Ω
where 𝐼𝐼𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓 is the filtered image; 𝐼𝐼 is the original input image; 𝑥𝑥 are the coordinates of the current
pixel to be filtered; Ω is the window centered in 𝑥𝑥, so 𝑥𝑥𝑖𝑖 ∈ Ω is another pixel; 𝑓𝑓𝑠𝑠 is the 2D Gaussian kernel
(spatial kernel) for smoothing differences in coordinates, here we choose 𝜎𝜎𝑠𝑠 = 0.02 ×
min(𝑖𝑖𝑖𝑖𝑖𝑖𝑖𝑖𝑡𝑡_𝑤𝑤𝑤𝑤𝑤𝑤𝑤𝑤ℎ, 𝑖𝑖𝑖𝑖𝑖𝑖𝑖𝑖𝑖𝑖_ℎ𝑒𝑒𝑒𝑒𝑒𝑒ℎ𝑡𝑡); 𝑔𝑔𝑟𝑟 is the 1D Gaussian kernel (range kernel) for smoothing
differences in intensities, here we choose 𝜎𝜎𝑟𝑟 = 0.4. The spatial kernel size (or the window size) can be
computed as 𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠 = 2 × max(𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟𝑟(1.5𝜎𝜎𝑠𝑠), 1) + 1.
procedure 𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷(Luminace 𝐿𝐿)
1. Compute the log intensity log10(𝐿𝐿)
2. Filter that with a bilateral filter get the base layer: 𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵 =
𝑏𝑏𝑏𝑏𝑏𝑏𝑏𝑏𝑏𝑏𝑏𝑏𝑏𝑏𝑏𝑏𝑏𝑏_𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓(log10(𝐿𝐿))
3. Decompose the detail layer: 𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷 = log10(𝐿𝐿) − 𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵
4. Compute 𝛾𝛾 = log10 𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐
max(𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵)−min(𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵)
5. Reconstruct the luminance: 𝐷𝐷′ = 10(𝛾𝛾×𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵+𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷𝐷)
6. Compute the display luminance: 𝐷𝐷 = 𝐷𝐷′ × 1
10max(𝛾𝛾×𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵𝐵)
The above part is relate to bilateral_filter(). You are allowed to use a bilateral filter from some thirdparty libraries. In that case, you can just put your function invocation inside the function body of
bilateral_filter(). If you choose to implement the bilateral filter by yourself, you will get some extra
bonus points.
2.4 Mapping Luminance
Since the desired result is an RGB image, we need to map the display luminance 𝑫𝑫 to the color space.
Conventionally, we can scale the RGB values of 𝐻𝐻𝐻𝐻𝐻𝐻_𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼 by 𝐷𝐷
𝐿𝐿 to get the 𝐿𝐿𝐿𝐿𝐿𝐿_𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼:
𝐶𝐶ℎ𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑙𝑙𝑖𝑖𝑖𝑖𝑖𝑖𝑖𝑖𝑖𝑖 = 𝐶𝐶ℎ𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑙𝑙𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜 ×
𝐷𝐷
𝐿𝐿
where 𝑳𝑳 is the luminance of the 𝐻𝐻𝐻𝐻𝐻𝐻_𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼. This part is related to the function map_luminance().
2.5 Summary
In this assignment, you are required to implement tone mapping in Python 3.4+. In order to make the
skeleton code functional, you need to complete these four functions in the skeleton code:
map_luminance(), bilateral_filter(), log_tonemap(),durand_tonemap().
The skeleton code depends on OpenCV and Numpy. You are allowed to import third-party libraries into
the code. However, you are not allowed to directly use tone mapping operator from these libraries.
Moreover, you can find some HDR images in the test_images directory. Tone mapped images will be
generated in the output directory.
3 Submission guidelines
You need to submit the completed tone_mapping.py to the Blackboard.
3.1 Marks
• map_luminance(): 10 points
• log_tonemap(): 30 points
• durand_tonemap(): 60 points
• bilateral_filter(): extra 20 bonus points if you implement this filter by yourself
(with pure Python and Numpy)
3.2 Put personal information in your source code
In your source code file, type your full name and student ID, just like:
3.3 Late submission penalty
If you submit your solution after the due date, 10 marks will be deducted per day, and the maximal
deduction is 30 marks even you delay more than 3 days. But there are hard deadlines as we need time to
grade and submit grade. The hard deadline is 29 April 2020. After this day, we will not grade your
assignment.
#
# CSCI3290 Computational Imaging and Vision *
# — Declaration — *
# I declare that the assignment here submitted is original except for source
# material explicitly acknowledged. I also acknowledge that I am aware of
# University policy and regulations on honesty in academic work, and of the
# disciplinary guidelines and procedures applicable to breaches of such policy
# and regulations, as contained in the website
# http://www.cuhk.edu.hk/policy/academichonesty/ *
# Assignment 3
# Name:
# Student ID:
# Email Addr:
#