Skip to content

Instantly share code, notes, and snippets.

View gutierrezps's full-sized avatar

Gabriel Gutierrez gutierrezps

View GitHub Profile
@gutierrezps
gutierrezps / cv2_noise.py
Last active December 3, 2022 16:55 — forked from lucaswiman/cv2_noise.py
Add Salt and Pepper noise to OpenCV Image
# Add Salt and Pepper noise to OpenCV image, vectorized approach.
# https://stackoverflow.com/questions/22937589/how-to-add-noise-gaussian-salt-and-pepper-etc-to-image-in-python-with-opencv
# Forked and fixed from https://gist.github.com/lucaswiman/1e877a164a69f78694f845eab45c381a
# Fixed: replaced 'image' with 'output'
import numpy as np
import cv2
def sp_noise(image, prob):
@gutierrezps
gutierrezps / parseIpAddress.java
Last active December 20, 2015 17:39 — forked from ryantenney/parseIpAddress.java
Method to parse IP addresses on format x.x.x.x. Useful for sockets etc.
public static boolean parseIpAddress(String ip) throws IllegalArgumentException { // IPv4, format x.x.x.x
StringTokenizer tok = new StringTokenizer(ip, ".");
if (tok.countTokens() != 4) {
throw new IllegalArgumentException("IP address must be in the format 'xxx.xxx.xxx.xxx'");
}
int i = 0;
while (tok.hasMoreTokens()) {
String strVal = tok.nextToken();