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
from PIL import * | |
# from IPython.display import display # uncomment if you are using Jupyter | |
im = Image.open(r"C:\Put_your_B&W_img_here.jpg") | |
outIm = Image.new('RGB', im.size, color = 'white') | |
draw = ImageDraw.Draw(outIm) | |
gridSpacing = 5 | |
lineThickness = int(gridSpacing/2) | |
for i in range(0,im.size[0],gridSpacing): |
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
# A fast - numpy based - CPU functions that take a height map and generate a normal map from it | |
import numpy as np | |
import matplotlib.image as mpimg | |
# a function that takes a vector - three numbers - and normalize it, i.e make it's length = 1 | |
def normalizeRGB(vec): | |
length = np.sqrt(vec[:,:,0]**2 + vec[:,:,1]**2 + vec[:,:,2]**2) | |
vec[:,:,0] = vec[:,:,0] / length | |
vec[:,:,1] = vec[:,:,1] / length |
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
#define _CRT_SECURE_NO_WARNINGS | |
#include <iostream> | |
#include <fstream> | |
#include <random> | |
#include <cmath> | |
#include <string> | |
#include <chrono> | |
#include <vector> | |
#include <windows.h> |
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
# calculate mean and std deviation | |
from pathlib import Path | |
import cv2 | |
imageFilesDir = Path(r'C:\your\dataset\dir\here\trainData') | |
files = list(imageFilesDir.rglob('*.png')) | |
# Since the std can't be calculated by simply finding it for each image and averaging like | |
# the mean can be, to get the std we first calculate the overall mean in a first run then |