Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // C++: int floodFill(Mat& image, Mat& mask, Point seedPoint, Scalar newVal, Rect* rect = 0, Scalar loDiff = Scalar(), Scalar upDiff = Scalar(), int flags = 4)
- //
- /**
- * Fills a connected component with the given color.
- *
- * The functions "floodFill" fill a connected component starting from the seed
- * point with the specified color. The connectivity is determined by the
- * color/brightness closeness of the neighbor pixels. The pixel at (x,y) is
- * considered to belong to the repainted domain if:
- * * src(x',y')- loDiff <= src(x,y) <= src(x',y')+ upDiff
- *
- * in case of a grayscale image and floating range
- * * src(seed.x, seed.y)- loDiff <= src(x,y) <= src(seed.x, seed.y)+ upDiff
- *
- * in case of a grayscale image and fixed range
- * * src(x',y')_r- loDiff _r <= src(x,y)_r <= src(x',y')_r+ upDiff _r,
- *
- *
- *
- * src(x',y')_g- loDiff _g <= src(x,y)_g <= src(x',y')_g+ upDiff _g
- *
- * and
- *
- * src(x',y')_b- loDiff _b <= src(x,y)_b <= src(x',y')_b+ upDiff _b
- *
- * in case of a color image and floating range
- * * src(seed.x, seed.y)_r- loDiff _r <= src(x,y)_r <= src(seed.x, seed.y)_r+
- * upDiff _r,
- *
- *
- *
- * src(seed.x, seed.y)_g- loDiff _g <= src(x,y)_g <= src(seed.x, seed.y)_g+
- * upDiff _g
- *
- * and
- *
- * src(seed.x, seed.y)_b- loDiff _b <= src(x,y)_b <= src(seed.x, seed.y)_b+
- * upDiff _b
- *
- * in case of a color image and fixed range
- *
- * where src(x',y') is the value of one of pixel neighbors that is already known
- * to belong to the component. That is, to be added to the connected component,
- * a color/brightness of the pixel should be close enough to:
- * * Color/brightness of one of its neighbors that already belong to the
- * connected component in case of a floating range.
- * * Color/brightness of the seed point in case of a fixed range.
- *
- * Use these functions to either mark a connected component with the specified
- * color in-place, or build a mask and then extract the contour, or copy the
- * region to another image, and so on. Various modes of the function are
- * demonstrated in the "floodfill.cpp" sample.
- *
- * @param image Input/output 1- or 3-channel, 8-bit, or floating-point image. It
- * is modified by the function unless the "FLOODFILL_MASK_ONLY" flag is set in
- * the second variant of the function. See the details below.
- * @param mask (For the second function only) Operation mask that should be a
- * single-channel 8-bit image, 2 pixels wider and 2 pixels taller. The function
- * uses and updates the mask, so you take responsibility of initializing the
- * "mask" content. Flood-filling cannot go across non-zero pixels in the mask.
- * For example, an edge detector output can be used as a mask to stop filling at
- * edges. It is possible to use the same mask in multiple calls to the function
- * to make sure the filled area does not overlap.
- *
- * Note: Since the mask is larger than the filled image, a pixel (x, y) in
- * "image" corresponds to the pixel (x+1, y+1) in the "mask".
- * @param seedPoint a seedPoint
- * @param newVal New value of the repainted domain pixels.
- * @param rect Optional output parameter set by the function to the minimum
- * bounding rectangle of the repainted domain.
- * @param loDiff Maximal lower brightness/color difference between the currently
- * observed pixel and one of its neighbors belonging to the component, or a seed
- * pixel being added to the component.
- * @param upDiff Maximal upper brightness/color difference between the currently
- * observed pixel and one of its neighbors belonging to the component, or a seed
- * pixel being added to the component.
- * @param flags Operation flags. Lower bits contain a connectivity value, 4
- * (default) or 8, used within the function. Connectivity determines which
- * neighbors of a pixel are considered. Upper bits can be 0 or a combination of
- * the following flags:
- * * FLOODFILL_FIXED_RANGE If set, the difference between the current pixel
- * and seed pixel is considered. Otherwise, the difference between neighbor
- * pixels is considered (that is, the range is floating).
- * * FLOODFILL_MASK_ONLY If set, the function does not change the image
- * ("newVal" is ignored), but fills the mask. The flag can be used for the
- * second variant only.
- *
- * @see <a href="http://opencv.itseez.com/modules/imgproc/doc/miscellaneous_transformations.html#floodfill">org.opencv.imgproc.Imgproc.floodFill</a>
- * @see org.opencv.imgproc.Imgproc.findContours
- */
- public static int floodFill(Mat image, Mat mask, Point seedPoint, Scalar newVal, Rect rect, Scalar loDiff, Scalar upDiff, int flags)
- {
- double[] rect_out = new double[4];
- int retVal = n_floodFill(image.nativeObj, mask.nativeObj, seedPoint.x, seedPoint.y, newVal.val[0], newVal.val[1], newVal.val[2], newVal.val[3], rect_out, loDiff.val[0], loDiff.val[1], loDiff.val[2], loDiff.val[3], upDiff.val[0], upDiff.val[1], upDiff.val[2], upDiff.val[3], flags);
- rect.x = (int)rect_out[0]; rect.y = (int)rect_out[1]; rect.width = (int)rect_out[2]; rect.height = (int)rect_out[3];
- return retVal;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement