Skip to content

Instantly share code, notes, and snippets.

@jiemojiemo
jiemojiemo / patches.py
Created April 20, 2018 03:08 — forked from dwf/patches.py
Some patch extraction code I'm using to process images.
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,
@jiemojiemo
jiemojiemo / gist:0f7768418d15aeb267ea457503d07611
Created May 17, 2018 07:11
Tensorflow Add Gaussian Noise
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
@jiemojiemo
jiemojiemo / split.cpp
Created June 25, 2018 07:16
Cpp-split a string
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();
@jiemojiemo
jiemojiemo / is_power2.py
Created November 1, 2018 13:01
Check if a number is a power of two
def is_power2(num):
'states if a number is a power of two'
return ((num & (num - 1)) == 0) and num != 0