From 4182a108a01df3aa28009716472f0ef291704866 Mon Sep 17 00:00:00 2001 From: Sudipto Mallick Date: Sat, 10 Feb 2024 12:49:55 +0000 Subject: Complete DIP assignments --- opencv/body.typ | 308 ++++++ opencv/buildall | 4 + opencv/code/a1.py | 29 + opencv/code/a10.py | 39 + opencv/code/a11.py | 29 + opencv/code/a12.py | 26 + opencv/code/a13.py | 9 + opencv/code/a14.py | 53 + opencv/code/a2.py | 26 + opencv/code/a3.py | 14 + opencv/code/a4.py | 17 + opencv/code/a5.py | 42 + opencv/code/a6.py | 43 + opencv/code/a7.py | 26 + opencv/code/a8.py | 10 + opencv/code/a9.py | 10 + opencv/code/align.py | 43 + opencv/contents.typ | 49 + opencv/cover.tpl.typ | 37 + opencv/images/1.1.png | Bin 0 -> 112079 bytes opencv/images/1.2.png | Bin 0 -> 303557 bytes opencv/images/1.3.png | Bin 0 -> 263851 bytes opencv/images/1.4.png | Bin 0 -> 332777 bytes opencv/images/1.5.png | Bin 0 -> 331129 bytes opencv/images/1.6.png | Bin 0 -> 8665 bytes opencv/images/1.7.png | Bin 0 -> 23744 bytes opencv/images/10.svg | 678 +++++++++++++ opencv/images/11.gn.jpg | Bin 0 -> 9577 bytes opencv/images/11.snp.jpg | 0 opencv/images/11.svg | 443 +++++++++ opencv/images/12.max.jpg | Bin 0 -> 113762 bytes opencv/images/12.mean.jpg | Bin 0 -> 85593 bytes opencv/images/12.median.jpg | Bin 0 -> 100633 bytes opencv/images/12.min.jpg | Bin 0 -> 109799 bytes opencv/images/12.svg | 561 +++++++++++ opencv/images/12.weighted_avg.jpg | Bin 0 -> 86753 bytes opencv/images/13.1.jpg | Bin 0 -> 69076 bytes opencv/images/13.2.jpg | Bin 0 -> 73734 bytes opencv/images/13.3.jpg | Bin 0 -> 62062 bytes opencv/images/14.svg | 895 +++++++++++++++++ opencv/images/15.svg | 895 +++++++++++++++++ opencv/images/1i.png | Bin 0 -> 343056 bytes opencv/images/1igr.png | Bin 0 -> 112340 bytes opencv/images/2.(-45.0).png | Bin 0 -> 352089 bytes opencv/images/2.(60.0).png | Bin 0 -> 350483 bytes opencv/images/3.svg | 1115 +++++++++++++++++++++ opencv/images/4.b.jpg | Bin 0 -> 74786 bytes opencv/images/4.g.jpg | Bin 0 -> 131628 bytes opencv/images/4.jpg | Bin 0 -> 96308 bytes opencv/images/4.r.jpg | Bin 0 -> 116801 bytes opencv/images/4i.jpg | Bin 0 -> 96308 bytes opencv/images/4igr.jpg | Bin 0 -> 112548 bytes opencv/images/5.log.jpg | Bin 0 -> 93785 bytes opencv/images/5.negative.jpg | Bin 0 -> 112502 bytes opencv/images/5.piecewise.jpg | Bin 0 -> 179118 bytes opencv/images/5.power_law.jpg | Bin 0 -> 108699 bytes opencv/images/6.jpg | Bin 0 -> 133954 bytes opencv/images/6.svg | 1920 +++++++++++++++++++++++++++++++++++++ opencv/images/7.a.jpg | Bin 0 -> 112406 bytes opencv/images/7.b.jpg | Bin 0 -> 111529 bytes opencv/images/7.c.jpg | Bin 0 -> 128948 bytes opencv/images/7.d.jpg | Bin 0 -> 169400 bytes opencv/images/8o.jpg | Bin 0 -> 105015 bytes opencv/images/9i1.jpg | Bin 0 -> 113762 bytes opencv/images/9i2.jpg | Bin 0 -> 109799 bytes opencv/images/9o.jpg | Bin 0 -> 125820 bytes opencv/images/landscape.png | Bin 1354640 -> 343056 bytes opencv/prelude.typ | 8 + opencv/tpl.typ | 115 ++- opencv/vendor/gr.tmTheme | 566 +++++++++++ 70 files changed, 7982 insertions(+), 28 deletions(-) create mode 100644 opencv/body.typ create mode 100644 opencv/buildall create mode 100644 opencv/code/a1.py create mode 100644 opencv/code/a10.py create mode 100644 opencv/code/a11.py create mode 100644 opencv/code/a12.py create mode 100644 opencv/code/a13.py create mode 100644 opencv/code/a14.py create mode 100644 opencv/code/a2.py create mode 100644 opencv/code/a3.py create mode 100644 opencv/code/a4.py create mode 100644 opencv/code/a5.py create mode 100644 opencv/code/a6.py create mode 100644 opencv/code/a7.py create mode 100644 opencv/code/a8.py create mode 100644 opencv/code/a9.py create mode 100644 opencv/code/align.py create mode 100644 opencv/contents.typ create mode 100644 opencv/cover.tpl.typ create mode 100644 opencv/images/1.1.png create mode 100644 opencv/images/1.2.png create mode 100644 opencv/images/1.3.png create mode 100644 opencv/images/1.4.png create mode 100644 opencv/images/1.5.png create mode 100644 opencv/images/1.6.png create mode 100644 opencv/images/1.7.png create mode 100644 opencv/images/10.svg create mode 100644 opencv/images/11.gn.jpg create mode 100644 opencv/images/11.snp.jpg create mode 100644 opencv/images/11.svg create mode 100644 opencv/images/12.max.jpg create mode 100644 opencv/images/12.mean.jpg create mode 100644 opencv/images/12.median.jpg create mode 100644 opencv/images/12.min.jpg create mode 100644 opencv/images/12.svg create mode 100644 opencv/images/12.weighted_avg.jpg create mode 100644 opencv/images/13.1.jpg create mode 100644 opencv/images/13.2.jpg create mode 100644 opencv/images/13.3.jpg create mode 100644 opencv/images/14.svg create mode 100644 opencv/images/15.svg create mode 100644 opencv/images/1i.png create mode 100644 opencv/images/1igr.png create mode 100644 opencv/images/2.(-45.0).png create mode 100644 opencv/images/2.(60.0).png create mode 100644 opencv/images/3.svg create mode 100644 opencv/images/4.b.jpg create mode 100644 opencv/images/4.g.jpg create mode 100644 opencv/images/4.jpg create mode 100644 opencv/images/4.r.jpg create mode 100644 opencv/images/4i.jpg create mode 100644 opencv/images/4igr.jpg create mode 100644 opencv/images/5.log.jpg create mode 100644 opencv/images/5.negative.jpg create mode 100644 opencv/images/5.piecewise.jpg create mode 100644 opencv/images/5.power_law.jpg create mode 100644 opencv/images/6.jpg create mode 100644 opencv/images/6.svg create mode 100644 opencv/images/7.a.jpg create mode 100644 opencv/images/7.b.jpg create mode 100644 opencv/images/7.c.jpg create mode 100644 opencv/images/7.d.jpg create mode 100644 opencv/images/8o.jpg create mode 100644 opencv/images/9i1.jpg create mode 100644 opencv/images/9i2.jpg create mode 100644 opencv/images/9o.jpg create mode 100644 opencv/prelude.typ create mode 100644 opencv/vendor/gr.tmTheme diff --git a/opencv/body.typ b/opencv/body.typ new file mode 100644 index 0000000..8d78290 --- /dev/null +++ b/opencv/body.typ @@ -0,0 +1,308 @@ +#import "/tpl.typ": * +#show: A => apply(A) +#set raw(lang: "py") +#set par(leading: 0.6em) +#set figure.caption(position: top) +#set figure(supplement: none, numbering: none) + +#assignment(1)[ + Write a program to do image format conversion i.e., from RGB to gray, gray to binary, RGB to binary, RGB to HSV, HSV to RGB, RGB to YCbCr and YCbCr to RGB. +] + +#scos(1)[ + #{ + let list-of-images = (image("/images/1i.png", width: 80%), ) + for i in range(1, 8) { + list-of-images.push(image("/images/1." + str(i) + ".png", width: 80%)) + } + let captions = ("Original Image", [RGB #sym.arrow.r Gray], [Gray #sym.arrow.r Binary], [RGB #sym.arrow.r Binary], [RGB #sym.arrow.r HSV], [HSV #sym.arrow.r RGB], [RGB #sym.arrow.r YCbCr], [YCbCr #sym.arrow.r RGB]) + let figures = () + for i in range(list-of-images.len()) { + figures.push(figure(caption: captions.at(i), list-of-images.at(i))) + } + grid( + columns: 2, + gutter: 1em, + ..figures + ) + } +] + +#signature() +#colbreak() + +#assignment(2)[ + Write a program to read an image and rotate that image in clockwise and anti-clockwise direction, and display it. +] + +#scos(2)[ + #figure(caption: [Original image], image("/images/1i.png", width: 50%)) + #figure(caption: [Rotated 60#sym.degree anti-clockwise], image("/images/2.(60.0).png", width: 50%)) + #figure(caption: [Rotated 45#sym.degree clockwise], image("/images/2.(-45.0).png", width: 60%)) +] + +#signature() +#colbreak() + +#assignment(3)[ + Write a program to find the histogram of a gray image and display the histogram. +] + +#scos(3)[ + #image("/images/3.svg") +] + +#signature() +#colbreak() + +#assignment(4)[ + Write a program to perform color separation into R, G, and B from an color image. +] + +#scos(4)[ + #{ + let filenames = ("4i", "4.r", "4.g", "4.b") + let list-of-images = () + for i in range(filenames.len()) { + list-of-images.push(image("/images/" + filenames.at(i) + ".jpg", width: 80%)) + } + let captions = ("Original Image", "Red Channel", "Green Channel", "Blue Channel") + let figures = () + for i in range(list-of-images.len()) { + figures.push(figure(caption: captions.at(i), list-of-images.at(i))) + } + grid( + columns: 2, + gutter: 1em, + ..figures + ) + } +] + +#signature() +#colbreak() + +#assignment(5)[ + Write a program to enhance the image in spatial domain using + + Image negative + + Log transformation + + Power law transform + + Piecewise linear transform +] + +#scos(5)[ + #{ + let filenames = ("negative", "log", "power_law", "piecewise") + let list-of-images = () + for i in range(filenames.len()) { + list-of-images.push(image("/images/5." + filenames.at(i) + ".jpg", width: 100%)) + } + let captions = ("Image negative", "Log transformation", "Power law transform", "Piecewise linear transform") + let figures = () + for i in range(list-of-images.len()) { + figures.push(figure(caption: captions.at(i), list-of-images.at(i))) + } + grid( + columns: 2, + gutter: 1em, + ..figures + ) + } +] + +#signature() +#colbreak() + +#assignment(6)[ + Write a program to enhance the image in spatial domain using histogram equalization method. +] + +#scos(6)[ + #image("/images/6.svg") +] + +#signature() +#colbreak() + +#assignment(7)[ + Write a program to perform the following image enhancement methods: + + Brightness enhancement + + Brightness suppression + + Contrast manipulation + + Gray level slicing without background +] + +#scos(7)[ + #{ + let filenames = ("a", "b", "c", "d") + let list-of-images = () + for i in range(filenames.len()) { + list-of-images.push(image("/images/7." + filenames.at(i) + ".jpg", width: 70%)) + } + let captions = ( + "Brightness enhancement", + "Brightness suppression", + "Contrast manipulation", + "Gray level slicing without background" + ) + let figures = () + for i in range(list-of-images.len()) { + figures.push(figure(caption: captions.at(i), list-of-images.at(i))) + } + grid( + columns: 2, + gutter: 1em, + ..figures + ) + } +] + +#signature() +#colbreak() + +#assignment(8)[ + Write a program to average two images together into a single image. +] + +#scos(8)[ + #{ + let filenames = ("9i1", "9i2", "8o") + let list-of-images = () + for i in range(filenames.len()) { + list-of-images.push(image("/images/" + filenames.at(i) + ".jpg", width: 70%)) + } + let captions = ( + "Image 1", + "Image 2", + "Average" + ) + let figures = () + for i in range(list-of-images.len()) { + figures.push(figure(caption: captions.at(i), list-of-images.at(i))) + } + grid( + columns: 2, + gutter: 1em, + ..figures + ) + } +] + +#signature() +#colbreak() + +#assignment(9)[ + Write a program to compare two images using image subtraction. +] + +#scos(9)[ + #{ + let filenames = ("9i1", "9i2", "9o") + let list-of-images = () + for i in range(filenames.len()) { + list-of-images.push(image("/images/" + filenames.at(i) + ".jpg", width: 70%)) + } + let captions = ( + "Image 1", + "Image 2", + "Difference" + ) + let figures = () + for i in range(list-of-images.len()) { + figures.push(figure(caption: captions.at(i), list-of-images.at(i))) + } + grid( + columns: 2, + gutter: 1em, + ..figures + ) + } +] + +#signature() +#colbreak() + +#assignment(10)[ + Write a program to perform the following image arithmetic. + + Image addition + + Image subtraction + + Image multiplication + + Image division +] + +#scos(10, cont: true)[ + #image("/images/10.svg") +] + +#signature() +#colbreak() + +#assignment(11)[ + Write a program to add various types of noise (salt and pepper noise, Gaussian noise) to an image. +] + +#scos(11, cont: true)[ + #image("/images/11.svg") +] + +#signature() +#colbreak() + +#assignment(12)[ + Write a program to enhance an image using mean filtering, weighted average filtering, median filtering, max/min filtering. +] + +#scos(12, cont: true)[ + #image("/images/12.svg") +] + +#signature() +#colbreak() + +#assignment(13)[ + Write a program to segment an image using thresolding technique. +] + +#scos(13)[ + #{ + let filenames = ("1igr.png", "13.1.jpg", "13.2.jpg", "13.3.jpg") + let list-of-images = () + for i in range(filenames.len()) { + list-of-images.push(image("/images/" + filenames.at(i), width: 70%)) + } + let captions = ( + "Original Image", + "Segment 1", + "Segment 2", + "Segment 3", + ) + let figures = () + for i in range(list-of-images.len()) { + figures.push(figure(caption: captions.at(i), list-of-images.at(i))) + } + grid( + columns: 2, + gutter: 1em, + ..figures + ) + } +] + +#signature() +#colbreak() + +#assignment(14)[ + Write a program to find the edge of a given image with the following operators. + + Difference operator + + Robert operator + + Prewitt operator + + Sobel operator +] + +#scos(14)[ + #image("/images/14.svg") +] + +#signature() + + diff --git a/opencv/buildall b/opencv/buildall new file mode 100644 index 0000000..9e8d86d --- /dev/null +++ b/opencv/buildall @@ -0,0 +1,4 @@ +#!/bin/sh +cat prelude.typ body.typ > all.typ +typst compile --root $PWD all.typ docs/all.pdf +pdftk docs/all.pdf cat 1 4-5 8-end output docs/ocv-all.pdf diff --git a/opencv/code/a1.py b/opencv/code/a1.py new file mode 100644 index 0000000..1f00db7 --- /dev/null +++ b/opencv/code/a1.py @@ -0,0 +1,29 @@ +import cv2 +import numpy as np +import os + +os.chdir("images") + +image = cv2.imread("1i.png") + +gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY) + +_, graytobin = cv2.threshold(gray, 150, 255, cv2.THRESH_BINARY) + +_, rgbtobin = cv2.threshold(image, 150, 255, cv2.THRESH_BINARY) + +hsv = cv2.cvtColor(image, cv2.COLOR_RGB2HSV) + +hsvtorgb = cv2.cvtColor(hsv, cv2.COLOR_HSV2RGB) + +rcb = cv2.cvtColor(image, cv2.COLOR_BGR2YCR_CB) + +rcbtorgb = cv2.cvtColor(rcb, cv2.COLOR_YCrCb2BGR) + +cv2.imwrite("1.1.png", gray) +cv2.imwrite("1.2.png", hsv) +cv2.imwrite("1.3.png", rcb) +cv2.imwrite("1.4.png", hsvtorgb) +cv2.imwrite("1.5.png", rcbtorgb) +cv2.imwrite("1.6.png", graytobin) +cv2.imwrite("1.7.png", rgbtobin) diff --git a/opencv/code/a10.py b/opencv/code/a10.py new file mode 100644 index 0000000..f54a024 --- /dev/null +++ b/opencv/code/a10.py @@ -0,0 +1,39 @@ +import cv2 +import numpy as np +import matplotlib.pyplot as plt + +images = [cv2.imread(path, cv2.IMREAD_GRAYSCALE) for path in ["9i1.jpg", "9i2.jpg"]] +assert all( + image.shape == images[0].shape for image in images +), "Input images must have the same dimensions" + +operations = [ + ("Addition", lambda x, y: cv2.add(x, y)), + ("Subtraction", lambda x, y: cv2.subtract(x, y)), + ("Multiplication", lambda x, y: cv2.multiply(x, y)), + ( + "Division", + lambda x, y: cv2.divide( + x.astype(np.float32), np.where(y == 0, 1, y).astype(np.float32) + ), + ), +] + +plt.figure(figsize=(8, 6)) + +for i, image in enumerate(images, start=1): + plt.subplot(3, 2, i) + plt.imshow(image, cmap="gray") + plt.title(f"Image {i}") + plt.axis("off") + +for i, (operation_name, operation_function) in enumerate( + operations, start=len(images) + 1 +): + result_image = operation_function(*images) + plt.subplot(3, 2, i) + plt.imshow(result_image, cmap="gray") + plt.title(operation_name) + plt.axis("off") + +plt.savefig("10.svg") diff --git a/opencv/code/a11.py b/opencv/code/a11.py new file mode 100644 index 0000000..dc4c436 --- /dev/null +++ b/opencv/code/a11.py @@ -0,0 +1,29 @@ +import cv2 +import numpy as np +import matplotlib.pyplot as plt +from skimage.util import random_noise + +image = cv2.imread("4igr.jpg", cv2.IMREAD_GRAYSCALE) + +# Add salt and pepper noise +salt_pepper_noise = random_noise(image, mode="s&p", amount=0.02) + +# Add Gaussian noise +gaussian_noise = random_noise(image, mode="gaussian", mean=0, var=0.01) + +# Create subplots +plt.figure(figsize=(10, 5)) + +# Salt and pepper noise +plt.subplot(1, 2, 1) +plt.imshow(salt_pepper_noise, cmap="gray") +plt.title("Salt and Pepper Noise") +plt.axis("off") + +# Gaussian noise +plt.subplot(1, 2, 2) +plt.imshow(gaussian_noise, cmap="gray") +plt.title("Gaussian Noise") +plt.axis("off") + +plt.savefig("11.svg") diff --git a/opencv/code/a12.py b/opencv/code/a12.py new file mode 100644 index 0000000..9cf8858 --- /dev/null +++ b/opencv/code/a12.py @@ -0,0 +1,26 @@ +import cv2 +import numpy as np +import matplotlib.pyplot as plt + +input_image = cv2.imread("4i.jpg", cv2.IMREAD_GRAYSCALE) + +kernel_size = 3 + +filters = [ + (input_image, "Original Image"), + (cv2.blur(input_image, (kernel_size, kernel_size)), "Mean Filtered"), + (cv2.GaussianBlur(input_image, (kernel_size, kernel_size), 0), "Weighted Average Filtered"), + (cv2.medianBlur(input_image, kernel_size), "Median Filtered"), + (cv2.dilate(input_image, np.ones((kernel_size, kernel_size), np.uint8)), "Max Filtered"), + (cv2.erode(input_image, np.ones((kernel_size, kernel_size), np.uint8)), "Min Filtered"), +] + +plt.figure(figsize=(12, 10)) + +for i, (filtered_image, title) in enumerate(filters, start=1): + plt.subplot(3, 3, i) + plt.imshow(filtered_image, cmap="gray") + plt.title(title) + plt.axis("off") + +plt.savefig("12.svg") diff --git a/opencv/code/a13.py b/opencv/code/a13.py new file mode 100644 index 0000000..3afdf1a --- /dev/null +++ b/opencv/code/a13.py @@ -0,0 +1,9 @@ +import cv2 + +image = cv2.imread("1i.png", cv2.IMREAD_GRAYSCALE) + +threshold_values = [50, 100, 150] + +for i, threshold in enumerate(threshold_values, start=1): + _, segmented_image = cv2.threshold(image, threshold, 255, cv2.THRESH_BINARY) + cv2.imwrite(f"13.{i}.jpg", segmented_image) diff --git a/opencv/code/a14.py b/opencv/code/a14.py new file mode 100644 index 0000000..ec04f27 --- /dev/null +++ b/opencv/code/a14.py @@ -0,0 +1,53 @@ +from matplotlib import pyplot as plt +import cv2 +import numpy as np + +img = cv2.imread("1i.png", 0) +laplacian = cv2.Laplacian(img, -1, None, 3) + +robert_x_kernel = np.array([[-1, 0], [0, 1]]) +robert_y_kernel = np.array([[0, -1], [1, 0]]) +robert_x = cv2.filter2D(img, -1, robert_x_kernel) +robert_y = cv2.filter2D(img, -1, robert_y_kernel) +robert_combined = cv2.bitwise_or(robert_x, robert_y) + +prewitt_x_kernel = np.array([[-1, -1, -1], [0, 0, 0], [1, 1, 1]]) +prewitt_y_kernel = np.array([[-1, 0, 1], [-1, 0, 1], [-1, 0, 1]]) +prewitt_x = cv2.filter2D(img, -1, prewitt_x_kernel) +prewitt_y = cv2.filter2D(img, -1, prewitt_y_kernel) +prewitt_combined = cv2.bitwise_or(prewitt_x, prewitt_y) + +sx = cv2.Sobel(img, cv2.CV_64F, 1, 0) +sy = cv2.Sobel(img, cv2.CV_64F, 0, 1) +sobel_x = np.uint8(np.absolute(sx)) +sobel_y = np.uint8(np.absolute(sy)) +sobel_combined = cv2.bitwise_or(sobel_x, sobel_y) + +empty = np.zeros(img.shape, dtype=np.uint8) + +data = [ + (img, "Original Image"), + (laplacian, "Laplacian"), + (robert_x, "Robert in x direction"), + (robert_y, "Robert in y direction"), + (robert_combined, "Combined Robert"), + (prewitt_x, "Prewitt in x direction"), + (prewitt_y, "Prewitt in y direction"), + (prewitt_combined, "Combined Prewitt"), + (sobel_x, "Sobel in x direction"), + (sobel_y, "Sobel in y direction"), + (sobel_combined, "Combined Sobel"), + (empty, ""), +] + +fig, axs = plt.subplots(3, 4, figsize=(10, 7)) + +for ax, (image, title) in zip(axs.flat, data): + if image is not img: + image = 255 - image + ax.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB)) + ax.set_title(title, fontsize=10) + ax.axis("off") + +plt.tight_layout() +plt.savefig("14.svg") diff --git a/opencv/code/a2.py b/opencv/code/a2.py new file mode 100644 index 0000000..f0bfc14 --- /dev/null +++ b/opencv/code/a2.py @@ -0,0 +1,26 @@ +import cv2 +import numpy as np + +image = cv2.imread("1i.png") + +angle = float(input("Enter angle in degrees: ")) + +height, width = image.shape[:2] + +rotation_matrix = cv2.getRotationMatrix2D((width / 2, height / 2), angle, 1) + +# Determine the new dimensions of the rotated image +cos_theta = np.abs(rotation_matrix[0, 0]) +sin_theta = np.abs(rotation_matrix[0, 1]) +new_width = int(height * sin_theta + width * cos_theta) +new_height = int(height * cos_theta + width * sin_theta) + +# Adjust the rotation matrix to take into account translation to keep the entire image within bounds +rotation_matrix[0, 2] += (new_width - width) / 2 +rotation_matrix[1, 2] += (new_height - height) / 2 + +rotated_image = cv2.warpAffine(image, rotation_matrix, (new_width, new_height)) + +cv2.imwrite(f"2.({angle}).png", rotated_image) +cv2.waitKey(0) +cv2.destroyAllWindows() diff --git a/opencv/code/a3.py b/opencv/code/a3.py new file mode 100644 index 0000000..5a8ffcd --- /dev/null +++ b/opencv/code/a3.py @@ -0,0 +1,14 @@ +import cv2 +import matplotlib.pyplot as plt + +image = cv2.imread("1i.png", cv2.IMREAD_GRAYSCALE) + +histogram = cv2.calcHist([image], [0], None, [256], [0, 256]) + +plt.figure(figsize=(8, 5)) +plt.plot(histogram, color="black") +plt.title("Grayscale Histogram") +plt.xlabel("Pixel Value") +plt.ylabel("Frequency") +plt.xlim([0, 256]) +plt.savefig("3.svg") diff --git a/opencv/code/a4.py b/opencv/code/a4.py new file mode 100644 index 0000000..dbd14e9 --- /dev/null +++ b/opencv/code/a4.py @@ -0,0 +1,17 @@ +import cv2 +import numpy as np + +image = cv2.imread("4i.jpg") + +blue_channel, green_channel, red_channel = cv2.split(image) + +zeros = np.zeros_like(blue_channel) + +# Merge each channel with zeroes for the other channels +blue_image = cv2.merge([blue_channel, zeros, zeros]) +green_image = cv2.merge([zeros, green_channel, zeros]) +red_image = cv2.merge([zeros, zeros, red_channel]) + +cv2.imwrite("4.b.jpg", blue_image) +cv2.imwrite("4.g.jpg", green_image) +cv2.imwrite("4.r.jpg", red_image) diff --git a/opencv/code/a5.py b/opencv/code/a5.py new file mode 100644 index 0000000..52e56c5 --- /dev/null +++ b/opencv/code/a5.py @@ -0,0 +1,42 @@ +import cv2 +import numpy as np + +image = cv2.imread("4i.jpg", cv2.IMREAD_GRAYSCALE) + +# Image Negative +negative_image = 255 - image +cv2.imwrite("5.negative.jpg", negative_image) + +# Log Transformation +c = 255 / np.log(1 + np.max(image)) +log_transformed = c * np.log1p(1.0 + image) +log_transformed = np.uint8(log_transformed) +cv2.imwrite("5.log.jpg", log_transformed) + +# Power Law Transform +gamma = 0.5 +power_law_transformed = np.power(image, gamma) +power_law_transformed = cv2.normalize( + power_law_transformed, None, 0, 255, cv2.NORM_MINMAX +) +power_law_transformed = np.uint8(power_law_transformed) +cv2.imwrite("5.power_law.jpg", power_law_transformed) + + +# Piecewise Linear Transform +def piecewise_linear(x): + return np.piecewise( + x, + [x < 50, (x >= 50) & (x < 100), (x >= 100) & (x < 150), x >= 150], + [ + lambda x: 0, + lambda x: 255 * ((x - 50) / (100 - 50)), + lambda x: 255, + lambda x: 255 * ((255 - x) / (255 - 150)), + ], + ) + + +piecewise_transformed = piecewise_linear(image) +piecewise_transformed = np.uint8(piecewise_transformed) +cv2.imwrite("5.piecewise.jpg", piecewise_transformed) diff --git a/opencv/code/a6.py b/opencv/code/a6.py new file mode 100644 index 0000000..a72d103 --- /dev/null +++ b/opencv/code/a6.py @@ -0,0 +1,43 @@ +import cv2 +import matplotlib.pyplot as plt + +image = cv2.imread("4i.jpg", cv2.IMREAD_GRAYSCALE) + +# Perform histogram equalization +equalized_image = cv2.equalizeHist(image) + +# Calculate histograms +hist_original = cv2.calcHist([image], [0], None, [256], [0, 256]) +hist_equalized = cv2.calcHist([equalized_image], [0], None, [256], [0, 256]) + +# Plot original and equalized images and their histograms +plt.figure(figsize=(10, 8)) + +# Original image and histogram +plt.subplot(2, 2, 1) +plt.imshow(image, cmap="gray") +plt.title("Original Image") +plt.xticks([]) +plt.yticks([]) + +plt.subplot(2, 2, 2) +plt.plot(hist_original, color="black") +plt.title("Histogram of Original Image") +plt.xlabel("Pixel Value") +plt.ylabel("Frequency") + +# Equalized image and histogram +plt.subplot(2, 2, 3) +plt.imshow(equalized_image, cmap="gray") +plt.title("Equalized Image") +plt.xticks([]) +plt.yticks([]) + +plt.subplot(2, 2, 4) +plt.plot(hist_equalized, color="black") +plt.title("Histogram of Equalized Image") +plt.xlabel("Pixel Value") +plt.ylabel("Frequency") + +plt.tight_layout() +plt.savefig("6.svg") 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) diff --git a/opencv/code/a8.py b/opencv/code/a8.py new file mode 100644 index 0000000..d1cdfb5 --- /dev/null +++ b/opencv/code/a8.py @@ -0,0 +1,10 @@ +import cv2 + +image1 = cv2.imread("9i1.jpg", cv2.IMREAD_GRAYSCALE) +image2 = cv2.imread("9i2.jpg", cv2.IMREAD_GRAYSCALE) + +assert image1.shape == image2.shape, "Input images must have the same dimensions" + +averaged_image = cv2.addWeighted(image1, 0.5, image2, 0.5, 0) + +cv2.imwrite("8o.jpg", averaged_image) diff --git a/opencv/code/a9.py b/opencv/code/a9.py new file mode 100644 index 0000000..fab1a4e --- /dev/null +++ b/opencv/code/a9.py @@ -0,0 +1,10 @@ +import cv2 + +image1 = cv2.imread("9i1.jpg", cv2.IMREAD_GRAYSCALE) +image2 = cv2.imread("9i2.jpg", cv2.IMREAD_GRAYSCALE) + +assert image1.shape == image2.shape, "Input images must have the same dimensions" + +result_image = cv2.subtract(image1, image2) + +cv2.imwrite("9o.jpg", 255 - result_image) diff --git a/opencv/code/align.py b/opencv/code/align.py new file mode 100644 index 0000000..6a340f6 --- /dev/null +++ b/opencv/code/align.py @@ -0,0 +1,43 @@ +import cv2 +import numpy as np + +# Load the two images +image1 = cv2.imread("T1.jpg") +image2 = cv2.imread("T2.jpg") + +# Convert images to grayscale +gray1 = cv2.cvtColor(image1, cv2.COLOR_BGR2GRAY) +gray2 = cv2.cvtColor(image2, cv2.COLOR_BGR2GRAY) + +# Initialize SIFT detector +sift = cv2.SIFT_create() + +# Find keypoints and descriptors +keypoints1, descriptors1 = sift.detectAndCompute(gray1, None) +keypoints2, descriptors2 = sift.detectAndCompute(gray2, None) + +# Initialize keypoint matcher +matcher = cv2.BFMatcher() + +# Match descriptors +matches = matcher.match(descriptors1, descriptors2) + +# Sort matches by distance +matches = sorted(matches, key=lambda x: x.distance) + +# Extract matched keypoints +points1 = np.float32([keypoints1[m.queryIdx].pt for m in matches]) +points2 = np.float32([keypoints2[m.trainIdx].pt for m in matches]) + +# Estimate transformation matrix (homography) using RANSAC +homography, _ = cv2.findHomography(points1, points2, cv2.RANSAC) + +# Warp image1 to align with image2 +aligned_image1 = cv2.warpPerspective( + image1, homography, (image2.shape[1], image2.shape[0]) +) + +# Display and save the aligned image +cv2.imwrite("T1p.jpg", aligned_image1) +cv2.waitKey(0) +cv2.destroyAllWindows() diff --git a/opencv/contents.typ b/opencv/contents.typ new file mode 100644 index 0000000..6f7e302 --- /dev/null +++ b/opencv/contents.typ @@ -0,0 +1,49 @@ +#import "@preview/tablex:0.0.7": tablex, cellx +#import "/tpl.typ": apply, signature, list-of-assignments, apply-page-borders + +#apply(page-numbering: "(i)" , [ + #let heading-format(content) = cellx(align: center + horizon, content) + #let column-alignments = (right, auto, center + horizon, center + horizon, auto) + #let preprocess-alist(assignment-list, last-page-number) = { + let index = 0 + let last-index = assignment-list.len() - 1 + let page-number-list = () + while index < last-index { + let item = assignment-list.at(index) + let next-item = assignment-list.at(index + 1) + let starting-page-number = item.page-number + let finishing-page-number = next-item.page-number - 1 + page-number-list.push((starting-page-number, finishing-page-number)) + index = index + 1 + } + page-number-list.push((assignment-list.at(last-index).page-number, last-page-number)) + let new-assignment-list = () + index = 0 + for (start, end) in page-number-list { + let page-number = if start == end [#start] else [#start - #end] + let assignment = assignment-list.at(index) + let serial-number = [#{assignment.number}. ] + let description = stack(dir: ltr, v(5em), assignment.description) + let item = (serial-number, description, page-number, assignment.date, []) + new-assignment-list.push(item) + index = index + 1 + } + new-assignment-list + } + #list-of-assignments((assignment-list, last-page-number) => { + counter(page).update(1) + align(center, [== Contents]) + tablex( + columns: (3em, 1fr, 4em, 6em, 11em), + stroke: 1pt + gray, + repeat-header: true, + map-cols: (i, cells) => (cells.first(), ..cells.slice(1).map(cell => (..cell, align: column-alignments.at(i)))), + heading-format[*Sl.* \ *No.*], heading-format[*Description*], heading-format[*Page No.*], heading-format[*Date*], heading-format[*Teacher’s* \ *Signature*], + ..preprocess-alist(assignment-list, last-page-number).flatten(), + ) + // signature() + }) +]) + +#colbreak() + diff --git a/opencv/cover.tpl.typ b/opencv/cover.tpl.typ new file mode 100644 index 0000000..d489faa --- /dev/null +++ b/opencv/cover.tpl.typ @@ -0,0 +1,37 @@ +#import "@preview/tablex:0.0.7": tablex, cellx +#import "/template.typ": apply + +#let cover(page-count) = apply(page-numbering: (..nums) => {}, [ + #set align(center) + #v(1in) + #set text(font: "Hanken Grotesk") + #set text(size: 40pt) + University of --- + #v(0.5in) + #set text(size: 30pt) + B.Sc. Honours Semester V --- \ + Examination 20--- + #v(0.35in) + #set text(font: "Inter", size: 25pt) + Practical Assignments \ _on_ \ Digital Image Processing Lab \ using OpenCV and Python + #v(1in) + #set text(font: "Hanken Grotesk", size: 20pt) + #tablex( + columns: 2, + stroke: none, + align: left, + gutter: 5pt, + [*Roll No.:*], [---], + [*Registration No.:*], [---], + [*Subject Code:*], [---], + [*Paper Code:*], [---], + [*Number of pages:*], page-count + ) +]) + +#locate(loc => { + let last-page-number = counter(page).final(loc).first() + cover(last-page-number) + colbreak() +}) + diff --git a/opencv/images/1.1.png b/opencv/images/1.1.png new file mode 100644 index 0000000..0e2f93a Binary files /dev/null and b/opencv/images/1.1.png differ diff --git a/opencv/images/1.2.png b/opencv/images/1.2.png new file mode 100644 index 0000000..ca86c1b Binary files /dev/null and b/opencv/images/1.2.png differ diff --git a/opencv/images/1.3.png b/opencv/images/1.3.png new file mode 100644 index 0000000..11c0932 Binary files /dev/null and b/opencv/images/1.3.png differ diff --git a/opencv/images/1.4.png b/opencv/images/1.4.png new file mode 100644 index 0000000..aabc372 Binary files /dev/null and b/opencv/images/1.4.png differ diff --git a/opencv/images/1.5.png b/opencv/images/1.5.png new file mode 100644 index 0000000..695e8cf Binary files /dev/null and b/opencv/images/1.5.png differ diff --git a/opencv/images/1.6.png b/opencv/images/1.6.png new file mode 100644 index 0000000..3dbdef3 Binary files /dev/null and b/opencv/images/1.6.png differ diff --git a/opencv/images/1.7.png b/opencv/images/1.7.png new file mode 100644 index 0000000..9049014 Binary files /dev/null and b/opencv/images/1.7.png differ diff --git a/opencv/images/10.svg b/opencv/images/10.svg new file mode 100644 index 0000000..d1a5bed --- /dev/null +++ b/opencv/images/10.svg @@ -0,0 +1,678 @@ + + + + + + + + + 2024-02-10T06:41:10.070195 + image/svg+xml + + + Matplotlib v3.3.4, https://matplotlib.org/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/opencv/images/11.gn.jpg b/opencv/images/11.gn.jpg new file mode 100644 index 0000000..19654c8 Binary files /dev/null and b/opencv/images/11.gn.jpg differ diff --git a/opencv/images/11.snp.jpg b/opencv/images/11.snp.jpg new file mode 100644 index 0000000..e69de29 diff --git a/opencv/images/11.svg b/opencv/images/11.svg new file mode 100644 index 0000000..0f029b6 --- /dev/null +++ b/opencv/images/11.svg @@ -0,0 +1,443 @@ + + + + + + + + + 2024-02-10T06:09:20.589307 + image/svg+xml + + + Matplotlib v3.3.4, https://matplotlib.org/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/opencv/images/12.max.jpg b/opencv/images/12.max.jpg new file mode 100644 index 0000000..606a664 Binary files /dev/null and b/opencv/images/12.max.jpg differ diff --git a/opencv/images/12.mean.jpg b/opencv/images/12.mean.jpg new file mode 100644 index 0000000..98ffbc5 Binary files /dev/null and b/opencv/images/12.mean.jpg differ diff --git a/opencv/images/12.median.jpg b/opencv/images/12.median.jpg new file mode 100644 index 0000000..f5fe5e5 Binary files /dev/null and b/opencv/images/12.median.jpg differ diff --git a/opencv/images/12.min.jpg b/opencv/images/12.min.jpg new file mode 100644 index 0000000..14aaeaa Binary files /dev/null and b/opencv/images/12.min.jpg differ diff --git a/opencv/images/12.svg b/opencv/images/12.svg new file mode 100644 index 0000000..913b46b --- /dev/null +++ b/opencv/images/12.svg @@ -0,0 +1,561 @@ + + + + + + + + + 2024-02-10T06:18:52.706437 + image/svg+xml + + + Matplotlib v3.3.4, https://matplotlib.org/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/opencv/images/12.weighted_avg.jpg b/opencv/images/12.weighted_avg.jpg new file mode 100644 index 0000000..b734df1 Binary files /dev/null and b/opencv/images/12.weighted_avg.jpg differ diff --git a/opencv/images/13.1.jpg b/opencv/images/13.1.jpg new file mode 100644 index 0000000..1f54829 Binary files /dev/null and b/opencv/images/13.1.jpg differ diff --git a/opencv/images/13.2.jpg b/opencv/images/13.2.jpg new file mode 100644 index 0000000..a1ca0cc Binary files /dev/null and b/opencv/images/13.2.jpg differ diff --git a/opencv/images/13.3.jpg b/opencv/images/13.3.jpg new file mode 100644 index 0000000..ce142e2 Binary files /dev/null and b/opencv/images/13.3.jpg differ diff --git a/opencv/images/14.svg b/opencv/images/14.svg new file mode 100644 index 0000000..058fe4f --- /dev/null +++ b/opencv/images/14.svg @@ -0,0 +1,895 @@ + + + + + + + + + 2024-02-10T02:49:34.379853 + image/svg+xml + + + Matplotlib v3.3.4, https://matplotlib.org/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/opencv/images/15.svg b/opencv/images/15.svg new file mode 100644 index 0000000..058fe4f --- /dev/null +++ b/opencv/images/15.svg @@ -0,0 +1,895 @@ + + + + + + + + + 2024-02-10T02:49:34.379853 + image/svg+xml + + + Matplotlib v3.3.4, https://matplotlib.org/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/opencv/images/1i.png b/opencv/images/1i.png new file mode 100644 index 0000000..0ad20bb Binary files /dev/null and b/opencv/images/1i.png differ diff --git a/opencv/images/1igr.png b/opencv/images/1igr.png new file mode 100644 index 0000000..c2d8b16 Binary files /dev/null and b/opencv/images/1igr.png differ diff --git a/opencv/images/2.(-45.0).png b/opencv/images/2.(-45.0).png new file mode 100644 index 0000000..c4ddc7d Binary files /dev/null and b/opencv/images/2.(-45.0).png differ diff --git a/opencv/images/2.(60.0).png b/opencv/images/2.(60.0).png new file mode 100644 index 0000000..c994102 Binary files /dev/null and b/opencv/images/2.(60.0).png differ diff --git a/opencv/images/3.svg b/opencv/images/3.svg new file mode 100644 index 0000000..877d579 --- /dev/null +++ b/opencv/images/3.svg @@ -0,0 +1,1115 @@ + + + + + + + + + 2024-02-10T03:25:42.088782 + image/svg+xml + + + Matplotlib v3.3.4, https://matplotlib.org/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/opencv/images/4.b.jpg b/opencv/images/4.b.jpg new file mode 100644 index 0000000..03dca9a Binary files /dev/null and b/opencv/images/4.b.jpg differ diff --git a/opencv/images/4.g.jpg b/opencv/images/4.g.jpg new file mode 100644 index 0000000..71e6db4 Binary files /dev/null and b/opencv/images/4.g.jpg differ diff --git a/opencv/images/4.jpg b/opencv/images/4.jpg new file mode 100644 index 0000000..42d1580 Binary files /dev/null and b/opencv/images/4.jpg differ diff --git a/opencv/images/4.r.jpg b/opencv/images/4.r.jpg new file mode 100644 index 0000000..100dde6 Binary files /dev/null and b/opencv/images/4.r.jpg differ diff --git a/opencv/images/4i.jpg b/opencv/images/4i.jpg new file mode 100644 index 0000000..42d1580 Binary files /dev/null and b/opencv/images/4i.jpg differ diff --git a/opencv/images/4igr.jpg b/opencv/images/4igr.jpg new file mode 100644 index 0000000..5b10150 Binary files /dev/null and b/opencv/images/4igr.jpg differ diff --git a/opencv/images/5.log.jpg b/opencv/images/5.log.jpg new file mode 100644 index 0000000..1e47f12 Binary files /dev/null and b/opencv/images/5.log.jpg differ diff --git a/opencv/images/5.negative.jpg b/opencv/images/5.negative.jpg new file mode 100644 index 0000000..63eeb8c Binary files /dev/null and b/opencv/images/5.negative.jpg differ diff --git a/opencv/images/5.piecewise.jpg b/opencv/images/5.piecewise.jpg new file mode 100644 index 0000000..f7a1b8b Binary files /dev/null and b/opencv/images/5.piecewise.jpg differ diff --git a/opencv/images/5.power_law.jpg b/opencv/images/5.power_law.jpg new file mode 100644 index 0000000..4fbb181 Binary files /dev/null and b/opencv/images/5.power_law.jpg differ diff --git a/opencv/images/6.jpg b/opencv/images/6.jpg new file mode 100644 index 0000000..b8b0942 Binary files /dev/null and b/opencv/images/6.jpg differ diff --git a/opencv/images/6.svg b/opencv/images/6.svg new file mode 100644 index 0000000..afd86dc --- /dev/null +++ b/opencv/images/6.svg @@ -0,0 +1,1920 @@ + + + + + + + + + 2024-02-10T05:35:57.939333 + image/svg+xml + + + Matplotlib v3.3.4, https://matplotlib.org/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/opencv/images/7.a.jpg b/opencv/images/7.a.jpg new file mode 100644 index 0000000..099e013 Binary files /dev/null and b/opencv/images/7.a.jpg differ diff --git a/opencv/images/7.b.jpg b/opencv/images/7.b.jpg new file mode 100644 index 0000000..ae6c25b Binary files /dev/null and b/opencv/images/7.b.jpg differ diff --git a/opencv/images/7.c.jpg b/opencv/images/7.c.jpg new file mode 100644 index 0000000..534a2b0 Binary files /dev/null and b/opencv/images/7.c.jpg differ diff --git a/opencv/images/7.d.jpg b/opencv/images/7.d.jpg new file mode 100644 index 0000000..7bfa055 Binary files /dev/null and b/opencv/images/7.d.jpg differ diff --git a/opencv/images/8o.jpg b/opencv/images/8o.jpg new file mode 100644 index 0000000..64d94ed Binary files /dev/null and b/opencv/images/8o.jpg differ diff --git a/opencv/images/9i1.jpg b/opencv/images/9i1.jpg new file mode 100644 index 0000000..606a664 Binary files /dev/null and b/opencv/images/9i1.jpg differ diff --git a/opencv/images/9i2.jpg b/opencv/images/9i2.jpg new file mode 100644 index 0000000..14aaeaa Binary files /dev/null and b/opencv/images/9i2.jpg differ diff --git a/opencv/images/9o.jpg b/opencv/images/9o.jpg new file mode 100644 index 0000000..da8316c Binary files /dev/null and b/opencv/images/9o.jpg differ diff --git a/opencv/images/landscape.png b/opencv/images/landscape.png index 6614b21..0ad20bb 100644 Binary files a/opencv/images/landscape.png and b/opencv/images/landscape.png differ diff --git a/opencv/prelude.typ b/opencv/prelude.typ new file mode 100644 index 0000000..ecb5543 --- /dev/null +++ b/opencv/prelude.typ @@ -0,0 +1,8 @@ +#import "@preview/tablex:0.0.7": tablex, cellx +#import "/tpl.typ": apply, signature, list-of-assignments, apply-page-borders + +#include "/cover.typ" +#include "/contents.typ" + +#counter(page).update(0) + diff --git a/opencv/tpl.typ b/opencv/tpl.typ index 239197a..2190dd5 100644 --- a/opencv/tpl.typ +++ b/opencv/tpl.typ @@ -1,47 +1,106 @@ #import "@preview/codelst:1.0.0": sourcefile -#let hlfile(filename) = sourcefile(read(filename), file: filename) -#let apply(body) = { -// let body-font-settings = (font: "Nunito Sans 10pt", size: 12pt, stretch: 75%) - let body-font-settings = (font: "Hanken Grotesk", size: 12pt, stretch: 75%) - let page-margin = (left: 1in, right: 0.5in, top: 0.5in, bottom: 0.25in) - let margin = (left: 0.75in, right: 0.25in, top: 2em, bottom: 2em) - let page-frame-thickness = 1.5pt + +/* Highlights the source code file. */ +#let highlight-code-file(filename) = sourcefile(read(filename), file: filename) + +/* The state variable to indicate whether the end of an assignment is reached. */ +#let eoa = state("is-at-end-of-assignment", false) + +/* Updates the state variable to indicate the end of an assignment. */ +#let signature() = { + eoa.update(true) +} + +/* Draws the signature construct at the bottom right corner in the footer of the last page of an assignment. */ +#let signature-footer(loc) = { + if eoa.at(loc) { + align(bottom + right, + move(dy: -4em, dx: -1em, + block(width: 15em)[ + #v(3em) + #line(length: 100%) \ + #v(-2.5em) + #align(center)[Teacher’s signature] + ])) + eoa.update(false) + } +} + +/* Draws page border around the provided content, taking an optional function to be called at the footer. */ +#let apply-page-borders(body, font-options: (), footer-special-func: none, page-numbering: none) = { + let page-margin = (left: 0.75in, right: 0.25in, top: 0.25in, bottom: 0.25in) + let margin = (left: 0.65in, right: 0.15in, top: 1.5em, bottom: 1.5em) + let page-border-thickness = 1.25pt set page( margin: (..page-margin, bottom: margin.bottom + 2em), - numbering: "1", - background: align(top + start, pad(..margin, rect(width: 100%, height: 100%, stroke: page-frame-thickness + gray))), - footer: locate(loc => align(center, move(dy: -margin.bottom + 1em, text(..body-font-settings, size: 9pt, counter(page).display(loc.page-numbering()))))) + numbering: if page-numbering != none { page-numbering } else { "1" }, + background: align(top + start, pad(..margin, rect(width: 100%, height: 100%, stroke: page-border-thickness + gray, radius: 5pt))), + footer: locate(loc => { + align(center, move(dy: -margin.bottom + 1em, text(..font-options, size: 9pt, counter(page).display(loc.page-numbering())))) + if footer-special-func != none { + footer-special-func(loc) + } + }) ) - show: block.with(breakable: true, width: 100%, inset: page-frame-thickness + 1em) - - set text(..body-font-settings) + show: block.with(breakable: true, width: 100%, inset: page-border-thickness + 1em) + body +} - let code-color = rgb("#f4f4f4") -// show raw: set text(font: "CommitMono", size: 1.1em) - show raw: set text(font: "Source Code Pro", size: 1.1em) -// show raw: set text(font: "Iosevka Fixed", size: 1.1em) +#let apply(body, page-numbering: none) = { + let body-font-settings = (font: "Nunito Sans 10pt", size: 12pt, stretch: 75%) + set text(..body-font-settings) + show raw: set text(font: "Iosevka Fixed", size: 1.1em) show raw.where(block: false): box.with( - fill: code-color, inset: (x: 3pt, y: 0pt), outset: (y: 3pt), radius: 2pt, ) show raw.where(block: true): block.with( - fill: code-color, inset: 10pt, radius: 4pt, width: 100%, ) show raw.where(block: true): it => align(left, it) -// set raw(theme: "vendor/gr.tmTheme") - set par(leading: 0.6em) - body + set raw(theme: "vendor/gr.tmTheme") + set list(marker: ([$square.filled.tiny$], [--])) + set par(leading: 0.5em) + apply-page-borders(body, font-options: body-font-settings, footer-special-func: signature-footer, page-numbering: page-numbering) } -#let assignment(number) = { - set align(center) - [== Assignment #number] -} -#let objective(body) = align(center, [*Objective*: #body]) -#let oset(kind) = block(spacing: 0.6em, [===== #h(1em) #kind]) + +#let alist = state("assignment-list", ()) + +#let list-of-assignments(contents) = locate(loc => { + let assignment-list = alist.final(loc) + let last-page-number = counter(page).final(loc).first() + contents(assignment-list, last-page-number) +}) + +#let list-of-dates = ([12/09/2023], [19/09/2023], [27/09/2023], [04/10/2023], [06/10/2023], [11/10/2023], [17/10/2023], [21/10/2023], [22/11/2023], [05/12/2023], [14/12/2023], [20/12/2023], [02/01/2024], [03/01/2024], [09/01/2024], [10/01/2024], [18/01/2024]) +#let assignment-dates-indices = (1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13) + +#let assignment(number, description, reduce-gap: false, pad: false) = align(center, [ += #text(weight: 600, [Assignment #number]) + #{ + let date = list-of-dates.at(assignment-dates-indices.at(number - 1) - 1) + v(-1.65em) + align(right, [Date: #date]) + if reduce-gap { v(-0.75em) } + align(center, box[ + #set par(justify: true) + #show: H => align(left, H) +== #text(weight: 500, [Program statement:]) #text(weight: 400, description) + ]) + locate(loc => alist.update(lst => (..lst, (number: number, description: description, page-number: counter(page).at(loc).first(), date: date)))) + } +]) + +#let scos(n, obody, cont: false) = [ + === Source Code + #show raw: set text(size: 10pt) + #highlight-code-file("/code/a" + str(n) + ".py") + #if cont == true [ #colbreak() ] + === Output + #obody +] diff --git a/opencv/vendor/gr.tmTheme b/opencv/vendor/gr.tmTheme new file mode 100644 index 0000000..c4ab8f1 --- /dev/null +++ b/opencv/vendor/gr.tmTheme @@ -0,0 +1,566 @@ + + + + + author + Template: Chris Kempson, Scheme: Alexandre Gavioli (https://github.com/Alexx2/) + name + Base16 Grayscale Light + semanticClass + theme.base16.grayscale-light + colorSpaceName + sRGB + gutterSettings + + background + #e3e3e3 + divider + #e3e3e3 + foreground + #ababab + selectionBackground + #b9b9b9 + selectionForeground + #525252 + + settings + + + settings + + background + #f7f7f7 + caret + #464646 + foreground + #464646 + invisibles + #ababab + lineHighlight + #ababab55 + selection + #b9b9b9 + + + + name + Text + scope + variable.parameter.function + settings + + foreground + #222222 + + + + name + Comments + scope + comment, punctuation.definition.comment + settings + + foreground + #777777 + fontStyle + bold + + + + name + Punctuation + scope + punctuation.definition.string, punctuation.definition.variable, punctuation.definition.string, punctuation.definition.parameters, punctuation.definition.string, punctuation.definition.array + settings + + foreground + #111111 + + + + name + Delimiters + scope + none + settings + + foreground + #222222 + + + + name + Operators + scope + keyword.operator + settings + + foreground + #222222 + + + + name + Keywords + scope + keyword + settings + + foreground + #333333 + fontStyle + bold + + + + name + Variables + scope + variable + settings + + foreground + #555555 + + + + name + Functions + scope + entity.name.function, meta.require, support.function.any-method, variable.function, variable.annotation, support.macro + settings + + foreground + #444444 + + + + name + Labels + scope + entity.name.label + settings + + foreground + #5e5e5e + + + + name + Classes + scope + support.class, entity.name.class, entity.name.type.class + settings + + foreground + #666666 + + + + name + Classes + scope + meta.class + settings + + foreground + #101010 + + + + name + Methods + scope + keyword.other.special-method + settings + + foreground + #444444 + + + + name + Storage + scope + storage + settings + + foreground + #444444 + fontStyle + bold + + + + name + Support + scope + support.function + settings + + foreground + #868686 + + + + name + Strings, Inherited Class + scope + string, constant.other.symbol, entity.other.inherited-class + settings + + foreground + #333333 + + + + name + Integers + scope + constant.numeric + settings + + foreground + #000000 + + + + name + Floats + scope + none + settings + + foreground + #000000 + + + + name + Boolean + scope + none + settings + + foreground + #222222 + + + + name + Constants + scope + constant + settings + + foreground + #000000 + + + + name + Tags + scope + entity.name.tag + settings + + foreground + #7c7c7c + + + + name + Attributes + scope + entity.other.attribute-name + settings + + foreground + #999999 + + + + name + Attribute IDs + scope + entity.other.attribute-name.id, punctuation.definition.entity + settings + + foreground + #686868 + + + + name + Selector + scope + meta.selector + settings + + foreground + #747474 + + + + name + Values + scope + none + settings + + foreground + #999999 + + + + name + Headings + scope + markup.heading punctuation.definition.heading, entity.name.section + settings + + fontStyle + + foreground + #686868 + + + + name + Units + scope + keyword.other.unit + settings + + foreground + #999999 + + + + name + Bold + scope + markup.bold, punctuation.definition.bold + settings + + fontStyle + bold + foreground + #a0a0a0 + + + + name + Italic + scope + markup.italic, punctuation.definition.italic + settings + + fontStyle + italic + foreground + #747474 + + + + name + Code + scope + markup.raw.inline + settings + + foreground + #8e8e8e + + + + name + Link Text + scope + string.other.link, punctuation.definition.string.end.markdown, punctuation.definition.string.begin.markdown + settings + + foreground + #7c7c7c + + + + name + Link Url + scope + meta.link + settings + + foreground + #999999 + + + + name + Lists + scope + markup.list + settings + + foreground + #7c7c7c + + + + name + Quotes + scope + markup.quote + settings + + foreground + #999999 + + + + name + Separator + scope + meta.separator + settings + + background + #b9b9b9 + foreground + #464646 + + + + name + Inserted + scope + markup.inserted + settings + + foreground + #8e8e8e + + + + name + Deleted + scope + markup.deleted + settings + + foreground + #7c7c7c + + + + name + Changed + scope + markup.changed + settings + + foreground + #747474 + + + + name + Colors + scope + constant.other.color + settings + + foreground + #868686 + + + + name + Regular Expressions + scope + string.regexp + settings + + foreground + #868686 + + + + name + Escape Characters + scope + constant.character.escape + settings + + foreground + #868686 + + + + name + Embedded + scope + punctuation.section.embedded, variable.interpolation + settings + + foreground + #747474 + + + + name + Illegal + scope + invalid.illegal + settings + + background + #7c7c7c + foreground + #101010 + + + + name + Broken + scope + invalid.broken + settings + + background + #999999 + foreground + #f7f7f7 + + + + name + Deprecated + scope + invalid.deprecated + settings + + background + #5e5e5e + foreground + #101010 + + + + name + Unimplemented + scope + invalid.unimplemented + settings + + background + #ababab + foreground + #101010 + + + + uuid + uuid + + -- cgit 1.4.1-2-gfad0