-
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
1 parent
c25d499
commit 70a926d
Showing
7 changed files
with
223 additions
and
5 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <stdio.h> | ||
|
||
int main( | ||
int argc, char* argv[]) { | ||
int (*f)(int a) { | ||
int g(int b) { | ||
return a+b; | ||
} | ||
|
||
return g; | ||
} | ||
|
||
return 0; | ||
} |
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 @@ | ||
#! /bin/bash | ||
|
||
g++ -std=c++11 -Wall test_currying.cpp -o test_currying | ||
echo "Compiled 'test_currying.cpp'" |
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,16 @@ | ||
#include <iostream> | ||
|
||
int main(int argc, char* argv[]) { | ||
auto f = [](int a) { | ||
auto g = [a](int b) { | ||
return a+b; | ||
}; | ||
return g; | ||
}; | ||
|
||
auto g = f(4); | ||
|
||
std::cout << "g(3): " << g(3) << std::endl; | ||
|
||
return 0; | ||
} |
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,70 @@ | ||
#! /usr/bin/python3 | ||
|
||
# -*- coding: utf-8 -*- | ||
|
||
import os | ||
|
||
import numpy as np | ||
|
||
from PIL import Image | ||
|
||
if __name__ == "__main__": | ||
from os.path import expanduser | ||
home = expanduser("~") | ||
print("home: {}".format(home)) | ||
|
||
path_images = home+"/Pictures/tiles_images/" | ||
|
||
img = Image.open(path_images+"smm_smb3_tiles.png") | ||
pix = np.array(img) | ||
|
||
tw = 16 # tile width | ||
th = 16 # tile height | ||
tiles_x = 4 | ||
tiles_y = 3 | ||
pix_tiles = np.zeros((th*tiles_y, tw*tiles_x, 3), dtype=np.uint8) | ||
|
||
# get all tiles per indices | ||
choose_tiles = [[0, 1, 0, 0], | ||
[0, 2, 0, 1], | ||
[0, 4, 0, 2], | ||
[5, 6, 0, 3], | ||
[0, 17, 1, 0], | ||
[0, 18, 1, 1], | ||
[0, 20, 1, 2], | ||
[5, 22, 1, 3], | ||
[0, 33, 2, 0], | ||
[0, 34, 2, 1], | ||
[0, 36, 2, 2], | ||
[5, 38, 2, 3]] | ||
|
||
for ts_y, ts_x, t_y, t_x in choose_tiles: | ||
pix_tiles[th*t_y:th*(t_y+1), tw*t_x:tw*(t_x+1)] = \ | ||
pix[(th+1)*ts_y+1:(th+1)*ts_y+th+1, (tw+1)*ts_x+1:(tw+1)*ts_x+tw+1] | ||
|
||
img_tiles = Image.fromarray(pix_tiles) | ||
img_tiles.show() | ||
|
||
img_anime = Image.open(path_images+"anime_1.jpeg") | ||
img_anime.show() | ||
|
||
pix_anime = np.array(img_anime) | ||
print("pix_anime.shape: {}".format(pix_anime.shape)) | ||
anim_h, anim_w, anim_c = pix_anime.shape | ||
|
||
pix_anime = pix_anime[:(anim_h//th)*th, :(anim_w//tw)*tw] | ||
print("pix_anime.shape: {}".format(pix_anime.shape)) | ||
|
||
# transform pix_tiles so that it will be like a | ||
# (tiles_y, tiles_x, th, tw, 3) shape | ||
x, y, z = pix_tiles.shape | ||
print("pix_tiles.shape: {}".format(pix_tiles.shape)) | ||
|
||
pix_tiles_own = pix_tiles.transpose(0, 2, 1) | ||
pix_tiles_own = pix_tiles_own.reshape((th, z*x//th, y)) | ||
pix_tiles_own = pix_tiles_own.transpose(0, 2, 1) | ||
pix_tiles_own = pix_tiles_own.reshape((x*y//th//tw, th, tw, z)) | ||
pix_tiles_own = pix_tiles_own.transpose(0, 2, 1, 3) | ||
pix_tiles_own = pix_tiles_own.reshape((x//th, y//tw, th, tw, z)) | ||
|
||
print("pix_tiles_own.shape: {}".format(pix_tiles_own.shape)) |
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,71 @@ | ||
# bs...border_size | ||
def get_derivatives_box(pix, pix_integral, bs, s=1): | ||
# First do the x-derivative | ||
# h...height | ||
# w...width | ||
h, w = pix.shape | ||
|
||
deriv_x_right = pix_integral[bs-s :bs+h-s , bs+1 :bs+w+1] \ | ||
+pix_integral[bs+s+1:bs+h+s+1, bs+1+s:bs+w+1+s] \ | ||
-pix_integral[bs-s :bs+h-s , bs+1+s:bs+w+1+s] \ | ||
-pix_integral[bs+s+1:bs+h+s+1, bs+1 :bs+w+1] | ||
deriv_x_left = pix_integral[bs-s :bs+h-s , bs-s :bs+w-s] \ | ||
+pix_integral[bs+s+1:bs+h+s+1, bs :bs+w] \ | ||
-pix_integral[bs-s :bs+h-s , bs :bs+w] \ | ||
-pix_integral[bs+s+1:bs+h+s+1, bs-s :bs+w-s] | ||
|
||
deriv_y_right = pix_integral[bs+1 :bs+h+1 , bs-s :bs+w-s ] \ | ||
+pix_integral[bs+1+s:bs+h+1+s, bs+s+1:bs+w+s+1] \ | ||
-pix_integral[bs+1+s:bs+h+1+s, bs-s :bs+w-s ] \ | ||
-pix_integral[bs+1 :bs+h+1 , bs+s+1:bs+w+s+1] | ||
deriv_y_left = pix_integral[bs-s :bs+h-s , bs-s :bs+w-s ] \ | ||
+pix_integral[bs :bs+h , bs+s+1:bs+w+s+1] \ | ||
-pix_integral[bs :bs+h , bs-s :bs+w-s ] \ | ||
-pix_integral[bs-s :bs+h-s , bs+s+1:bs+w+s+1] | ||
|
||
deriv_x = deriv_x_right-deriv_x_left | ||
deriv_y = deriv_y_right-deriv_y_left | ||
|
||
print("Needed time for deriv other: {:.4f}".format(end_time-start_time)) | ||
|
||
return deriv_x, deriv_y | ||
|
||
def get_derivatives_box_tiles(tile_h, tile_w, pix_integral, bs, s=1, offset=0): | ||
# First do the x-derivative | ||
# h...height | ||
# w...width | ||
h, w = tile_h, tile_w | ||
# print("bs: {}".format(bs)) | ||
# print("pix.shape: {}".format(pix.shape)) | ||
# offset = 1 | ||
bs_l = bs-offset | ||
bs_h = bs+offset | ||
|
||
v_1 = pix_integral[:, bs_l-s :bs_h+h-s , bs_l+1 :bs_h+w+1] | ||
v_2 = pix_integral[:, bs_l+s+1:bs_h+h+s+1, bs_l+1+s:bs_h+w+1+s] | ||
v_3 = pix_integral[:, bs_l-s :bs_h+h-s , bs_l+1+s:bs_h+w+1+s] | ||
v_4 = pix_integral[:, bs_l+s+1:bs_h+h+s+1, bs_l+1 :bs_h+w+1] | ||
print("v_1.shape: {}".format(v_1.shape)) | ||
print("v_2.shape: {}".format(v_2.shape)) | ||
print("v_3.shape: {}".format(v_3.shape)) | ||
print("v_4.shape: {}".format(v_4.shape)) | ||
deriv_x_right = v_1+v_2-v_3-v_4 | ||
v_1 = pix_integral[:, bs_l-s :bs_h+h-s , bs_l-s :bs_h+w-s] | ||
v_2 = pix_integral[:, bs_l+s+1:bs_h+h+s+1, bs_l :bs_h+w] | ||
v_3 = pix_integral[:, bs_l-s :bs_h+h-s , bs_l :bs_h+w] | ||
v_4 = pix_integral[:, bs_l+s+1:bs_h+h+s+1, bs_l-s :bs_h+w-s] | ||
deriv_x_left = v_1+v_2-v_3-v_4 | ||
|
||
deriv_y_right = pix_integral[:, bs_l+1 :bs_h+h+1 , bs_l-s :bs_h+w-s ] \ | ||
+pix_integral[:, bs_l+1+s:bs_h+h+1+s, bs_l+s+1:bs_h+w+s+1] \ | ||
-pix_integral[:, bs_l+1+s:bs_h+h+1+s, bs_l-s :bs_h+w-s ] \ | ||
-pix_integral[:, bs_l+1 :bs_h+h+1 , bs_l+s+1:bs_h+w+s+1] | ||
deriv_y_left = pix_integral[:, bs_l-s :bs_h+h-s , bs_l-s :bs_h+w-s ] \ | ||
+pix_integral[:, bs_l :bs_h+h , bs_l+s+1:bs_h+w+s+1] \ | ||
-pix_integral[:, bs_l :bs_h+h , bs_l-s :bs_h+w-s ] \ | ||
-pix_integral[:, bs_l-s :bs_h+h-s , bs_l+s+1:bs_h+w+s+1] | ||
|
||
deriv_x = deriv_x_right-deriv_x_left | ||
deriv_y = deriv_y_right-deriv_y_left | ||
|
||
return deriv_x, deriv_y |
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,15 @@ | ||
#! /usr/bin/python3.5 | ||
|
||
def f(a): | ||
def g(b): | ||
return a+b | ||
return g | ||
|
||
f1 = f(3) | ||
f2 = f(6) | ||
|
||
print("f1(4): {}".format(f1(4))) | ||
print("f2(4): {}".format(f2(4))) | ||
|
||
print("f(3)(4): {}".format(f(3)(4))) | ||
print("f(6)(4): {}".format(f(6)(4))) |