Skip to content

Commit f2e98ae

Browse files
author
Lopes
committed
Applying pre-commit on the files
1 parent 287970c commit f2e98ae

File tree

2 files changed

+40
-56
lines changed

2 files changed

+40
-56
lines changed

25_libraries_image_classification.ipynb

Lines changed: 33 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -523,16 +523,9 @@
523523
"%%ipytest\n",
524524
"\n",
525525
"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"
536529
]
537530
},
538531
{
@@ -567,8 +560,9 @@
567560
"source": [
568561
"%%ipytest\n",
569562
"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"
572566
]
573567
},
574568
{
@@ -603,7 +597,9 @@
603597
"source": [
604598
"%%ipytest\n",
605599
"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"
607603
]
608604
},
609605
{
@@ -638,7 +634,9 @@
638634
"source": [
639635
"%%ipytest\n",
640636
"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"
642640
]
643641
},
644642
{
@@ -673,22 +671,9 @@
673671
"source": [
674672
"%%ipytest\n",
675673
"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"
692677
]
693678
},
694679
{
@@ -736,7 +721,9 @@
736721
"source": [
737722
"%%ipytest\n",
738723
"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"
740727
]
741728
},
742729
{
@@ -771,7 +758,9 @@
771758
"source": [
772759
"%%ipytest\n",
773760
"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"
775764
]
776765
},
777766
{
@@ -806,7 +795,9 @@
806795
"source": [
807796
"%%ipytest\n",
808797
"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"
810801
]
811802
},
812803
{
@@ -854,7 +845,9 @@
854845
"source": [
855846
"%%ipytest\n",
856847
"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"
858851
]
859852
},
860853
{
@@ -892,7 +885,9 @@
892885
"source": [
893886
"%%ipytest\n",
894887
"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"
896891
]
897892
},
898893
{
@@ -930,20 +925,9 @@
930925
"source": [
931926
"%%ipytest\n",
932927
"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"
947931
]
948932
},
949933
{

tutorial/tests/test_25_libraries_image_classification.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_scale_image(scale_factor, function_to_test):
2626

2727
def reference_crop_image(image, x: int, y: int, width: int, height: int):
2828
x1, x2, y1, y2 = x, x + width, y, y + height
29-
return image[y : y + height, x : x + width]
29+
return image[y1:y2, x1:x2]
3030

3131

3232
@pytest.mark.parametrize(
@@ -64,20 +64,20 @@ def test_vertical_flip_image(function_to_test):
6464
def reference_rotate_image(image, angle: float):
6565
(h, w) = image.shape[:2]
6666
center = (w // 2, h // 2)
67-
M = cv2.getRotationMatrix2D(center, angle, scale=1.0)
67+
mat = cv2.getRotationMatrix2D(center, angle, scale=1.0)
6868

6969
# Compute new bounding dimensions
70-
cos = np.abs(M[0, 0])
71-
sin = np.abs(M[0, 1])
70+
cos = np.abs(mat[0, 0])
71+
sin = np.abs(mat[0, 1])
7272
new_w = int((h * sin) + (w * cos))
7373
new_h = int((h * cos) + (w * sin))
7474

7575
# Adjust rotation matrix for translation
76-
M[0, 2] += (new_w / 2) - center[0]
77-
M[1, 2] += (new_h / 2) - center[1]
76+
mat[0, 2] += (new_w / 2) - center[0]
77+
mat[1, 2] += (new_h / 2) - center[1]
7878

7979
# Perform rotation with expanded canvas
80-
return cv2.warpAffine(image, M, (new_w, new_h))
80+
return cv2.warpAffine(image, mat, (new_w, new_h))
8181

8282

8383
@pytest.mark.parametrize("angle", [5, 10, 20, 30])

0 commit comments

Comments
 (0)