static Image2B binaryImageOutline(IImage2B image) { int w = image.w(), h = image.h(); ret image == null ?: binaryImageFromFunction(w+2, h+2, (x, y) -> !( // white if pixel was black before getBoolPixelDefaultTrue(image, x, y) ? false // otherwise, black if surrounded by at least one black pixel : ( getBoolPixelDefaultTrue(image, x-1, y-1) || getBoolPixelDefaultTrue(image, x, y-1) || getBoolPixelDefaultTrue(image, x+1, y-1) || getBoolPixelDefaultTrue(image, x-1, y) || getBoolPixelDefaultTrue(image, x+1, y) || getBoolPixelDefaultTrue(image, x-1, y+1) || getBoolPixelDefaultTrue(image, x, y+1) || getBoolPixelDefaultTrue(image, x+1, y+1)))); }