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 :-))

tour1.jpg
The photo I want to use as a new background.


tour2.jpg


The outline made in Po on a grayscale implementation of the image.
(A heavy black line around the figure)


tour3.jpg


The line extracted from the rest of the grayscale image. Done with netpbm tools.

tour4.jpg


The outside of the figure filled out with black. That operation is done "manually" in Po with the bucked-fill tool. (I have an idea that this could also be done with some Netpbm tool, but I have not yet figured out how. If anyone has an idea I would be happy to hear about it. ...Yes I already had a comment on the subject read here)

tour5.jpg


The same image but if you look carefully you can see that the edge has been smoothed a little bit so that the figure will not look too "pixelated" on the new background. Done with Netpbm tools.

tour7.jpg




The three images that netpbm tool 'pnmcomp' need to do the image overlay. Note that now the two images to the left have been cropped by Netpbm tools to exactly fit the outline of the figure.





tour6.jpg


The alpha mask
tour7.jpg
tour2.jpg


The resulting image.


tour8.jpg

As sead before you can view ore download the scripts used in the seen above process. Inside the scripts is all the netpbm operations performed and there are comments inside the script text which explains a bit of what are going on. popnma, popnmb, popnmc and puton.

/Mikkel


site map