HOME |
Illustrated tour on Po and Netpbm To cut out a figure (an irregular shape) from a color photo and insert that figure into another background such as another color photo is certainly no big news in the history of digital image manipulation so you might wonder why I want to do this operation in such a strange and complicated way. Well it has to do with computer power limitations. In the Gnu/Linux world we have a nice image manipulation program called Gimp. Gimp can cut out a figure from a color photo and insert that figure into another color photo very well, but it won't work with a very limited computer power. Even with 64 MB RAM I sometimes have an image operation that slows down the computer so much that there is no point in trying to adjust things with the mouse. I am practically stalled. Sometimes I can do the same operation on the same computer with a precise netpbm command in just a few. For this experiment I use a computer with 8 MB RAM. This computer wouldn't be able to do anything thing with Gimp. So this is the joy of doing an advanced image editing task with very little computer power, but still with a good result and within reasonable time and effort.The task is to cut out a figure (an irregular shape) from a color photo and insert that figure into another background such as another color photo. Po, which is an SVGAlib paint tool, is not very well suited for doing this for two reasons. Po can not do an irregular selection. And Po only works with 256 colors, witch is not enough for a color photo. With Netpbm tools you can do the operation in full color (24 bit) but here you will need an alpha mask that has the shape of the figure you want to cut out. So the idea here is to use the fine painting tools within Po to draw a strong black line around the figure (in a grayscale implementation of the image). Then with netpbnm extract the black line out from the rest of the grayscale image and from that black line create the mask to finely cut out the figure and passte it into the other color photo with Netpbm tools. There is a lot of Netpbm "gymnastics" involved in that process, but netpbm has the advantage that the commands can be linked together as a 'bash shell script'. (There is a little about shell scripts at the end of the 'text an image page' -here-) So the whole process can be done with the outlining in Po and four shell scripts which in practice means four commands opening the image twice in Po. You can view ore download the scripts used in the process. There are comments inside the script text. The process goes like this: 1. Run popnma which will: Prepare a special grayscale version of the initial image and open Po with that image. 1b. Do the outline in Po with black color with the curves tool and save it. 2. Run popnmb which will: Extract the black line out of the image and open Po with that image. 2b. Fill out the background in Po with the bucket-fill tool and save it. 3. Run popnmc which will: Smooth the edge of the figure a bit. 4. Run puton which will: Insert the figure in to the new background image. The image series below illustrates the process. Maybe it is not possible to judge from this small images, but I think the result is quite good. The Tour |
|
The photo with the figure I would like to cut out. (Yes it is me :-)) ![]() |
The photo I want to use as a new background.![]() |
|
The outline made in Po on a grayscale implementation of the image. |
![]() |
The alpha mask ![]() |
![]() |
|
The resulting image. /Mikkel |