|
227 | 227 | "source": [
|
228 | 228 | "\n",
|
229 | 229 | "def crop_img(img):\n",
|
230 |
| - "\timg = img[250:800, 100:450, :]\n", |
231 |
| - "\treturn img\n", |
| 230 | + " # Implement your function here\n", |
| 231 | + " return img\n", |
232 | 232 | "\n",
|
233 | 233 | "img = load_image(\"cs41img.png\").copy()\n",
|
234 | 234 | "save_image(crop_img(img), \"cs41img_cropped.png\")"
|
|
261 | 261 | "outputs": [],
|
262 | 262 | "source": [
|
263 | 263 | "def green_img(img):\n",
|
264 |
| - "\timg = img[:, :, 1]\n", |
265 |
| - "\tzeros = np.zeros(img.shape)\n", |
266 |
| - "\timg = np.stack((zeros, img, zeros), axis=2)\n", |
| 264 | + " # Implement your function here\n", |
267 | 265 | "\treturn img\n",
|
268 | 266 | "\n",
|
269 | 267 | "img = load_image(\"cs41img.png\").copy()\n",
|
|
296 | 294 | "source": [
|
297 | 295 | "\n",
|
298 | 296 | "def third_third_third(img):\n",
|
299 |
| - "\tred = img[:int(img.shape[0]/3), :, 0]\n", |
300 |
| - "\tgreen = img[int(img.shape[0]/3):int(2*img.shape[0]/3), :, 1]\n", |
301 |
| - "\tblue = img[int(2*img.shape[0]/3):, :, 2]\n", |
302 |
| - "\n", |
303 |
| - "\tred = np.stack((red, np.zeros(red.shape), np.zeros(red.shape)), axis=2)\n", |
304 |
| - "\tgreen = np.stack((np.zeros(green.shape), np.zeros(green.shape), green), axis=2)\n", |
305 |
| - "\tblue = np.stack((np.zeros(blue.shape), blue, np.zeros(blue.shape)), axis=2)\n", |
306 |
| - "\n", |
307 |
| - "\treturn np.concatenate((red, green, blue), axis=0)\n", |
| 297 | + " # Implement your function here\n", |
| 298 | + " return img\n", |
308 | 299 | "\n",
|
309 | 300 | "img = load_image(\"cs41img.png\").copy()\n",
|
310 | 301 | "save_image(third_third_third(img), \"cs41img_third.png\")"
|
|
338 | 329 | "source": [
|
339 | 330 | "\n",
|
340 | 331 | "def brightness(img, factor):\n",
|
341 |
| - "\tfor row in range(img.shape[0]):\n", |
342 |
| - "\t\tfor col in range(img.shape[1]):\n", |
343 |
| - "\t\t\tfor color in range(img.shape[2]):\n", |
344 |
| - "\t\t\t\timg[row, col, color] = min(img[row, col, color]*factor, 255)\n", |
| 332 | + " # Implement your function here\n", |
345 | 333 | "\treturn img\n",
|
346 | 334 | "\n",
|
347 | 335 | "img = load_image(\"cs41img.png\").copy()\n",
|
|
369 | 357 | "outputs": [],
|
370 | 358 | "source": [
|
371 | 359 | "def contrast(img, factor):\n",
|
372 |
| - "\tfor row in range(img.shape[0]):\n", |
373 |
| - "\t\tfor col in range(img.shape[1]):\n", |
374 |
| - "\t\t\tfor color in range(img.shape[2]):\n", |
375 |
| - "\t\t\t\tif img[row, col, color] < 128:\n", |
376 |
| - "\t\t\t\t\timg[row, col, color] = img[row, col, color]/factor\n", |
377 |
| - "\t\t\t\telse:\n", |
378 |
| - "\t\t\t\t\timg[row, col, color] = min(img[row, col, color]*factor, 255)\n", |
379 |
| - "\n", |
| 360 | + " # Implement your function here\n", |
380 | 361 | "\treturn img\n",
|
381 | 362 | "\n",
|
382 | 363 | "img = load_image(\"cs41img.png\").copy()\n",
|
|
418 | 399 | "outputs": [],
|
419 | 400 | "source": [
|
420 | 401 | "def reconstruct(img1, img2, img3):\n",
|
421 |
| - " reconstructed_img = np.zeros(img1.shape)\n", |
422 |
| - " for row in range(img1.shape[0]):\n", |
423 |
| - " for col in range(img1.shape[1]):\n", |
424 |
| - " for color in range(img1.shape[2]):\n", |
425 |
| - " pixel_choices = np.asarray([img1[row, col, color], img2[row, col, color], img3[row, col, color]])\n", |
426 |
| - " reconstructed_img[row, col, color] = np.argmax(np.bincount(pixel_choices))\n", |
427 |
| - "\n", |
| 402 | + " # Implement your function here\n", |
428 | 403 | " return reconstructed_img\n",
|
429 | 404 | "\n",
|
430 | 405 | "img1 = load_image(\"SOLcs41img_unicorn1.png\").copy()\n",
|
|
547 | 522 | "name": "python",
|
548 | 523 | "nbconvert_exporter": "python",
|
549 | 524 | "pygments_lexer": "ipython3",
|
550 |
| - "version": "3.8.0" |
| 525 | + "version": "3.7.4" |
551 | 526 | }
|
552 | 527 | },
|
553 | 528 | "nbformat": 4,
|
|
0 commit comments