This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
image = cv2.imread('images/input.jpg') | |
cv2.imshow('Original', image) | |
# Create our shapening kernel, we don't normalize since the | |
# the values in the matrix sum to 1 | |
kernel_sharpening = np.array([[-1,-1,-1], | |
[-1,9,-1], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
image = cv2.imread('images/elephant.jpg') | |
cv2.imshow('Original Image', image) | |
cv2.waitKey(0) | |
# Creating our 3 x 3 kernel | |
kernel_3x3 = np.ones((3, 3), np.float32) / 9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
# If you're wondering why only two dimensions, well this is a grayscale image, | |
# if we doing a colored image, we'd use | |
# rectangle = np.zeros((300, 300, 3),np.uint8) | |
# Making a sqare | |
square = np.zeros((300, 300), np.uint8) | |
cv2.rectangle(square, (50, 50), (250, 250), 255, -2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
image = cv2.imread('images/input.jpg') | |
# Create a matrix of ones, then multiply it by a scaler of 100 | |
# This gives a matrix with same dimesions of our image with all values being 100 | |
M = np.ones(image.shape, dtype = "uint8") * 175 | |
# We use this to add this matrix M, to our image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
image = cv2.imread('images/input.jpg') | |
height, width = image.shape[:2] | |
# Let's get the starting pixel coordiantes (top left of cropping rectangle) | |
start_row, start_col = int(height * .25), int(width * .25) | |
# Let's get the ending pixel coordinates (bottom right) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
image = cv2.imread('images/input.jpg') | |
smaller = cv2.pyrDown(image) | |
larger = cv2.pyrUp(smaller) | |
cv2.imshow('Original', image ) | |
cv2.imshow('Smaller ', smaller ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
# load our input image | |
image = cv2.imread('images/input.jpg') | |
# Let's make our image 3/4 of it's original size | |
image_scaled = cv2.resize(image, None, fx=0.75, fy=0.75) | |
cv2.imshow('Scaling - Linear Interpolation', image_scaled) | |
cv2.waitKey() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
image = cv2.imread('images/input.jpg') | |
height, width = image.shape[:2] | |
# Divide by two to rototate the image around its centre | |
rotation_matrix = cv2.getRotationMatrix2D((width/2, height/2), 90, .5) | |
rotated_image = cv2.warpAffine(image, rotation_matrix, (width, height)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
image = cv2.imread('images/input.jpg') | |
# Store height and width of the image | |
height, width = image.shape[:2] | |
quarter_height, quarter_width = height/4, width/4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution(object): | |
def permuteUnique(self, nums): | |
""" | |
:type nums: List[int] | |
:rtype: List[List[int]] | |
""" | |
nums = sorted(nums) | |
temp = [] | |
result = [] | |
used = [0 for _ in range(len(nums))] |