OpenSource For You

Extending the concept behind Multicrop

-

The basic sequence of how the Multicrop script works is as follows: ‘Fuzzy’ replaces the background colour by none and the rest by red Actual images will be islands of red surrounded by ‘none’ It extracts each red island and binds or surrounds it in a rectangle It uses the rectangle as a mask on the original image, before extracting the photo A fuzz factor is used to select the background colour. If the value is too high, part of the background of the photo may be lost and the photo may be split into multiple parts. If the value is too low, photos may not be extracted. However, even if a part of the photo is treated as background, as long as the enclosing rectangle is the size of the original photo, you don't have to worry.

The script worked very well with multiple loose photos scanned at one time, as long as there was some gap between the photos and the boundaries.

My problem was that the photos could not be removed from the album without damage. Besides, the background was not uniform, but comprised multiple colours. Hence, in the above sequence, I decided to replace the first step by three others: Select a set of colours from the border Replace each colour by ‘none’

For each background colour - bgcolor as a ( r, g, b) tuple, rename out.mpc and out.cache to in.mpc and in.cache and floodfill; ‘none’ should replace the background colour. A 1x1 pixel border of the background colour is added to ensure floodfilli­ng is from all sides of the image and it is then shaved off.

The next step is to remove the background and replace the remaining image with red. You will get an image similar to what’s shown in Figure 2.

You now need to find a cluster of red pixels. Since your photo will not be very small, rather than searching pixel by pixel, you can speed up the process by a factor of 100 by searching every 10th pixel in each row and column.

Newspapers in English

Newspapers from India