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
from PIL import Image | |
def resize_image(img_path, desired_size = 300, background_color=None): | |
img = Image.open(img_path) | |
old_size = img.size | |
if background_color == None: | |
background_color = img.load()[0,0] |
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 cv2 | |
import numpy as np | |
from PIL import Image | |
def process_pixels(img): | |
pixel_data = list(img.getdata()) | |
pixels = np.array(pixel_data).flatten() | |
width = img.size[0] | |
height = img.size[1] |
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 os | |
import hashlib | |
import glob | |
# Get the SHA-256 hash of a file | |
def sha256(fname, size=4096): | |
sha256_hash = hashlib.sha256() | |
with open(fname, 'rb') as f: | |
for byte_block in iter(lambda: f.read(4096), b""): |
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 cv2 | |
import numpy as np | |
def calculate_threshold(img): | |
hist, bin_edges = np.histogram(img, bins=256) | |
bin_mids = (bin_edges[:-1] + bin_edges[1:]) / 2. | |
weight1 = np.cumsum(hist) | |
weight2 = np.cumsum(hist[::-1])[::-1] | |
mean1 = np.cumsum(hist * bin_mids) / weight1 |
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 re, sys | |
input_file ="input.csv" | |
output_file ="output.csv" | |
input_file_delimiter = ';' | |
output_file_delimiter = ',' | |
output = [] | |
with open(input_file) as f_input: | |
lines = f_input.read().splitlines() |
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
from wordcloud import WordCloud | |
import matplotlib.pyplot as plt | |
def plot_wordcloud(text, mask=None, max_words=200, max_font_size=100, figure_size=(12.0,12.0), | |
title = None, title_size=18, image_color=False): | |
wordcloud = WordCloud(background_color='white', | |
max_words = max_words, | |
max_font_size = max_font_size, | |
random_state = 42, |
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 json | |
seperator = ',' | |
with open("text.txt", encoding='utf-8') as file: | |
data = file.read().splitlines() | |
print(len(data)) | |
json_object = {} | |
for i, each in enumerate(data): |
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
with open("text.txt", 'r') as infile: | |
data = infile.read().splitlines() | |
# print(data) | |
with open("text.txt", 'w') as outfile: | |
for each in list(set(data)): | |
outfile.write(each + '\n') |
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
# Image Data augmentation | |
# Use this program to perform image data augmentation in case you do not want to use a generator for some reason | |
# Check out ImageDataGenerator if you are looking for a generator in TensorFlow: https://www.tensorflow.org/api_docs/python/tf/keras/preprocessing/image/ImageDataGenerator | |
import cv2 | |
import numpy as np | |
import glob | |
import hashlib | |
search_pattern = "images/*.jpg" |
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 sys | |
try: | |
import matplotlib.pyplot as plt | |
except ModuleNotFoundError: | |
print("Error: Module was not found") | |
sys.exit() | |
except: | |
print("Something went wrong while importing module/s \n") | |
sys.exit() | |