Skip to content

Instantly share code, notes, and snippets.

@YCAyca
YCAyca / non_linear_filtering.py
Last active Sep 2, 2021
non_linear_filtering
View non_linear_filtering.py
import copy
import cv2
import numpy as np
from PIL import Image, ImageFilter
from enum import Enum
class Filter_Type(Enum):
MIN = 1
MAX = 2
View linear_filtering.py
import copy
from nonlinear_filtering import padding, Print_Mode
import cv2
import numpy as np
from enum import Enum
import scipy.stats as st
class OPERATION_TYPE(Enum):
Convolution = 1
@YCAyca
YCAyca / morphological_processing.py
Created Sep 2, 2021
Morphological Image Processing
View morphological_processing.py
import cv2
import numpy as np
from scipy import ndimage
""" Erosion with OpenCV """
def Erosion_Opencv(img, kernel):
cv2.imshow("Input Image", img)
cv2.waitKey(0)
erosion = cv2.erode(img,kernel,iterations = 1)
View connected_components.py
import cv2
import numpy as np
import matplotlib.pyplot as plt
def show_components(labels):
# Map component labels to hue val, 0-179 is the hue range in OpenCV
label_hue = np.uint8(179*labels/np.max(labels))
blank_ch = 255*np.ones_like(label_hue)
labeled_img = cv2.merge([label_hue, blank_ch, blank_ch])
View simple_som.py
""" Dataset """
v1 = [1, 1, 0, 0]
v2 = [1, 0, 0, 0]
v3 = [0, 0, 0, 1]
v4 = [0, 0, 1, 1]
inputs = [v1, v2, v3, v4]
dataset_length = len(inputs)
View main.m
clear all;
close all;
clc;
format short
%% DLT
% Loading 3D World Points and 2D projected points (Ground Truth Points for projection)coming from previous lab
World_PTS = load('pts3D.txt');
View DLT.m
% Apply DLT using the following functions
% World_PTS : 3D world points, GT_PTS: 2D Projected image points of these 3D world points,
% Calibration_Points_Count : the quantity of points we use for realizing calibration
function DLT(World_PTS, GT_PTS, Calibration_Points_Count)
A = Create_Matrix_A(Calibration_Points_Count, World_PTS, GT_PTS)
P = Obtain_Projection_Matrix(A)
[K,R,T] = QR_Decomposition(P)
[Projected_X, Projected_Y] = Projection(P, World_PTS, GT_PTS);
end
View zhang.m
clear all;
close all;
clc;
%We have simulated a regular checkerboard pattern, comprising 10x10 points, and a camera observing it.
%The checkerboard is moved around the camera and 10 images of it are acquired in the process.
%PTS_world = load('ptsXY.txt'); % Cartesian coordinates of the checkerboard points,
%Pixel coordinates of the 2D points in the 10 images, given in pts2D_i.txt, i = 1, 2, ..., 10.
View epipolar_geometry.m
clear all;
close all;
clc;
PTS1 = load('pts2D_1.txt'); % 300 x 2 matrix
PTS2 = load('pts2D_2.txt'); % 300 x 2 matrix
tmp = ones(length(PTS1),1);
Homogenous_PTS1 = [PTS1, tmp];
View triangulation.m
%% Obtain 2 cameras seeing the same scene
clear all;
close all;
clc;
PTS= load('pts3D.txt');
count_3d_points = length(PTS);
tmp = ones(count_3d_points,1);
PTS_homogenous = [PTS, tmp];