A ternary tree representation of generalized digital images