This document contains questions and answers about image processing concepts such as linear indexing, converting between m-paths and 4-paths, adjacency in image subsets, shortest path lengths between pixels using different adjacency types, and inverse affine transformations including scaling, translation, shearing, and rotation. Equations and examples are provided to derive the inverse transformations from the original transformations.
Interactive Powerpoint_How to Master effective communication
DIP Homework: Image Resolution and Linear Indexing
1. DIP Homework: 3
Q- 5 You are preparing a report and have to install in it an image of size 2048 * 2048 pixels?
a- Assuming on limitations on the printer, what would the resolution in line pairs mm
have to be for the image to fit in a space of size 5*5cm?
Answer: the resolution of the fitting in the space size of 5*5 can be calculated
2048 𝐿𝑖𝑛𝑒𝑠
50 𝑚𝑚
≅ 41 lines / min
≅ 20 lines / min
b- What would the resolution have to be in dpi for the image to fit in 2*2 inches?
Answer: the image resolution for fitting 2*2 inch will be calculated as
2048 𝑑𝑜𝑡𝑠
2 𝑖𝑛𝑐ℎ
= 1024 dots per inch
Q- 11 When discussing linear indexing in section 2.4, we arrived at the linear index in Eq.
(2.14) by inspection. The same argument used there can be extended to a 3-D array with
coordinates x,y and z, and corresponding dimensions M, N and P. The linear index for any
(x,y,z) is S = x + M (y + Nz) = x + Mg + Myz
Start with expression and
a- *Drive Eq. (2.15)
b- Drive Eq. (2.16)
Answer:
For 2D array to 1D array (leaner)
∝ = 𝑀𝑦 + 𝑥
𝑥 = ∝ +𝑥
⟹ 𝑦 =
𝑎−𝑥
𝑀
For 3D case we have
( 𝑥, 𝑦, 𝑧) ⟶ 𝑠
M
N
y
x
m-1
0
2. 𝑠 = 𝑥 + 𝑚 ( 𝑦 + 𝑁𝑧) ⟹ 𝑥 = 𝑠 𝑚𝑜𝑑 𝑚
𝑠 − 𝑥 = 𝑚 (𝑦 + 𝑁𝑧)
𝑦 + 𝑁𝑧 =
𝑠−𝑥
𝑀
⟹ 𝑦 = (
𝑠−𝑥
𝑀
) 𝑚𝑜𝑑 𝑀
Since the (
𝑠−𝑥
𝑀
) < 𝑀 , (
𝑠−𝑥
𝑀
) 𝑚𝑜𝑑 𝑁 =
𝑠−𝑥
𝑀
. The maximum value of S is MN - 1 and, the
maximum of x is 0.
Q- 16 Develop an algorithm for converting a one-pixel-thick m-path to a 4-paths?
Answer: Any pixel p (x, y) has two vertical and two horizontal neighbors, given by (x+1,
y), (x-1, y), (x, y+1), (x, y-1) and This set of pixels are called the 4-neighbors of P, and is
denoted by N4 (P) and each of them are at a unit distance from P. We assume that (x,y) is
spatial location of the starting of 4-path. and in image path is represented by 1's and
remaining values are 0's.
1- we assign (p,q) is the m-connected neighborhood of (x,y) which is not processed yet
2- For each pixel is unit distance from (x,y)
3- Check whether the common 4-neighborhood pixel position of (x,y) and (p,q) is part of
existing path, if not make any one of the common 4-neighborhood to be 1, else no need
to do anything(because it is already 4-connected).
4- We assign (x,y )= (p,q)
5- 4-neighbors of p, denoted by N4(p): (x-1, y), (x+1, y), (x, y-1), and (x, y+1).
The solution to this problem consists of defining all possible neighborhood shapes to go from a
diagonal segment to a corresponding 4-connected segment, as shown in fig bellow. The algorithm
then simply looks for the appropriate match every time a diagonal segment is encountered in the
3. boundary for converting from an m-connected path to a 4-connected path simply involves
detecting diagonal segments and converting them to the appropriate 4-connected segment.
Q- 14 Consider the two image subsets, S1 and S2, shown in the following figure. For V = {1},
determine whether these two subsets are (a) 4-adjacent, (b) 8-adjacent, or (c) m-adjacent.
A- Let p and q be as shown in Fig. Then:
(a) S1 and S2 are not 4-connected because q is not in the set N4(p);
(b) S1 and S2 are 8-connected because q is in the set N8(p);
(c) S1 and S2 are m-connected because
(i) q is in ND(p), and
(ii) the set N4(p) ∩ N4(q) is empty
B- Paths
A (digital) path (or curve) from pixel p with coordinates (x, y) to pixel q with coordinates
(s, t) is a sequence of distinct pixels with coordinates
4. (x0, y0), (x1,y1), ……., (xn, yn)
where (x0, y0) = (x, y), (xn, yn) = (s, t),
and pixels (xi, yi) and (xi-1, yi-1) are adjacent for 1≤ i ≤ n.
In this case, n is the length of the path.
If (x0, y0) = (xn, yn) the path is a closed path.
The path can be defined 4-,8-m-paths depending on adjacency type.
Let S be a subset of pixels in an image. Two pixels’ p and q are said to be
connected in S if there exists a path between them consisting entirely of pixels
in S
For any pixel p in S, the set of pixels that are connected to it in S is called
a connected component of S.
If it only has one connected component, then set S is called a connected
set.
Q- 18 Consider the image segment show in the figure that follows
a- As in section 2.5, let V= {0,1} be the set of intensity values to defined adjacency.
Compute the lengths of the shortest 4-, 8- and m-path between p and q in the following
image. If a particular path does not exist between these points, explain why?
Answer- (a) When V = {0,1}, 4-path does not exist between p and q because it is impossible to get
from p to q by traveling along points that are both 4-adjacent and also have values from V. Figure
P2.15(a) shows this condition; it is not possible to get to q. The shortest 8-path is shown in Fig.
P2.15(b); its length is 4. The length of the shortest m- path (shown dashed) is 5. Both of these
shortest paths are unique in this case.
b- Repeat (a) by using V= {1,2}
Answer- (b) One possibility for the shortest 4-path when V = {1, 2}is shown in Fig.
P2.15(c); its length is 6. It is easily verified that another 4-path of the same length exists
5. between p and q. One possibility for the shortest 8-path (it is not unique) is shown in Fig.
P2.15(d); its length is 4. The length of a shortest m-path (shown dashed) is 6. This path is
not unique.
Q- 30 Give Venn diagram for the following expression?
a- *(𝑨 ∩ 𝑪) - (A ∩ B ∩ 𝑪 )
b- (𝑨 ∩ 𝑪) ∪ (𝑩 ∩ 𝑪)
c- B - [(𝑨 ∩ 𝑩)- (A ∩ B ∩ 𝑪 )]
d- B-B ∩ ( A ∪ C); Give that ( 𝑨 ∩ 𝑪)= ∅
Q- 37 We know from the E.q (2-45) that an offline transformation of coordinators given by
6. Where (x’,y’) are the transformed coordinators (x,y) are the original coordinator, and the
element of A are given in the table 2.3. for the various type of transformation. The inverse
transformation, A-1, to go from transformed back to the original coordinators in just as
important for performing inverse mappings.
a- Find the inverse scaling transformation?
b- Find the inverse translation transformation?
c- Find the inverse vertical and horizontal shearing transformation?
d- Find the inverse rotation transformation?
e- Show a composite inverse translate/rotation transformation?
Answer for the former of matrix
1 0 0
0 1 0
0 0 1
x = v and y = w
𝑐 𝑥 0 0
0 𝑐 𝑦 0
0 0 1
x’ = cx v and y’ = cy w
For the inverse translation transformation
1 0 𝑡 𝑥
0 1 𝑡 𝑦
𝑡 𝑥 𝑡 𝑦 1
x’ = v + tx and y’ = w + ty
For the inverse vertical and horizontal shearing transformation
1 𝑠 𝑥 0
0 1 0
0 0 1
x’ = v +sx w and y’ = w
1 0 0
𝑠 𝑘 1 0
0 0 1
x’ = v and y’ = sk x + w
7. For the inverse rotation transformation
−
𝑐𝑜𝑠 𝜃 𝑠𝑖𝑛 𝜃 0
𝑠𝑖𝑛 𝜃 𝑐𝑜𝑠 𝜃 0
0 0 1
x’ = v cos 𝜃 - w sin 𝜃 and y’ = v sin 𝜃 + w cos 𝜃
Note:
The above diagram used of OpenCV3 operates on images. Image operations are mainly based on
various coordinate transformations of images, such as scale transformation, rotation
transformation, translation transformation and offset transformation (horizontal or vertical). These
transformations are all directed at the coordinates of images, not the pixels of images. They can be
collectively called affine transformation. The above description is for several transformations in
Gonzalez's Digital Image Processing.