to flatten images structure