The issue is that ~ (home directory) doesn't work in im4java, so use the full path like /home/yourusername/test.jpg. use full path for image.. specify the output file at the end with addImage("/home/yourusername/test.jpg").
~
im4java
/home/yourusername/test.jpg
addImage("/home/yourusername/test.jpg")