Skip to content

Commit

Permalink
I HAVE A DREAM
Browse files Browse the repository at this point in the history
  • Loading branch information
dnery committed Jun 11, 2017
1 parent 5a82802 commit 3458868
Show file tree
Hide file tree
Showing 9 changed files with 46,354 additions and 9 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
*.jpg
*.png
*.gif
*.zip
*.pdf
*.txt
Expand Down
Binary file added assets/arara.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/jacobite.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/lena.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/shapes.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/shapes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 14 additions & 3 deletions display_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,23 @@
## Build graph
print('Rebuilding graph... ', end='', flush=True)

with open('image_as_graph.txt', 'rb') as input:
next(input, '')
with open('image_to_graph.out', 'rb') as input:
dims = next(input, '').split()
rows = int(dims[0])
cols = int(dims[1])
G = nx.read_edgelist(input, nodetype=int)

print('Done.')

print('Making layout... ', end='', flush=True)

layout = {}
for row in range(rows):
for col in range(cols):
layout[row*cols+col] = [col,rows-row]

print('Done.')

## Check results
nx.draw_networkx_edges(G, pos=nx.spring_layout(G))
nx.draw_networkx_edges(G, pos=layout)
pl.show()
11 changes: 8 additions & 3 deletions image_to_graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#include <opencv2/highgui.hpp>

// pixel neighborhood size
#define NSPAN 15
#ifndef NSPAN
#define NSPAN 5
#endif

int main(int argc, char *argv[])
{
Expand Down Expand Up @@ -72,7 +74,7 @@ int main(int argc, char *argv[])
uchar neighbour_value = image.data[irow_n*image.cols+icol_n];

// If the pixels have similarity greater than a certain measure, link them
if (255-std::abs(value-neighbour_value) >= 245) {
if (255-std::abs(value-neighbour_value) >= 253) {
igraph_vector_push_back(&edges, irow*image.cols+icol);
igraph_vector_push_back(&edges, irow_n*image.cols+icol_n);
}
Expand All @@ -95,7 +97,10 @@ int main(int argc, char *argv[])
using std::ofstream;
ofstream graph_file; // output graph to this file

graph_file.open("image_as_graph.txt", ofstream::out|ofstream::trunc);
graph_file.open("image_to_graph.out", ofstream::out|ofstream::trunc);

// Downsampled image dims outputted as header
graph_file << image.rows << " " << image.cols << std::endl;

// Graph is outputted to file as an edgelist
for (igraph_integer_t iedge = 0; iedge < igraph_ecount(&graph); iedge++) {
Expand Down
Loading

0 comments on commit 3458868

Please sign in to comment.