Skip to content

Instantly share code, notes, and snippets.

erogol / readDataFromPath.m
Created April 28, 2013 18:04
Read images into matrix from two layer folder structure
function [images, images_RGB] = readDataFromPath(DataPath, image_size)
% Reads the image content of the given rootpath. Assumes that we have a
% root folder includes sub folder for each class of images
images = {};
images_RGB = {};
root_dir = dir(DataPath);
root_dir = root_dir([root_dir.isdir]);
folder_names = {};
root_dir = root_dir(~ismember(folder_names,{'.','..'}))
erogol / gridsplit.m
Last active December 22, 2015 00:28
function im_array=gridsplit(im,grid_x,grid_y,width_fact,height_fact,left_extra,right_extra,top_extra,bottom_extra)
%Crops a grid of images out of one image
% im_array=gridsplit(im,...) returns an image array im_array that has
% size (MxNxPxR) in which M the width, N the height, P the channel and R
% the amount of images destilled from the grid. So it puts all the
% gridparts in R which has size (grid_x*grid_y)
% You get the idea. Otherwise more info on:
% grid_x = Amount of horizontal patches
% grid_y = Amount of vertical patches
erogol / WTA_kernel_binary
Created August 30, 2013 16:06
Google's Winner Takes All hashing implemmentation
function[binary_codes,G_vecs] = WTA_kernel_binary(X,G_vecs,G, K)
% G is number of permutation vectors
% K is the insterest span
if size(G_vecs,1) == 0
G_vec = zeros(G,size(X,2));
for i = 1:G
G_vecs(i,:) = randperm(size(X,2),size(X,2));
function[ROOT_DIR] = read_dir(PATH)
% video_names = ls(fullfile(PATH,'*.mp4'));
file_names = {};
ROOT_DIR = ROOT_DIR(~ismember(file_names,{'.','..'}));
erogol / normalize_data.m
Created September 3, 2013 15:06
Data normalization columnwise
% Normalize data columnwise to reduce different unit's effect
function[X_norm, val] = normalize_data(X,val)
% if ~exist('va','var')
% [val,ind] = max(X,[],1);
% end
% X_norm = bsxfun(@rdivide, X, val);
erogol / zscore_normalize_data.m
Created September 3, 2013 15:06
Z-score Normalization of data
function[X_norm, mu, sigma] = zscore_normalize_data(X, mu, sigma)
erogol /
Last active December 22, 2015 10:09
scrap imdb to get non-dublicate movies of given categories
import urllib2
from BeautifulSoup import BeautifulSoup
import pdb
import os
import htmlentitydefs
from BeautifulSoup import BeautifulStoneSoup
import HTMLParser
import cgi
erogol /
Last active February 22, 2019 19:05
find the youtube video and downlaod convert to matlab readable format avi from mp4
This code stupidly take the lined list of movie names, suppossely scraped from imdb
and download them as a first instance of YouTube. It also converts the downloaded video mp4
to avi version to be processed in Matlab.
erogol -
It needs;
Beautifulsoup : easy_install BeautifulSoup -- for scraping
erogol / GMM.m
Created September 9, 2013 13:14
function mix = gmm(dim, ncentres, covar_type, ppca_dim)
%GMM Creates a Gaussian mixture model with specified architecture.
% Description
% MIX = GMM(DIM, NCENTRES, COVARTYPE) takes the dimension of the space
% DIM, the number of centres in the mixture model and the type of the
% mixture model, and returns a data structure MIX. The mixture model
% type defines the covariance structure of each component Gaussian:
% 'spherical' = single variance parameter for each component: stored as a vector
% 'diag' = diagonal matrix for each component: stored as rows of a matrix
erogol / rdir.m
Created September 20, 2013 18:19
discover file paths recursively to the deeps of your computer given the root folder
function [varargout] = rdir(rootdir,varargin)
% Lists the files in a directory and its sub directories.
% function [D] = rdir(ROOT,TEST)
% Recursive directory listing.
% ROOT is the directory starting point and includes the
% wildcard specification.
% The function returns a structure D similar to the one