@Test
public void cloudExtractionWithoutDarkPixels() throws Exception {

    GeoTiffReader reader = null;
    FeatureIterator<SimpleFeature> iter = null;
    GridCoverage2D cov = null;
    try {
        reader = new GeoTiffReader(cloudFile);
        cov = reader.read(null);
        // Exclude pixels with luminance less than 20.
        final int referenceLuminance = 10;
        List<Range<Integer>> exclusionRanges = Collections.singletonList(new Range<Integer>(Integer.class, 0, referenceLuminance));
        SimpleFeatureCollection fc = process.execute(cov, exclusionRanges, 10d, false, null,
                true, true, null, null);
        iter = fc.features();
        SimpleFeature feature = iter.next();
        Geometry geometry = (Geometry) feature.getDefaultGeometry();
        Raster raster = cov.getRenderedImage().getData();
        int[] darkPixel = new int[3];
        // These positions identify a couple of dark pixels of the cloud edge
        raster.getPixel(9, 13, darkPixel);
        double luminance = ImageUtilities.RGB_TO_GRAY_MATRIX[0][0] * darkPixel[0]
                + ImageUtilities.RGB_TO_GRAY_MATRIX[0][1] * darkPixel[1]
                + ImageUtilities.RGB_TO_GRAY_MATRIX[0][2] * darkPixel[2];
        assertTrue(luminance < referenceLuminance);
        raster.getPixel(15, 7, darkPixel);
        luminance = ImageUtilities.RGB_TO_GRAY_MATRIX[0][0] * darkPixel[0]
                + ImageUtilities.RGB_TO_GRAY_MATRIX[0][1] * darkPixel[1]
                + ImageUtilities.RGB_TO_GRAY_MATRIX[0][2] * darkPixel[2];
        assertTrue(luminance < referenceLuminance);
        // The computed polygon should have different shape due to dark pixels being excluded
        assertFalse(referenceGeometry.equalsExact(geometry, TOLERANCE));
    } finally {
        if (iter != null) {
            iter.close();
        }
        if (reader != null) {
            try {
                reader.dispose();
            } catch (Throwable t) {
            }
        }
        if (cov != null) {
            try {
                cov.dispose(true);
            } catch (Throwable t) {
            }
        }
    }
}