Seamcarving your own images

I tried using my algorithm on some other downloaded images (*.ppm). I moved them to the same directory as test images from the project. But for some reason neither the carve_debug nor carve_opt worked. You can see, how it looks for me in the terminal. In the first line I added some common test with owl.ppm. These “1” at the start of the line are red, so I assume they represent some error code.

prog2@prog2 /media/sf_Cproject(2)/project2 % ./bin/carve_opt -n150 test/data/owl.ppm
prog2@prog2 /media/sf_Cproject(2)/project2 % ./bin/carve_debug -n1 test/data/sample1.ppm
1 prog2@prog2 /media/sf_Cproject(2)/project2 % ./bin/carve_opt -n1 test/data/sample1.ppm
1 prog2@prog2 /media/sf_Cproject(2)/project2 % : (

By the way, I tested all the ppm images wich come with the project archive. And all of my tests were successful. Thus, please let me know if I have to do this kind of tests in different way.

The 1 means that the application exited with EXIT_FAILURE which is error code 1.
This is most likely due to the wrong file format.

There are two likely causes:

  1. The files you downloaded are in P6 binary PPM format.
    This file format is also called ppm and stores each pixel’s color one after the other.
    But instead of decimal numbers, the bytes are written directly. The file read method does not handle such ppm files.
  2. Some programs add comments to ppm files in lines starting with #. The read method can not handle comments.

The solution is to convert the files to P3 PPM files using imagemagic or GIMP and remove comments by hand or using the sed command.

You can also use the plugin provided to do all these steps automatically.

I have written how to do this here:

For those, who are interested: I did a small script for converting own images to a valid ppm format (using the commands and packages you mentioned earlier @Marcel.Ullrich).
You could check it out here, download it to your VM and give it execution permissions by running

chmod +x convert_ppm.sh

and then converting custom jpegs by using the script as follows:

./convert_ppm.sh <src file> <dst file>

Hope that makes it easier for some people to experiment with the written algorithm, also for larger images. :smiley: