Skip to content

Instantly share code, notes, and snippets.

View arccoder's full-sized avatar

Akshay Chavan arccoder

  • MA, USA
View GitHub Profile
@arccoder
arccoder / meanshift.m
Last active April 23, 2016 17:21
Mean shift - Toy Example
clc; close all; clear all;
% Generate data
org = zeros(200,200,3);
org(100:198,100:198,:) = 255;
I = org(:,:,1);
imshow(I)
tic
% %
Iteration : 1
Zeroth moment : 1020
First moments : 102510,102510
Center : 101,101
Location : 52,52,98,98
Iteration : 2
Zeroth moment : 689520
First moments : 86534760,86534760
Center : 126,126
Location : 77,77,98,98
@arccoder
arccoder / fastcv_rgb_to_gray.cpp
Created October 3, 2016 23:57
Convert RGB color image to Grayscale using FastCV
#include "fastcv.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
@arccoder
arccoder / fastcv_meanshift.cpp
Last active October 5, 2016 00:37
How to use meanshift functionality from FastCV
#include "fastcv.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
@arccoder
arccoder / create_gif_from_images.m
Last active October 30, 2016 23:19
Create gif using MATLAB
imageExt = '.png';
imagefiles = dir(['*' imageExt]);
outfilename = 'gifname.gif';
for n = 1:length(imagefiles)
im = imread(imagefiles(n).name);
[imind,cm] = rgb2ind(im,256);
% DelayTime in seconds
if n == 1
imwrite(imind,cm,outfilename,'gif','Loopcount',inf,'DelayTime',0.7);
@arccoder
arccoder / kmeans.py
Created October 28, 2016 18:06
K-means Algorithm
import numpy as np
def kmeans(data, numofclasses, options=None):
"""
Calculates the clusters using k-means algorithm and returns cluster labels and centroids
:param data: Data to cluster structured as [Number of observations x Data dimensions(variables)]
:param numofclasses: Number of classes you want to cluster the data into.
:param options: Optional data in dictionary form to overwrite the defaults
max_iterations - int: Maximum number of iterations
@arccoder
arccoder / edgedetection1d.m
Last active January 16, 2017 02:35
Edge detection example explained using 1D toy example.
clc; clear all; close all;
% Data Generation
x = 0:10:2000;
y = sigmf(x,[0.1 1000]);
n = rand(1,201)/40 - 0.0125;
f = y;% + n;
fig = figure;
set(fig, 'PaperUnits', 'inches');
set(fig, 'PaperPosition', [0 0 8 2]);
@arccoder
arccoder / opencv_hough_lines.py
Last active April 5, 2025 20:41
Process the output of cv2.HoughLines from OpenCV using functions that do Polar to Cartesian line conversion, Intersection of Cartesian lines, Line end points on image. https://arccoder.medium.com/process-the-output-of-cv2-houghlines-f43c7546deae
"""
Script contains functions to process the lines in polar coordinate system
returned by the HoughLines function in OpenCV
Line equation from polar to cartesian coordinates
x = rho * cos(theta)
y = rho * sin(theta)
x, y are at a distance of rho from 0,0 at an angle of theta
@arccoder
arccoder / pandas-sort-within-groups.py
Created October 2, 2019 22:32
Pandas: Sort within groups
# Load the Pandas libraries with alias 'pd'
import pandas as pd
# Read csv to dataframe
df = pd.read_csv("data.csv")
# Set column types
df['Submission Date'] = pd.to_datetime(df['Submission Date'], format="%Y-%m-%d %H:%M")
print(df)
@arccoder
arccoder / help.txt
Last active January 23, 2021 21:18
Redact word documents using Python
> python redact.py -h
usage: redact.py [-h] -i INPUT -o OUTPUT -p PATTERNS [-r REPLACE] [-c COLOR]
optional arguments:
-h, --help show this help message and exit
-i INPUT, --input INPUT
Path to the document to be redacted
-o OUTPUT, --output OUTPUT
Path to save the redacted document
-p PATTERNS, --patterns PATTERNS