summary refs log tree commit diff stats
path: root/opencv/code/a7.py
diff options
context:
space:
mode:
authorSudipto Mallick <smlckz@termux-alpine>2024-02-10 12:49:55 +0000
committerSudipto Mallick <smlckz@termux-alpine>2024-02-10 12:49:55 +0000
commit4182a108a01df3aa28009716472f0ef291704866 (patch)
tree8fabeb2d6ddff80b930c02b3d535b5447bbd41dc /opencv/code/a7.py
parent02884d29e4f5aea71364a203dcaecd53600d8aa4 (diff)
downloadzadania-4182a108a01df3aa28009716472f0ef291704866.tar.gz
Complete DIP assignments main
Diffstat (limited to 'opencv/code/a7.py')
-rw-r--r--opencv/code/a7.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/opencv/code/a7.py b/opencv/code/a7.py
new file mode 100644
index 0000000..d9fbb0c
--- /dev/null
+++ b/opencv/code/a7.py
@@ -0,0 +1,26 @@
+import cv2
+import numpy as np
+
+image = cv2.imread("4i.jpg", cv2.IMREAD_GRAYSCALE)
+
+# a) Brightness enhancement
+brightness_enhanced = cv2.add(image, 50)
+cv2.imwrite("7.a.jpg", brightness_enhanced)
+
+# b) Brightness suppression
+brightness_suppressed = cv2.subtract(image, 50)
+cv2.imwrite("7.b.jpg", brightness_suppressed)
+
+# c) Contrast manipulation
+alpha = 1.5
+contrast_adjusted = cv2.multiply(image, alpha)
+cv2.imwrite("7.c.jpg", contrast_adjusted)
+
+# d) Gray level slicing without background
+lower_threshold = 100
+upper_threshold = 200
+gray_level_sliced = np.copy(image)
+gray_level_sliced[
+    (gray_level_sliced >= lower_threshold) & (gray_level_sliced <= upper_threshold)
+] = 255
+cv2.imwrite("7.d.jpg", gray_level_sliced)