Skip to content

Instantly share code, notes, and snippets.

@RashidLadj
RashidLadj / Medianfilter.py
Last active January 4, 2022 15:47
Apply a length-k median filter to a 1D array x
import numpy as np
import cv2 as cv
def medianFilter(x, k):
"""
Apply a length-k median filter to a 1D array x.
Boundaries are extended by repeating endpoints.
this is the equivalent of opencv Median for 2D array
"""
if k == 1 :
@RashidLadj
RashidLadj / intersect2D.py
Last active October 16, 2020 15:08
Python function to find the intersection between two 2D (or nD) numpy arrays, i.e. intersection of rows
import numpy as np
def intersect2D(Array_A, Array_B):
"""
Find row intersection between 2D numpy arrays, a and b.
"""
# ''' Using Tuple ''' #
intersectionList = np.asarray([x for x in Array_A for y in Array_B if(tuple(x) == tuple(y))])
@RashidLadj
RashidLadj / intersect2D_with_Index.py
Last active February 4, 2021 11:51
Python function to find the intersection between two 2D numpy arrays with index in each array, i.e. intersection of rows
import numpy as np
def intersect2D(Array_A, Array_B):
"""
Find row intersection between 2D numpy arrays, a and b.
Returns another numpy array with shared rows and index of items in A & B arrays
"""
# [[IDX], [IDY], [value]] where Equal
# ''' Using Tuple ''' #
IndexEqual = np.asarray([(i, j, x) for i,x in enumerate(Array_A) for j, y in enumerate (Array_B) if(tuple(x) == tuple(y))]).T
@Shreeyak
Shreeyak / create_pointCloud.py
Created May 2, 2019 10:23
Script to create a point cloud and save to .ply file from an RGB and Depth Image
#!/usr/bin/env python3
import numpy as np
from PIL import Image
import imageio
import OpenEXR
import struct
import os
def get_pointcloud(color_image,depth_image,camera_intrinsics):