Adding a rigidity mask

Foreword
Adding an individual rigidity coefficient to a pixel
Using an array of floating-point values
Using another image
Operating on a specific area

Foreword

The rigidity parameter which is set at carver activation time (see section Carver activation) normally affects the whole image. It is possible, however, to specify which areas of the image should be affected by using a rigidity mask.

When a rigidity mask is used, each pixel of the image acquires an individual rigidity coefficient, which has to be multiplied with the overall rigidity parameter to get the actual pixel's rigidity. This is useful in some situations to reduce distorsions in specific areas of the image while keeping the seams optimal in other areas.

The library interface to deal with rigidity masks follows very closely the scheme for bias masks as described in the bias section, the main difference being that no equivalent to the bias factor has to be provided (since it is already given in the lqr_carver_init function).

Important

The rigidity mask has to be added always after the LqrCarver initialization and before resizing takes place. (Note that this is different from the bias, which instead can also be added to non-initialised carver objects.)

Important

Whenever a rigidity mask is set, all pixels for which the value is not explicitly defined will have coefficient 0, i.e. the rigidity setting will will be disabled.

Note

All of the functions can be called multiple times, but their effect is not summed up, to the contrary of what happens for the bias functions; instead, new values will substitute old ones when the affected regions overlap.

Adding an individual rigidity coefficient to a pixel

The function to use in order to set the rigidity mask at a given pixel is:

LqrRetVal lqr_carver_rigmask_add_xy(LqrCarver* carver,
 gdouble rigidity,
 gint x,
 gint y);
 

Using an array of floating-point values

It is possible to use a whole array of floating points at once through this function:

LqrRetVal lqr_carver_rigmask_add(LqrCarver* carver,
 gdouble* buffer);
 

Here, buffer is an array contining the rigidity coefficients values, and it is assumed to have the same size as the image loaded in carver.

Note

This function, and all the following, will not swallow the buffer (to the contrary of what happens e.g. when creating a new LqrCarver object and allowing the default behaviour), therefore the buffer must be freed by the user afterwards.

Using another image

The rigidity mask can also be read from an 8-bit rgb buffer. This buffer has to be in the same format as the one used in the 8-bit LqrCarver constructor (but may have a different number of colours per channel). The function is:

LqrRetVal lqr_carver_rigmask_add_rgb(LqrCarver* carver,
 guchar* buffer,
 gint channels);
 

As in the previous case, buffer is assumed to hold and image of the same size as the one in the carver.

The buffer contents will be transformed into floating-points by averaging the colour components and multiplying the result by the alpha channel (transparency) value.

Important

The existence of an alpha channel is inferred from the channels value: if this is 1 or 3, no alpha channel is assumed, if it is 2 or 4, it is assumed that the last channel is holds the alpha value. If this is not what you want, you should resort to one of the previous methods.

Operating on a specific area

The two previously described functions operate on the whole LqrCarver image. It is also possible to access specific image regions in a similar way; for the floating point use:

LqrRetVal lqr_carver_rigmask_add_area(LqrCarver* carver,
 gdouble* buffer,
 gint width,
 gint height,
 gint x_off,
 gint y_off);
 

while for the rgb image use:

LqrRetVal lqr_carver_rigmask_add_rgb_area(LqrCarver* carver,
 guchar* buffer,
 gint channels,
 gint width,
 gint height,
 gint x_off,
 gint y_off);
 

In both functions, width and height are used to specify the size of the area of interest, while x_off and y_off specify its offset. For the rest, both functions work in the same way as their global couterpart.

The provided buffers have to be of size width * height (or width * height * channels for the rgb case) but the specified areas need not to be strictly included inside the LqrCarver image area: only the parts which overlap with it will be used. For example, the offsets can also be negative.