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
def is_power2(num): | |
'states if a number is a power of two' | |
return ((num & (num - 1)) == 0) and num != 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
void SplitString(const std::string& s, std::vector<std::string>& v, const std::string& c) | |
{ | |
std::string::size_type pos1, pos2; | |
pos2 = s.find(c); | |
pos1 = 0; | |
while(std::string::npos != pos2) | |
{ | |
v.push_back(s.substr(pos1, pos2-pos1)); | |
pos1 = pos2 + c.size(); |
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
def add_gaussian_noise(image): | |
# image must be scaled in [0, 1] | |
with tf.name_scope('Add_gaussian_noise'): | |
noise = tf.random_normal(shape=tf.shape(image), mean=0.0, stddev=(50)/(255), dtype=tf.float32) | |
noise_img = image + noise | |
noise_img = tf.clip_by_value(noise_img, 0.0, 1.0) | |
return noise_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
import os | |
import numpy as np | |
import scipy.ndimage as ndimage | |
import matplotlib | |
import matplotlib.pyplot as plt | |
def frac_eq_to(image, value=0): | |
return (image == value).sum() / float(np.prod(image.shape)) | |
def extract_patches(image, patchshape, overlap_allowed=0.5, cropvalue=None, |