Refactor and add possibility to test density image