Method IsBlank
IsBlank(byte)
Determines whether the image is blank (all pixels have the same or similar values within a tolerance).
public bool IsBlank(byte tolerance = 0)
Parameters
tolerancebyteMaximum allowed per-channel absolute difference between pixels (0-255). Default is 0 (exact match required). For GRAY8: absolute difference between gray values. For RGB24/RGBA32: maximum absolute difference across any channel. For BINARY1: tolerance is ignored (pixels are either 0 or 1).
Returns
- bool
trueif all pixels in the image have values within the specified tolerance; otherwise,false.
Remarks
This method efficiently checks if all pixels have similar values by comparing each pixel against the first pixel in the image. The implementation is optimized with separate fast paths for exact matching (tolerance = 0) and tolerant matching.
For BINARY1 images, it checks if all packed bytes are identical (all white or all black). For GRAY8 images, it checks if all bytes differ by at most the tolerance. For RGB24 images, it checks if all R, G, B channels independently differ by at most the tolerance. For RGBA32 images, it checks if all R, G, B, A channels independently differ by at most the tolerance.
Performance: O(n) where n is the number of pixels, but returns early upon finding the first pixel that exceeds the tolerance.
// Check for exact uniformity
bool isExactlyBlank = image.IsBlank();
// Allow slight variations (e.g., for scanned documents with noise)
bool isNearlyBlank = image.IsBlank(tolerance: 10);
IsBlank(IBounds, byte)
Determines whether the specified region of the image is blank (all pixels have the same or similar values within a tolerance).
public bool IsBlank(IBounds bounds, byte tolerance = 0)
Parameters
boundsIBoundsThe rectangular region to check. Coordinates are clamped to the image dimensions.
tolerancebyteMaximum allowed per-channel absolute difference between pixels (0-255). Default is 0 (exact match required). For GRAY8: absolute difference between gray values. For RGB24/RGBA32: maximum absolute difference across any channel.
Returns
- bool
trueif all pixels in the specified region have values within the specified tolerance of the first pixel in the region; otherwise,false. Returnstrueif the clamped region is empty or contains a single pixel.