Skip to content

Instantly share code, notes, and snippets.

View ali-john's full-sized avatar
🎯
Focusing

Ali John ali-john

🎯
Focusing
View GitHub Profile
import numpy as np
import cv2 as opencv
import random as r
def neighbours(i, j, src):
# left
left = src[i, j - 1]
# top
top = src[i - 1, j]
def maxFilter(img, size):
out = np.zeros([img.shape[0], img.shape[1]], dtype="int")
for i in range(img.shape[0] - size):
for j in range(img.shape[1] - size):
mat = img[i: i + size, j: j + size]
mat = np.ravel(mat) # convert to 1D array
mat = np.sort(mat)
out[i, j] = np.max(mat)
return out
import numpy as np
import cv2 as opencv
import Transforms
import od as o
import cca
import pad as p
import csv
import os
@ali-john
ali-john / contrastStretching.py
Created April 20, 2022 20:36
Contrast stretching code for image enhancement
import numpy as np
import cv2 as opencv
# Read Image
image = opencv.imread('einstein.PNG', opencv.IMREAD_GRAYSCALE)
fifth_percentile = np.percentile(image, 5) # 5th percentile- used as min value
nintyfive_percentile = np.percentile(image, 95) # used for max value
output = np.zeros([image.shape[0], image.shape[1]], dtype=np.uint8)
# pixel value less than 5th percentile -- set to 0
# pixel value > 95th percentile -- set to 255