|
@@ -1,14 +1,14 @@
|
1
|
|
-#Recursion - Image Scrambler
|
|
1
|
+# Recursion - Image Scrambler
|
2
|
2
|
|
3
|
3
|
![main1.png](images/main1-small.png)
|
4
|
4
|
![main2.png](images/main2-small.png)
|
5
|
5
|
![main3.png](images/main3-small.png)
|
6
|
6
|
|
7
|
|
-[Verano 2016 - Rafa - Ive]
|
|
7
|
+[Verano 2016 - Coralys]
|
8
|
8
|
|
9
|
|
-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.
|
|
9
|
+One commonly used programming technique is *recursion*. With this technique, problems are solved by solving similar problems, but for smaller cases. We can build 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 the 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.
|
10
|
10
|
|
11
|
|
-##Objectives:
|
|
11
|
+## Objectives:
|
12
|
12
|
|
13
|
13
|
1. Define and implement recursive functions.
|
14
|
14
|
|
|
@@ -16,7 +16,7 @@ One commonly used programming technique is *recursion*. With this technique, pro
|
16
|
16
|
|
17
|
17
|
3. Practice the use of decision and repetition structures.
|
18
|
18
|
|
19
|
|
-##Pre-Lab:
|
|
19
|
+## Pre-Lab:
|
20
|
20
|
|
21
|
21
|
Before arriving at the laboratory you should have:
|
22
|
22
|
|
|
@@ -30,7 +30,7 @@ Before arriving at the laboratory you should have:
|
30
|
30
|
|
31
|
31
|
---
|
32
|
32
|
|
33
|
|
-##Scrambling images digitally
|
|
33
|
+## Scrambling images digitally
|
34
|
34
|
|
35
|
35
|
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]
|
36
|
36
|
|
|
@@ -42,7 +42,7 @@ When scrambling images digitally we reorder the pixels of the image to break the
|
42
|
42
|
|
43
|
43
|
---
|
44
|
44
|
|
45
|
|
-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.
|
|
45
|
+There are 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.
|
46
|
46
|
|
47
|
47
|
### Scramble it!
|
48
|
48
|
|
|
@@ -52,11 +52,11 @@ The method you will use to scramble the image works by exchanging rectangles of
|
52
|
52
|
|
53
|
53
|
![figure2.png](images/figure2.png)
|
54
|
54
|
|
55
|
|
-**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.
|
|
55
|
+**Figure 2.** Level 1 scramble: (a) is the original image divided in quadrants, (b) is the image after scrambling it the first level by exchanging diagonal quadrants.
|
56
|
56
|
|
57
|
57
|
---
|
58
|
58
|
|
59
|
|
-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.
|
|
59
|
+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.
|
60
|
60
|
|
61
|
61
|
---
|
62
|
62
|
|
|
@@ -81,7 +81,7 @@ If we follow the pattern, a *level 3* scramble starts by exchanging the diagonal
|
81
|
81
|
|
82
|
82
|
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?
|
83
|
83
|
|
84
|
|
-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.
|
|
84
|
+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.
|
85
|
85
|
|
86
|
86
|
|
87
|
87
|
The following figures illustrate the exchanges that are done by level 1, 2 and 3 scrambles.
|
|
@@ -97,7 +97,7 @@ The following figures illustrate the exchanges that are done by level 1, 2 and 3
|
97
|
97
|
|
98
|
98
|
![figure7.png](images/figure7.png)
|
99
|
99
|
|
100
|
|
-**Figure 7.** Level 2 scramble: (a) the left and right halves are exhanged, (b) a level 1 scramble is applied to each quadrant.
|
|
100
|
+**Figure 7.** Level 2 scramble: (a) the left and right halves are exchanged, (b) a level 1 scramble is applied to each quadrant.
|
101
|
101
|
|
102
|
102
|
|
103
|
103
|
---
|
|
@@ -134,7 +134,7 @@ The project which you will be working on today contains the `cropSwap` function
|
134
|
134
|
|
135
|
135
|
Its parameters are:
|
136
|
136
|
* `img`: reference to the image that we wish to modify (an object of the `QImage` class)
|
137
|
|
-* `x0`, `y0`,`x0`, `y0`: coordinates of the upper left corners of the rectangles.
|
|
137
|
+* `x0`, `y0`,`x1`, `y1`: coordinates of the upper left corners of the rectangles.
|
138
|
138
|
* `width`, `height`: width and height (in pixels) of the rectangles.
|
139
|
139
|
|
140
|
140
|
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:
|
|
@@ -151,19 +151,20 @@ For example, if we wish to exchange the pixels of the upper and lower halves of
|
151
|
151
|
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.
|
152
|
152
|
|
153
|
153
|
|
154
|
|
-###Exercise 1: Pseudocode for the scrambling function
|
|
154
|
+### Exercise 1: Pseudocode for the scrambling function
|
155
|
155
|
|
156
|
156
|
Write the pseudocode to express the scrambling algorithm described above as a recursive function.
|
157
|
157
|
|
158
|
158
|
|
159
|
|
-###Exercise 2: Recursive function to scramble an image
|
|
159
|
+### Exercise 2: Recursive function to scramble an image
|
160
|
160
|
|
161
|
|
-####Instructions
|
|
161
|
+**Instructions**
|
162
|
162
|
|
163
|
163
|
1. Load the project `ImageScrambler` into `QtCreator`. There are two ways to do this:
|
164
|
164
|
|
165
|
|
- * Using the virtual machine: Double click the file `ImageScrambler.pro` located in the folder `/home/eip/labs/recursion-imagescrambler` of your virtual machine.
|
166
|
|
- * Downloading the project’s folder from `Bitbucket`: Use a terminal and write the command `git clone http:/bitbucket.org/eip-uprrp/recursion-imagescrambler` to download the folder `recursion-imagescrambler` from `Bitbucket`. Double click the file `ImageScrambler.pro` located in the folder that you downloaded to your computer.
|
|
165
|
+ * Using the virtual machine: Double click the file `ImageScrambler.pro` that can be found in the folder `/home/eip/labs/recursion-imagescrambler` of your virtual machine.
|
|
166
|
+
|
|
167
|
+ * Downloading the project’s folder from `Bitbucket`: Use the terminal found in your virtual machine and write the `git clone http:/bitbucket.org/eip-uprrp/recursion-imagescrambler` command to download the folder `recursion-imagescrambler` from `Bitbucket`. Double click the file `ImageScrambler.pro` located in the folder that you downloaded to your computer.
|
167
|
168
|
|
168
|
169
|
2. The code that we provide creates the interface in Figure 9.
|
169
|
170
|
|
|
@@ -191,14 +192,14 @@ Write the pseudocode to express the scrambling algorithm described above as a re
|
191
|
192
|
|
192
|
193
|
1. Use “Deliverable 1” in Moodle to upload the file with the pseudocode for the recursive function.
|
193
|
194
|
|
194
|
|
-2. Use "Deliverable 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.
|
|
195
|
+2. Use "Deliverable 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, by including the names of the programmers involved, and documenting your program.
|
195
|
196
|
|
196
|
197
|
|
197
|
198
|
---
|
198
|
199
|
|
199
|
200
|
---
|
200
|
201
|
|
201
|
|
-##References
|
|
202
|
+## References
|
202
|
203
|
|
203
|
204
|
[1] F. Maleki et al., ‘‘An Image Encryption System by
|
204
|
205
|
Cellular Automata with Memory,’’ Proc. 3rd Int’l
|