forked from edward-zhu/umaru
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Edward Zhu
committed
Aug 13, 2015
1 parent
b2c9862
commit 82e7f99
Showing
11 changed files
with
736 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
1/* | ||
samples/* | ||
*.png | ||
*.tif | ||
|
||
.DS_Store | ||
*.dSYM | ||
|
||
# Compiled Lua sources | ||
luac.out | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CMAKE_MINIMUM_REQUIRED(VERSION 2.6 FATAL_ERROR) | ||
CMAKE_POLICY(VERSION 2.6) | ||
FIND_PACKAGE(Torch REQUIRED) | ||
SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
extern "C" { | ||
#include <luaT.h> | ||
#include <TH/TH.h> | ||
} | ||
|
||
#include <cmath> | ||
#include <iostream> | ||
#include <vector> | ||
|
||
static int ctc_print(lua_State * L) | ||
{ | ||
THDoubleTensor * input = (THDoubleTensor *)luaT_checkudata(L, 1, "torch.DoubleTensor"); | ||
int h = input->size[0]; | ||
int w = input->size[1]; | ||
|
||
double * data = THDoubleTensor_data(input); | ||
|
||
for (int i = 0; i < h; i++) { | ||
for (int j = 0; j < w; j++) { | ||
printf("%.4lf\t", data[i * w + j]); | ||
} | ||
printf("\n"); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
static const struct luaL_reg ctc[] = { | ||
{"ctc_print", ctc_print}, | ||
{NULL, NULL} | ||
}; | ||
|
||
LUA_EXTERNC int luaopen_ctc(lua_State *L) { | ||
luaL_openlib(L, "ctc", ctc, 0); | ||
return 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from scipy import misc, ndimage | ||
from scipy.ndimage import filters | ||
import matplotlib.pyplot as plt | ||
from pylab import * | ||
from numpy import * | ||
import PIL | ||
|
||
|
||
|
||
def pil2array(im,alpha=0): | ||
if im.mode=="L": | ||
a = fromstring(im.tostring(),'B') | ||
a.shape = im.size[1],im.size[0] | ||
return a | ||
if im.mode=="RGB": | ||
a = fromstring(im.tostring(),'B') | ||
a.shape = im.size[1],im.size[0],3 | ||
return a | ||
if im.mode=="RGBA": | ||
a = fromstring(im.tostring(),'B') | ||
a.shape = im.size[1],im.size[0],4 | ||
if not alpha: a = a[:,:,:3] | ||
return a | ||
return pil2array(im.convert("L")) | ||
|
||
im = PIL.Image.open('bq01_006-1.png') | ||
im = pil2array(im) | ||
|
||
im = im / 255.0 | ||
|
||
print(im) | ||
|
||
|
||
h = im.shape[0] | ||
w = im.shape[1] | ||
|
||
smooth = filters.gaussian_filter(im, (h * 0.5, h * 1.0), mode='constant') | ||
|
||
smooth += 0.001*filters.uniform_filter(smooth, (h*0.5, w), mode='constant') | ||
|
||
print(smooth.shape) | ||
|
||
a = argmax(smooth, axis=0) | ||
a = filters.gaussian_filter(a, h * 0.3) | ||
|
||
center = array(a,'i') | ||
# print(center) | ||
deltas = abs(arange(h)[:, newaxis] - center[newaxis, :]) | ||
mad = mean(deltas[im != 0]) | ||
r = int(1 + 4 * mad) | ||
|
||
plt.imshow(smooth, cmap=cm.gray) | ||
plot(center) | ||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.