module

CrImage::Operation::MaskApply

Apply a mask to an image

Taking sample image:

Woman with black turtleneck and white background

And mask

Black box with thin horizontal white box at eye level
mask = CrImage::Mask.new(image, false)
mask[50..90, 65..75] = true
mask.to_gray.save("apply_mask_mask.jpg")

image.apply(mask).save("apply_mask.jpg")

image.apply_color(mask, CrImage::Color.of("#00f")).save("apply_mask_color.jpg")

image.apply(mask) do |pixel, channel_type, x, y|
  Math.min(255, pixel + 50).to_u8 if channel_type.blue?
end.save("apply_mask_block.jpg")
Image is blacked out other than thin horizontal bar of the woman's eyes Thin horizontal blue bar over woman's eyes Thin horizantal transparent blue bar over woman's eyes

Instance methods

apply(mask : Mask) : self

Black out all pixels but those found in the mask

Source
apply(mask : Mask, &block : UInt8, ChannelType, Int32, Int32 -> UInt8 | Nil) : self

Apply block to all pixels that match mask, replacing pixel value if block returns non-nil value.

Does not change values not matched by the mask

Source
apply!(mask : Mask) : self

TODO: add apply version that accepts 1+ ChannelType that the mask should apply to (i.e. make a background completely transparent, not just transparent black)

Source
apply!(mask : Mask, &block : UInt8, ChannelType, Int32, Int32 -> UInt8 | Nil) : self
Source
apply_color(mask : Mask, color : Color) : self

Change the color of all pixels that match the mask

Source
apply_color!(mask : Mask, color : Color) : self
Source