1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
//! Steganalysis functions for analyzing images.
use crateunsigned_int_to_bits;
use ;
use HashMap;
/// Subtract two 24-bit RGB pixels in each one of their channels
///
/// Uses the `Rgb` struct from the image crate to represent the value of each pixel.
/// # Example
/// ```
/// # use image::Rgb;
/// # use pixelveil::image_steganalysis::subtract_pixels;
/// let p1: Rgb<u8> = Rgb([13, 80, 40]); // R, G, B
/// let p2: Rgb<u8> = Rgb([240, 93, 31]); // R, G, B
///
/// let diff = subtract_pixels(&p1, &p2);
///
/// assert_eq!(
/// diff,
/// Rgb::<u8>([227, 13, 9]) // abs(R1 - R2), abs(G1 - G2), abs(B1 - B2)
/// );
/// ```
///
/// # Arguments
/// This function takes in two arguments:
/// * `p1: &Rgb<u8>` — The first pixel.
/// * `p2: &Rgb<u8>` — The second pixel.
///
/// # Panics
/// This function does not panic.
///
/// # Errors
/// This function does not return errors.
///
/// # Returns
/// The returned value of this function is a pixel that represent the difference in each channel between the two pixels.
/// XOR two 24-bit RGB pixels in each one of their channels
///
/// Uses the `Rgb` struct from the image crate to represent the value of each pixel.
/// # Example
/// ```
/// # use image::Rgb;
/// # use pixelveil::image_steganalysis::xor_pixels;
/// let p1: Rgb<u8> = Rgb([0b10110010, 0b11011100, 0b11010001]); // R, G, B
/// let p2: Rgb<u8> = Rgb([0b00100011, 0b01110001, 0b11110001]); // R, G, B
///
/// let xored = xor_pixels(&p1, &p2);
///
/// assert_eq!(
/// xored,
/// Rgb::<u8>([0b10010001, 0b10101101, 0b00100000]) // R1 ^ R2, G1 ^ G2, B1 ^ B2
/// );
/// ```
///
/// # Arguments
/// This function takes in two arguments:
/// * `p1: &Rgb<u8>` — The first pixel.
/// * `p2: &Rgb<u8>` — The second pixel.
///
/// # Panics
/// This function does not panic.
///
/// # Errors
/// This function does not return errors.
///
/// # Returns
/// The returned value of this function is a pixel that is the two passed in pixels, XORed with each other.
/// Subtracts two 24-bit RGB images from one another
///
/// Applies the `subtract_pixels` function to each pair of pixels at the same x,y and records the result in a new image
/// of the same dimensions.
///
/// # Example
/// ```no_run
/// # use image::RgbImage;
/// # use pixelveil::image_steganalysis::subtract_images;
/// let img1 = RgbImage::new(500, 500);
/// let img2 = RgbImage::new(500, 500);
///
/// let diff = subtract_images(&img1, &img2);
/// ```
///
/// # Arguments
/// This function takes in two arguments:
/// * `image1: &RgbImage` — The first image.
/// * `image2: &RgbImage` — The second image.
///
/// # Panics
/// This function panics if the two images aren't of the same dimensions.
///
/// # Errors
/// This function does not return errors.
///
/// # Returns
/// This function returns an image that every pixel at x,y is the result of applying `subtract_pixels` to the
/// corresponding pixels in the two images.
/// XOR two 24-bit RGB images
///
/// Applies the `xor_pixels` function to each pair of pixels at the same x,y and records the result in a new image
/// of the same dimensions.
///
/// # Example
/// ```no_run
/// # use image::RgbImage;
/// # use pixelveil::image_steganalysis::xor_images;
/// let img1 = RgbImage::new(500, 500);
/// let img2 = RgbImage::new(500, 500);
///
/// let diff = xor_images(&img1, &img2);
/// ```
///
/// # Arguments
/// This function takes in two arguments:
/// * `image1: &RgbImage` — The first image.
/// * `image2: &RgbImage` — The second image.
///
/// # Panics
/// This function panics if the two images aren't of the same dimensions.
///
/// # Errors
/// This function does not return errors.
///
/// # Returns
/// This function returns an image that every pixel at x,y is the result of applying `xor_pixels` to the
/// corresponding pixels in the two images.
/// Highlight each different channel in each pixel between two 24-bit RGB images
///
/// Uses the `subtract_images` function to calculate the exact difference between two images. Then, sets every non-zero
/// value to 255.
///
/// # Example
/// ```no_run
/// # use image::RgbImage;
/// # use pixelveil::image_steganalysis::highlight_image_difference;
/// let img1 = RgbImage::new(500, 500);
/// let img2 = RgbImage::new(500, 500);
///
/// let diff = highlight_image_difference(&img1, &img2);
/// ```
///
/// # Arguments
/// This function takes in two arguments:
/// * `image1: &RgbImage` — The first image.
/// * `image2: &RgbImage` — The second image.
///
/// # Panics
/// This function panics if the two images aren't of the same dimensions.
///
/// # Errors
/// This function does not return errors.
///
/// # Returns
/// This function returns an image that for each different channel in a pixel between the two images, the value of that
/// channel is 255.
/// Slices a 24-bit RGB image into 24 bit planes that represent each bit plane of the image as defined [here](https://en.wikipedia.org/wiki/Bit_plane)
///
/// # Example
/// ```no_run
/// # use image::RgbImage;
/// # use pixelveil::image_steganalysis::slice_image_bit_planes;
/// let img = RgbImage::new(500, 500);
///
/// let bit_planes = slice_image_bit_planes(&img);
///
/// let green_4 = bit_planes.get(&(1, 4)).unwrap(); // green channel at 4th bit index (5th bit from the left — 2^3 significance)
/// let red_7 = bit_planes.get(&(0, 7)).unwrap(); // red channel at 7th bit index (last bit — 2^0 significance)
/// let blue_0 = bit_planes.get(&(2, 0)).unwrap(); // blue channel at 0th bit index (first bit — 2^7 significance)
/// ```
///
/// # Arguments
/// This function takes in one argument:
/// * `img: &RgbImage` — The first image.
///
/// # Panics
/// This function does not panic.
///
/// # Errors
/// This function does not return errors.
///
/// # Returns
/// This function returns a `HashMap<(u8, u8), GrayImage>`.
/// Where:
/// * Each key is a tuple of the channel index (R,G,B = 0,1,2) and the bit index of a bit plane.
/// * Each value is the bit plane that corresponds to the matching key.
///
/// # Notes
/// The bit indices are ordered from left to right. This means that the most significant bit is at index 0, and the
/// least significant one is at index 7.
/// It's safe to call unwrap on the .get() function of the HashMap as long as the key has a valid channel and bit
/// index. All valid bit plane keys are guaranteed to have a value in the HashMap