Pārlūkot izejas kodu

What was in the book

Luis Albertorio 8 gadus atpakaļ
vecāks
revīzija
75f3a50edf
1 mainītis faili ar 199 papildinājumiem un 1 dzēšanām
  1. 199
    1
      README-en.md

+ 199
- 1
README-en.md Parādīt failu

@@ -1,6 +1,204 @@
1
-
2 1
 #Recursion - Image Scrambler
3 2
 
4 3
 ![main1.png](images/main1-small.png)
5 4
 ![main2.png](images/main2-small.png)
6 5
 ![main3.png](images/main3-small.png)
6
+
7
+One commonly used programming technique is *recursion*. With this technique, problems are solved by solving similar problems but for smaller cases. We can construct sets of objects or tasks using *recursive rules* and *initial values*. *Recursive functions* are functions that are self-invoking, using smaller sets or elements each time, until reaching a point where an initial value is used instead of self-invoking. In this laboratory experience you will practice the definition and implementation of recursive functions to scramble an image and make it incomprehensible.
8
+
9
+##Objectives:
10
+
11
+1) Define and implement recursive functions.
12
+
13
+2) Practice image processing.
14
+
15
+3) Practice the use of decision and repetition structures.
16
+
17
+##Pre-Lab:
18
+
19
+Before arriving at the laboratory you should have:
20
+
21
+1) Reviewed the concepts related to recursive functions.
22
+
23
+2) Studied the concepts and instructions for the laboratory session.
24
+
25
+3) Have taken the Pre-Lab quiz that can be found in Moodle.
26
+
27
+---
28
+
29
+---
30
+
31
+##Scrambling images digitally
32
+
33
+When scrambling images digitally we reorder the pixels of the image to break the relation between adjacent pixels, making the original image incomprehensible. This technique is used frequently to cypher images and hide data. [1]
34
+
35
+---
36
+
37
+![figure1.png](images/figure1.png)
38
+
39
+**Figure 1.** The image to the left was cyphered using the image scrambling technique to obtain the image on the right. Taken from [2].
40
+
41
+---
42
+
43
+There exist many methods that have been proposed to scramble images. In this laboratory experience you will use a simple method that has a natural implementation with recursive functions.
44
+
45
+### Scramble it!
46
+
47
+The method you will use to scramble the image works by exchanging rectangles of an image a certain number of times, which is established by the *level*. Figure 2 illustrates a *level 1* scramble: the diagonal quadrants are exchanged. Observe Figure 6 as well.
48
+
49
+---
50
+
51
+![figure2.png](images/figure2.png)
52
+
53
+**Figure 2.** Level 1 scramble: (a) is the original image divided in quadrants, (b) is the image after scrambling the first level by exchanging diagonal quadrants.
54
+
55
+---
56
+
57
+The next level scramble, *level 2*, first exchanges the left and right halves of the image. Afterwards the *level 1* scramble is applied to each quadrant. Observe that the level 1 scramble is applied to each of the four quadrants of the original image.
58
+
59
+---
60
+
61
+![figure3.png](images/figure3.png)
62
+
63
+**Figure 3.** Level 2 scramble: (a) is the original image, (b) is the image after exchanging the left and right halves, (c) is the image after applying a level 1 scramble to each quadrant.
64
+
65
+---
66
+
67
+**Question:** Which of the following figures (a), (b), (c), (d) represents the result of applying a *level 2* scramble to the following drawing of a penguin?   
68
+
69
+---
70
+
71
+![figure4.png](images/figure4.png)
72
+
73
+
74
+![figure5.png](images/figure5.png)
75
+
76
+---
77
+
78
+If we follow the pattern, a *level 3* scramble starts by exchanging the diagonal quadrants. Afterward, a *level 2* scramble is applied to each quadrant: exchange the left and right halves and apply a *level 1* scramble to each new quadrant. Figure 8 shows the process of applying a level 3 scramble.
79
+
80
+To scramble an image repeat this process for a certain *level N*. What is the pattern? How would a *level 4* scramble start? In how many quadrants will we have divided the original image after completing the scramble?
81
+
82
+The algorithm to scramble that was just described is its own inverse. That is, if you apply the same algorithm to the scrambled image you should obtain the original image.
83
+
84
+
85
+The following figures illustrate the exchanges that are done by level 1, 2 and 3 scrambles. 
86
+
87
+---
88
+
89
+![figure6.png](images/figure6.png)
90
+
91
+**Figure 6.** Level 1 scramble: the diagonal quadrants are exchanged.
92
+
93
+---
94
+
95
+
96
+![figure7.png](images/figure7.png)
97
+
98
+**Figure 7.** Level 2 scramble: (a) the left and right halves are exhanged, (b) a level 1 scramble is applied to each quadrant.
99
+
100
+
101
+---
102
+
103
+![figure8.png](images/figure8.png)
104
+
105
+**Figure 8.** Level 3 scramble: (a) the diagonal quadrants are exchanged to then apply a level 2 scramble to each quadrant, (b) the left and right halves are exchanged in each quadrant, (c)  a level 1 scramble is applied in each new quadrant.
106
+
107
+
108
+---
109
+
110
+---
111
+
112
+## Additional functions provided in the project
113
+
114
+The project which you will be working on today contains the `cropSwap` function that implements the functionality of exchanging the pixels contains in two congruent rectangles within an image. Its prototype is: 
115
+
116
+```
117
+void ImageScrambler::cropSwap(QImage &img, int x0, int y0, int x1, int y1, int width, int height );
118
+```
119
+
120
+Its parameters are:
121
+* `img`: reference to the image that we wish to modify (an object of the `QImage` class)
122
+* `x0`, `y0`,`x0`, `y0`: coordinates of the upper left corners of the rectangles.
123
+* `width`, `height`: width and height (in pixels) of the rectangles.
124
+
125
+For example, if we wish to exchange the pixels of the upper and lower halves of an image *P* with width 100 and height 150, we invoke the function:
126
+
127
+```
128
+cropSwap(P, 0, 0, 0, 75, 100, 75 );  
129
+```
130
+
131
+
132
+----
133
+
134
+----
135
+
136
+## Laboratory Session:
137
+
138
+The project `ImageScrambler` contains the skeleton of an application to scramble and unscramble images. In today’s laboratory experience you will work in the `Filter.cpp` file to complete the application.
139
+
140
+
141
+###Exercise 1: Pseudocode for the scrambling function
142
+
143
+Write the pseudocode to express the scrambling algorithm described above as a recursive function.
144
+
145
+
146
+###Exercise 2: Recursive function to scramble an image
147
+
148
+####Instructions
149
+
150
+1) Load the project `ImageScrambler` onto QtCreator by double-clicking on the `ImageScrambler.pro` file in the `Documents/eip/Recursion-ImageScrambler` directory on your computer. You may also go to `http://bitbucket.org/eip-uprrp/recursion-imagescrambler` to download the `Recursion-ImageScrambler` folder to your computer.
151
+
152
+2) The code that we provide creates the interface in Figure 9.
153
+
154
+---
155
+
156
+![figure9.png](images/figure9.png)
157
+
158
+**Figure 9.** Interface for the `Image Scrambler` project.
159
+
160
+---
161
+
162
+The button that says `Scramble Image` is programmed so it invokes a function called `ScramblerFilter`.
163
+
164
+3. Complete the function `ScrambleFIlter` contained in the `Filter.cpp` file so it implements the recursive algorithm to scramble images. The function has the following format:
165
+
166
+ ```cpp
167
+QImage ImageScrambler::ScrambleFilter(QImage image, int N, int sx, int sy, int width, int height);
168
+```
169
+
170
+4. Download the image in http://i.imgur.com/ZiJ61Gk.png so you can validate the function you implemented.
171
+
172
+---
173
+
174
+---
175
+
176
+## Deliverables
177
+
178
+1. Use “Deliverables 1” in Moodle to upload the file with the pseudocode for the recursive function.
179
+
180
+2. Use "Deliverables 2" in Moodle to upload the `Filter.cpp` file that contains the functions you implemented in this laboratory experience. Remember to use good programming techniques, include the names of the programmers involved, and to document your program.
181
+
182
+
183
+---
184
+
185
+---
186
+
187
+##References
188
+
189
+[1]  F. Maleki et al., ‘‘An Image Encryption System by
190
+Cellular Automata with Memory,’’ Proc. 3rd Int’l
191
+Conf. Availability, Reliability, and Security, IEEE CS
192
+Press, 2008, pp. 12661271.
193
+
194
+[2] Dalhoum, Abdel Latif Abu, et al. "Digital Image Scrambling Using 2 D Cellular Automata." IEEE MultiMedia 19.4 (2012): 28-36.
195
+
196
+[3] http://www.instructables.com/id/Python-Programming-recursion/
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+