This file contains hidden or 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
#create a triangle mask by picking all pixels below a given line | |
triangle_mask = (y > 400 + n - x) | |
#set the triangle to be cyan | |
copyImg[triangle_mask] = [0,255,255] | |
#show image | |
plt.imshow(copyImg) |
This file contains hidden or 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
#create a square mask around the top right of the image | |
square_mask = (x<200)&(x>100)&(y<600)&(y>500) | |
#make the square red | |
copyImg[square_mask] = [255,0,0] | |
#show image | |
plt.imshow(copyImg) |
This file contains hidden or 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
#operate on a copy of the image | |
copyImg = img.copy() | |
#get the x and y center points of our image | |
center_x = n/2 | |
center_y = m/2 | |
#create a circle mask which is centered in the middle of the image, and with radius 100 | |
circle_mask = (x-center_x)**2 + (y-center_y)**2 <= 100**2 |
This file contains hidden or 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 numpy as np | |
import matplotlib.pyplot as plt | |
#read the image | |
img = plt.imread('mouse.jpg') | |
#show the image | |
plt.imshow(img) |
This file contains hidden or 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
#create a copy of my grey image and just get first layer (because all layers are same) | |
copyImg = greyImage.copy()[:,:,0] | |
#get number of rows, columns in our image | |
numRows,numCols = copyImg.shape | |
#define how big we want our blurring box to be, the bigger the blurrier | |
boxSize = 31 | |
#get half the size of the box |
This file contains hidden or 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
#create a copy of my image | |
copyImg = img.copy() | |
#reverse all the rows in my image | |
hFlipImg = copyImg[:,::-1] | |
#show the image | |
plt.imshow(hFlipImg) |
This file contains hidden or 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
#create a copy of my image | |
copyImg = img.copy() | |
#reverse all the rows in my image | |
vFlipImg = copyImg[::-1] | |
#show the image | |
plt.imshow(vFlipImg) |
This file contains hidden or 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
#create a copy of my image | |
copyImg = img.copy() | |
#get the average of each pixel | |
#we need axis=2 so that we take averages accross the 3rd axis (the color axis) rather than accross the rows or columns | |
average_pixel_values = np.mean(copyImg, axis=2, keepdims=True) | |
#create the grey image by "stacking" three copies of these grey values together | |
greyImage = np.concatenate([average_pixel_values]*3, axis=2) |
This file contains hidden or 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 matplotlib.pyplot as plt | |
import numpy as np | |
#read my image from file | |
img = plt.imread('baby_yoda.jpg') | |
#show my image | |
plt.imshow(img) |
This file contains hidden or 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
#initialize tf-idf dictionary for secret speech | |
tfidf_dict_secret = {} | |
#initalize bush and obama scores to zero | |
bush_score = 0 | |
obama_score = 0 | |
#for each phrase in the secret TF dictionary... | |
for phrase, tf in d_secret.items(): | |
#get the importance of this phrase in the bush tf-idf dictionary |