fixed an energy bug

Energy depends on partition which means local term does too.
added a flag showing if memory for image was allocated
deleting image only if needed
implemented output to an existing image
added imageNetwork constructor from existing image
changed main properly