I want to transform a picture into a square matrix with NxN dimension. The elements of the matrix are represented by 0 (red color) or 1 (blue color), from the figure below.
n = 128; (*dimension of matrix*)
f[i_, j_] := (*rule to generated the tube*)
s = SparseArray[{{i_, j_} -> f[i, j]}, {n, n}]; (*matrix*)
MatrixForm[s];
I tried to implement several routines for f[i_,j_], but none of them worked. Can anybody help me?




