Skip to content

Instantly share code, notes, and snippets.

View pebbie's full-sized avatar

Peb Ruswono Aryan pebbie

View GitHub Profile
@pebbie
pebbie / bwmorph_thin.py
Created May 10, 2016 17:38 — forked from joefutrelle/bwmorph_thin.py
bwmorph('thin') in Python
import numpy as np
from scipy import ndimage as ndi
# lookup tables for bwmorph_thin
G123_LUT = np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1,
0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0,
1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
@pebbie
pebbie / su.py
Last active April 16, 2024 23:42
Implementation of document binarization algorithm by (Bolan Su et al, 2010)
"""
author: Peb Ruswono Aryan
Binarization Algorithm by Su et al.
@inproceedings{Su:2010:BHD:1815330.1815351,
author = {Su, Bolan and Lu, Shijian and Tan, Chew Lim},
title = {Binarization of Historical Document Images Using the Local Maximum and Minimum},
booktitle = {Proceedings of the 9th IAPR International Workshop on Document Analysis Systems},
series = {DAS '10},
@pebbie
pebbie / roi_selector_pyr.py
Created January 18, 2016 01:19
automatic roi selector based on automatic scale selection fixed at single point
"""
author : Peb Ruswono Aryan
Automatic selection of ROI rectangle based on single point (assumed target center) selection on the image
Automatic scale selection performed by selecting scale which maximizes laplacian of gaussian in the selected point across scales
intended use : simplifying object tracking target selection, output rectangle can be used as initial target
"""
import os
import sys
import cv2
import numpy as np
"""
TBMR : Tree-based morse region
Xu et al, 2013, Tree-Based Morse Regions: A Topological Approach to Local Feature Detection
"""
import sys
import numpy as np
import timeit
def compute_tree(img, isMaxTree=True):
@pebbie
pebbie / abc.py
Created April 30, 2015 08:01
bottom-up a^n.b^n.c^n acceptor
import sys
class Rule:
def __init__(self, lhs, rhs):
self.lhs = lhs
self.rhs = rhs
def __repr__(self):
return "{0} ::== {1}".format(self.lhs, self.rhs)
@pebbie
pebbie / rastore.py
Created March 1, 2015 22:40
Treat a NumPy array as a graph in RDFLib
"""
rastore - virtual RDF data store for rasters
a graph interface from a numpy array into RDF Data Cube
- shape (dimensions)
- element datatype
- elements as rdf list?
- slices? as structured naming of bnode or a slice object?
@pebbie
pebbie / ldfstore.py
Created February 25, 2015 13:24
Wrapper of Linked Data Fragment as a Graph Store in RDFLib
from rdflib.store import Store
from rdflib import Graph, RDF, URIRef, Namespace
import urllib.parse as urlparse
def add_params(origUrl, paramsDict):
url_parts = list(urlparse.urlparse(origUrl))
query = dict(urlparse.parse_qsl(url_parts[4]))
query.update(dict([i for i in iter(paramsDict.items()) if i[1] is not None]))
url_parts[4] = urlparse.urlencode(query)
return urlparse.urlunparse(url_parts)
@pebbie
pebbie / hydra-client.py
Created September 15, 2014 16:22
an attempt to write a console for hydra
import sys
from rdflib import Graph, Namespace
from rdflib.namespace import RDF, RDFS
import requests
HYDRA = Namespace("http://www.w3.org/ns/hydra/core#")
class HydraOperation:
def __init__(self, subj, graph):
self.type = graph.value(subj, RDF.type)
@pebbie
pebbie / rdf2rdf.py
Created September 12, 2014 22:53
rdf-to-rdf format conversion in one line of python code
import sys, rdflib; print rdflib.Graph().parse(sys.argv[1], format=sys.argv[2] if len(sys.argv)>2 else "json-ld").serialize(format=sys.argv[3] if len(sys.argv)>3 else "n3") if len(sys.argv)>1 else "%s <input-file> [<input-format> <output-format>]" % sys.argv[0]
@pebbie
pebbie / dump_ckan.py
Created August 13, 2014 21:00
dump all data from ckan website
"""
call : dump_ckan.py <ckan_website>
ckan_website : e.g. http://data.ukp.go.id
author : Peb Ruswono Aryan
"""
from __future__ import print_function
import json
import os