|
523 | 523 | "%%ipytest\n", |
524 | 524 | "\n", |
525 | 525 | "def solution_scale_image(img, scale_factor: float):\n", |
526 | | - " # Get the current dimensions\n", |
527 | | - " height, width = img.shape[:2]\n", |
528 | | - "\n", |
529 | | - " # Calculate the new dimensions\n", |
530 | | - " new_width = int(width * scale_factor)\n", |
531 | | - " new_height = int(height * scale_factor)\n", |
532 | | - " new_size = (new_width, new_height)\n", |
533 | | - "\n", |
534 | | - " # Resize the image\n", |
535 | | - " return cv2.resize(img, new_size)" |
| 526 | + " # Start your code here\n", |
| 527 | + " return\n", |
| 528 | + " # End your code here" |
536 | 529 | ] |
537 | 530 | }, |
538 | 531 | { |
|
567 | 560 | "source": [ |
568 | 561 | "%%ipytest\n", |
569 | 562 | "def solution_crop_image(img, x: int, y: int, width: int, height: int):\n", |
570 | | - " x1, x2, y1, y2 = x, x+width, y, y+height\n", |
571 | | - " return img[y:y + height, x:x + width]" |
| 563 | + " # Start your code here\n", |
| 564 | + " return\n", |
| 565 | + " # End your code here" |
572 | 566 | ] |
573 | 567 | }, |
574 | 568 | { |
|
603 | 597 | "source": [ |
604 | 598 | "%%ipytest\n", |
605 | 599 | "def solution_horizontal_flip_image(img):\n", |
606 | | - " return cv2.flip(img, 1)" |
| 600 | + " # Start your code here\n", |
| 601 | + " return\n", |
| 602 | + " # End your code here" |
607 | 603 | ] |
608 | 604 | }, |
609 | 605 | { |
|
638 | 634 | "source": [ |
639 | 635 | "%%ipytest\n", |
640 | 636 | "def solution_vertical_flip_image(img):\n", |
641 | | - " return cv2.flip(img, 0)" |
| 637 | + " # Start your code here\n", |
| 638 | + " return\n", |
| 639 | + " # End your code here" |
642 | 640 | ] |
643 | 641 | }, |
644 | 642 | { |
|
673 | 671 | "source": [ |
674 | 672 | "%%ipytest\n", |
675 | 673 | "def solution_rotate_image(img, angle: float):\n", |
676 | | - " (h, w) = img.shape[:2]\n", |
677 | | - " center = (w // 2, h // 2)\n", |
678 | | - " M = cv2.getRotationMatrix2D(center, angle, scale=1.0)\n", |
679 | | - " \n", |
680 | | - " # Compute new bounding dimensions\n", |
681 | | - " cos = np.abs(M[0, 0])\n", |
682 | | - " sin = np.abs(M[0, 1])\n", |
683 | | - " new_w = int((h * sin) + (w * cos))\n", |
684 | | - " new_h = int((h * cos) + (w * sin))\n", |
685 | | - "\n", |
686 | | - " # Adjust rotation matrix for translation\n", |
687 | | - " M[0, 2] += (new_w / 2) - center[0]\n", |
688 | | - " M[1, 2] += (new_h / 2) - center[1]\n", |
689 | | - "\n", |
690 | | - " # Perform rotation with expanded canvas\n", |
691 | | - " return cv2.warpAffine(img, M, (new_w, new_h))" |
| 674 | + " # Start your code here\n", |
| 675 | + " return\n", |
| 676 | + " # End your code here" |
692 | 677 | ] |
693 | 678 | }, |
694 | 679 | { |
|
736 | 721 | "source": [ |
737 | 722 | "%%ipytest\n", |
738 | 723 | "def solution_average_filter(img, kernel_size = (5, 5)):\n", |
739 | | - " return cv2.blur(img, kernel_size)" |
| 724 | + " # Start your code here\n", |
| 725 | + " return\n", |
| 726 | + " # End your code here" |
740 | 727 | ] |
741 | 728 | }, |
742 | 729 | { |
|
771 | 758 | "source": [ |
772 | 759 | "%%ipytest\n", |
773 | 760 | "def solution_median_filter(img, ksize):\n", |
774 | | - " return cv2.medianBlur(img, ksize)" |
| 761 | + " # Start your code here\n", |
| 762 | + " return\n", |
| 763 | + " # End your code here" |
775 | 764 | ] |
776 | 765 | }, |
777 | 766 | { |
|
806 | 795 | "source": [ |
807 | 796 | "%%ipytest\n", |
808 | 797 | "def solution_gaussian_filter(img, kernel_size = (5, 5), sigma = 0):\n", |
809 | | - " return cv2.GaussianBlur(img, kernel_size, sigma)" |
| 798 | + " # Start your code here\n", |
| 799 | + " return\n", |
| 800 | + " # End your code here" |
810 | 801 | ] |
811 | 802 | }, |
812 | 803 | { |
|
854 | 845 | "source": [ |
855 | 846 | "%%ipytest\n", |
856 | 847 | "def solution_adjust_brightness(img, brightness_value):\n", |
857 | | - " return cv2.convertScaleAbs(img, beta=brightness_value)" |
| 848 | + " # Start your code here\n", |
| 849 | + " return\n", |
| 850 | + " # End your code here" |
858 | 851 | ] |
859 | 852 | }, |
860 | 853 | { |
|
892 | 885 | "source": [ |
893 | 886 | "%%ipytest\n", |
894 | 887 | "def solution_adjust_contrast(img, contrast_value):\n", |
895 | | - " return cv2.convertScaleAbs(img, alpha = contrast_value)" |
| 888 | + " # Start your code here\n", |
| 889 | + " return\n", |
| 890 | + " # End your code here" |
896 | 891 | ] |
897 | 892 | }, |
898 | 893 | { |
|
930 | 925 | "source": [ |
931 | 926 | "%%ipytest\n", |
932 | 927 | "def solution_adjust_saturation(img, saturation_factor):\n", |
933 | | - " # Convert the image from BGR to HSV\n", |
934 | | - " image_hsv = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)\n", |
935 | | - "\n", |
936 | | - " # Split the HSV image into Hue, Saturation, and Value channels\n", |
937 | | - " hue, saturation, value = cv2.split(image_hsv)\n", |
938 | | - "\n", |
939 | | - " # Adjust the saturation channel (Ensure it stays within valid range)\n", |
940 | | - " saturation = np.clip(saturation * saturation_factor, 0, 255)\n", |
941 | | - "\n", |
942 | | - " # Merge the channels back\n", |
943 | | - " image_hsv_adjusted = cv2.merge([hue, saturation.astype(np.uint8), value])\n", |
944 | | - "\n", |
945 | | - " # Convert the adjusted image back to BGR\n", |
946 | | - " return cv2.cvtColor(image_hsv_adjusted, cv2.COLOR_HSV2RGB)" |
| 928 | + " # Start your code here\n", |
| 929 | + " return\n", |
| 930 | + " # End your code here" |
947 | 931 | ] |
948 | 932 | }, |
949 | 933 | { |
|
0 commit comments