Skip to content

Instantly share code, notes, and snippets.

View mubaidr's full-sized avatar
🎯
Adding bugs to web applications!

Muhammad Ubaid Raza mubaidr

🎯
Adding bugs to web applications!
View GitHub Profile
//Parameters required to calculate threshold using OTSU Method
let prbn = 0.0 // First order cumulative
let meanitr = 0.0 // Second order cumulative
let meanglb = 0.0 // Global mean level
let OPT_THRESH_VAL = 0 // Optimum threshold value
let param1
let param2 // Parameters required to work out OTSU threshold algorithm
let param3 = 0.0
let hist_val = []
/**
* Greyscale, threshold and apply median noise removal to image data
* @param {number[]} data Raw pixel data
* @param {number} width Width fo image data
* @param {number} height Height of image data
* @returns {number[]} Pixel Data
*/
function applyAdaptiveThreshold(data, width, height) {
const integralImage = new Array(width * height).fill(0)
/**
* Threshold image data
* @param {number[]} data Raw pixel data
* @param {number} width Width fo image data
* @param {number} height Height of image data
* @returns {number[]} Pixel Data
*/
// function applyMedianFilter(data, width, height) {
// const channels = data.length / (width * height)
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"defaultProfile": "{c8312ac6-2aa2-4191-a6ff-5fcd63b22b8b}",
"keybindings": [],
"profiles": [
{
"acrylicOpacity": 0.85,
"backgroundImage": "E:\\Resources\\Wallpapers\\dark-smoke-abstract-4k-37.jpg",
"backgroundImageOpacity": 0.15,
"colorScheme": "Campbell",
/(((?=\d{4})\d{4}|(?=[a-zA-Z]{3})[a-zA-Z]{3}|\d{2})((?=\/)(\/)|(-)|(\.)|(,))((?=[0-9]{2})[0-9]{2}|(?=[0-9]{1,2})[0-9]{1,2}|[a-zA-Z]{3})((?=\/)(\/)|(-)|(\.)|(,))((?=[0-9]{4})[0-9]{4}|(?=[0-9]{2})[0-9]{2}|[a-zA-Z]{3}))|([0-9]{1,2}(,)?( )?[a-z]{1,3}(,)?( )?[0-9]{2,4})/gim
{
"env": {
"NODE_ENV": "development"
},
"exec": "ts-node --transpile-only src/tmp.ts",
"ext": "js,json,ts",
"ignore": ["dist", "*.test.ts", ".git", "node_modules/**/node_modules"],
"restartable": "rs",
"verbose": true,
"watch": ["src"]
@mubaidr
mubaidr / medianFilter.ts
Last active February 29, 2020 18:42
Median filter implementation in Typescript/javaScript
export function applyMedianFilter(
data: Uint8ClampedArray,
width: number,
height: number,
windowSize = 3
): Uint8ClampedArray {
const channels = data.length / (width * height)
const filterWindow: number[][] = []
const limit = (windowSize - 1) / 2
@mubaidr
mubaidr / SimpleThreshold.ts
Created February 29, 2020 18:47
Simple Threshold implementation in Typescript/javaScript
export function applySimpleThreshold(
data: Uint8ClampedArray,
width: number,
height: number
): Uint8ClampedArray {
const channels = data.length / (width * height)
for (let i = 0; i < data.length; i += channels) {
let average = Math.sqrt((data[i] ** 2 + data[i + 1] ** 2 + data[i + 2] ** 2) / 3)
average = average >= 127 ? 255 : 0
@mubaidr
mubaidr / convolute.ts
Created March 1, 2020 11:59
Convolving images in Typescript/Javascript
export function convolute(
data: Uint8ClampedArray,
width: number,
height: number,
filterWindow = [1, 1, 1, 1, 0, 1, 1, 1, 1]
): Uint8ClampedArray {
const channels = data.length / (width * height)
const windowSize = filterWindow.length
const halfWindowSide = Math.floor(windowSize / 2)
const src = data
@mubaidr
mubaidr / get-latest-tag-on-git.sh
Created March 24, 2020 13:58 — forked from rponte/get-latest-tag-on-git.sh
Getting latest tag on git repository
# The command finds the most recent tag that is reachable from a commit.
# If the tag points to the commit, then only the tag is shown.
# Otherwise, it suffixes the tag name with the number of additional commits on top of the tagged object
# and the abbreviated object name of the most recent commit.
git describe
# With --abbrev set to 0, the command can be used to find the closest tagname without any suffix:
git describe --abbrev=0
# other examples