Skip to content

Instantly share code, notes, and snippets.

View nhomble's full-sized avatar
🐕

Nicolas nhomble

🐕
View GitHub Profile
public class ExampleLoopString {
public static int frequencyOf(String input, char c) {
if (input == null) {
return 0;
}
int ret = 0;
for (int i = 0; i < input.length(); i++) {
if (input.charAt(i) == c) {
ret += 1;
@nhomble
nhomble / ExampleFileIO.java
Created January 20, 2022 08:17
first example of java streams to read a file into string
import java.io.*;
public class ExampleFileIO {
public static void main(String[] args) {
try (InputStream is = ExampleFileIO.class.getClassLoader().getResourceAsStream("list.txt");
InputStreamReader reader = new InputStreamReader(is);
BufferedReader bufferedReader = new BufferedReader(reader);
) {
String s;
@nhomble
nhomble / EnumExample.java
Created January 19, 2022 01:35
first look at Java enumerations
public class EnumExample {
enum Seasons {
WINTER, SPRING, SUMMER, FALL;
}
public static boolean needJacket(Seasons s){
return s == Seasons.WINTER || s == Seasons.FALL;
}
@nhomble
nhomble / tf-http-provider-map.tf
Created February 4, 2021 00:32
terraform http provider - get map
data "http" "example" {
url = "https://checkpoint-api.hashicorp.com/v1/check/terraform"
# Optional request headers
request_headers = {
Accept = "application/json"
}
}
output "example" {
@nhomble
nhomble / rubiks_lab.py
Created October 23, 2017 01:29
show lab color space
import cv2
def thresh(src, img, low, ty):
_, mask = cv2.threshold(img, low, 256, ty)
splits = [cv2.bitwise_and(x, mask) for x in cv2.split(src)]
return cv2.merge(splits)
img = cv2.imread("rubiks.png")
@nhomble
nhomble / color_experiment.py
Last active October 22, 2017 22:42
demonstrate easy color extraction with HSV rather than RGB
import cv2
import numpy as np
import matplotlib.pyplot as plt
"""
Starting motivation [https://docs.opencv.org/3.2.0/df/d9d/tutorial_py_colorspaces.html]
RGB has no concept of hue unlike HS* (in this case we will do HSV). While we can extract it, it's not as straightforward
as with HSV. In our image, let's say we want to find the green parts. In HSV, we can do a pretty good job by just with
just an arc in the hue and then a fixed saturation range and value. Green can only exist in ~[90,150] degrees. Given
@nhomble
nhomble / diff_of_gauss.py
Created October 9, 2017 04:12
interactively do quick edge detection via difference of gaussian
import cv2
def dog(img, k2=(7, 7), k1=(3, 3), denoise=False, denoise_k=3):
blur1 = cv2.GaussianBlur(img, k1, 1)
blur2 = cv2.GaussianBlur(img, k2, 1)
diff = blur1 - blur2
if denoise:
diff = cv2.medianBlur(diff, denoise_k)
return diff
@nhomble
nhomble / gauss_smooth.py
Created October 1, 2017 23:05
Try gaussian smoothing across different scenarios
import cv2
import matplotlib.pyplot as plt
kernel = (7, 7)
imgs = {
"salt_n_pepper": cv2.imread("Noise_salt_and_pepper.png"), # thank you wikipedia
"wrinkles": cv2.imread("old_man.jpeg"), # images.pexels.com
"tripod": cv2.imread("tripod.png") # classic b/w man looking at camera on tripod
}
@nhomble
nhomble / opencv_denoise_rt_tutorial.py
Last active September 7, 2017 06:16
denoise in real time
import cv2
import numpy as np
def get_img(cap):
ret, frame = cap.read()
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
return frame
@nhomble
nhomble / opencv_denoise_tutorial.py
Last active September 5, 2017 05:33
computational photography discussion 2---wrap two opencv tutorials to grab an image from the webcam and denoise it
import cv2
from matplotlib import pyplot as plt
def before_after(bef, af):
"""
refactor out the matplot lib thing
"""
plt.subplot(121), plt.imshow(bef, 'gray')
plt.subplot(122), plt.imshow(af, 'gray')