|
166 | 166 | },
|
167 | 167 | {
|
168 | 168 | "cell_type": "code",
|
169 |
| - "execution_count": 8, |
| 169 | + "execution_count": 1, |
170 | 170 | "metadata": {},
|
171 | 171 | "outputs": [],
|
172 | 172 | "source": [
|
|
310 | 310 | "cell_type": "markdown",
|
311 | 311 | "metadata": {},
|
312 | 312 | "source": [
|
313 |
| - "These next two functions are really neat, since these are image editing techniques which feature in production image editing software (and apps like Instagram and the iPhone Photos app)!\n", |
| 313 | + "These next two functions - `brightness` and `contrast` - are really neat, since these are image editing techniques which feature in production image editing software (and apps like Instagram and the iPhone Photos app)!\n", |
314 | 314 | "\n",
|
315 | 315 | "`brightness`: the first thing that you'll note about this function is that, in addition to a NumPy array\n",
|
316 | 316 | "representing an image, it takes in a factor. Scale the brightness of the image by multiplying every element\n",
|
|
336 | 336 | "save_image(brightness(img, 1.5), \"cs41img_bright.png\")"
|
337 | 337 | ]
|
338 | 338 | },
|
| 339 | + { |
| 340 | + "cell_type": "markdown", |
| 341 | + "metadata": {}, |
| 342 | + "source": [ |
| 343 | + "`brightness_PIL`: it turns out that for many image processing tasks, like this one, NumPy isn't necessarily the best way to go. You'll recall that your implementation of `brightness` likely took a few minutes to run. Can we use Python's image processing libraries to speed up the computation time and make our code even more pythonic?\n", |
| 344 | + "\n", |
| 345 | + "Take a moment and check out the `Image.point()` function included with `PIL`. It takes in a lambda (which takes in one argument), then applies that lambda to each point (R, G, B value) in the image. So now that we've implemented our solution to `brightness` above, how might we implement `brightness_PIL`, which makes use of this functionality from `PIL` in order to achieve the same effect?" |
| 346 | + ] |
| 347 | + }, |
| 348 | + { |
| 349 | + "cell_type": "code", |
| 350 | + "execution_count": 8, |
| 351 | + "metadata": {}, |
| 352 | + "outputs": [], |
| 353 | + "source": [ |
| 354 | + "\n", |
| 355 | + "def brightness_PIL(img, factor):\n", |
| 356 | + " # Implement your function here\n", |
| 357 | + " return img\n", |
| 358 | + "\n", |
| 359 | + "img = brightness_PIL(Image.open(\"cs41img.png\"), 1.5)\n", |
| 360 | + "img.save(\"cs41img_bright_PIL.png\")\n" |
| 361 | + ] |
| 362 | + }, |
339 | 363 | {
|
340 | 364 | "attachments": {
|
341 | 365 | "SOLcs41img_contrast.png": {
|
|
522 | 546 | "name": "python",
|
523 | 547 | "nbconvert_exporter": "python",
|
524 | 548 | "pygments_lexer": "ipython3",
|
525 |
| - "version": "3.7.4" |
| 549 | + "version": "3.8.0" |
526 | 550 | }
|
527 | 551 | },
|
528 | 552 | "nbformat": 4,
|
|
0 commit comments