Advertisement
Guest User

floodfill-android-opencv

a guest
Oct 25th, 2011
779
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.38 KB | None | 0 0
  1.     //
  2.     // C++:  int floodFill(Mat& image, Mat& mask, Point seedPoint, Scalar newVal, Rect* rect = 0, Scalar loDiff = Scalar(), Scalar upDiff = Scalar(), int flags = 4)
  3.     //
  4.  
  5.     /**
  6.      * Fills a connected component with the given color.
  7.      *
  8.      * The functions "floodFill" fill a connected component starting from the seed
  9.      * point with the specified color. The connectivity is determined by the
  10.      * color/brightness closeness of the neighbor pixels. The pixel at (x,y) is
  11.      * considered to belong to the repainted domain if:
  12.      *   * src(x',y')- loDiff <= src(x,y) <= src(x',y')+ upDiff
  13.      *
  14.      * in case of a grayscale image and floating range
  15.      *   * src(seed.x, seed.y)- loDiff <= src(x,y) <= src(seed.x, seed.y)+ upDiff
  16.      *
  17.      * in case of a grayscale image and fixed range
  18.      *   * src(x',y')_r- loDiff _r <= src(x,y)_r <= src(x',y')_r+ upDiff _r,
  19.      *
  20.      *
  21.      *
  22.      * src(x',y')_g- loDiff _g <= src(x,y)_g <= src(x',y')_g+ upDiff _g
  23.      *
  24.      * and
  25.      *
  26.      * src(x',y')_b- loDiff _b <= src(x,y)_b <= src(x',y')_b+ upDiff _b
  27.      *
  28.      * in case of a color image and floating range
  29.      *   * src(seed.x, seed.y)_r- loDiff _r <= src(x,y)_r <= src(seed.x, seed.y)_r+
  30.      * upDiff _r,
  31.      *
  32.      *
  33.      *
  34.      * src(seed.x, seed.y)_g- loDiff _g <= src(x,y)_g <= src(seed.x, seed.y)_g+
  35.      * upDiff _g
  36.      *
  37.      * and
  38.      *
  39.      * src(seed.x, seed.y)_b- loDiff _b <= src(x,y)_b <= src(seed.x, seed.y)_b+
  40.      * upDiff _b
  41.      *
  42.      * in case of a color image and fixed range
  43.      *
  44.      * where src(x',y') is the value of one of pixel neighbors that is already known
  45.      * to belong to the component. That is, to be added to the connected component,
  46.      * a color/brightness of the pixel should be close enough to:
  47.      *   * Color/brightness of one of its neighbors that already belong to the
  48.      * connected component in case of a floating range.
  49.      *   * Color/brightness of the seed point in case of a fixed range.
  50.      *
  51.      * Use these functions to either mark a connected component with the specified
  52.      * color in-place, or build a mask and then extract the contour, or copy the
  53.      * region to another image, and so on. Various modes of the function are
  54.      * demonstrated in the "floodfill.cpp" sample.
  55.      *
  56.      * @param image Input/output 1- or 3-channel, 8-bit, or floating-point image. It
  57.      * is modified by the function unless the "FLOODFILL_MASK_ONLY" flag is set in
  58.      * the second variant of the function. See the details below.
  59.      * @param mask (For the second function only) Operation mask that should be a
  60.      * single-channel 8-bit image, 2 pixels wider and 2 pixels taller. The function
  61.      * uses and updates the mask, so you take responsibility of initializing the
  62.      * "mask" content. Flood-filling cannot go across non-zero pixels in the mask.
  63.      * For example, an edge detector output can be used as a mask to stop filling at
  64.      * edges. It is possible to use the same mask in multiple calls to the function
  65.      * to make sure the filled area does not overlap.
  66.      *
  67.      * Note: Since the mask is larger than the filled image, a pixel (x, y) in
  68.      * "image" corresponds to the pixel (x+1, y+1) in the "mask".
  69.      * @param seedPoint a seedPoint
  70.      * @param newVal New value of the repainted domain pixels.
  71.      * @param rect Optional output parameter set by the function to the minimum
  72.      * bounding rectangle of the repainted domain.
  73.      * @param loDiff Maximal lower brightness/color difference between the currently
  74.      * observed pixel and one of its neighbors belonging to the component, or a seed
  75.      * pixel being added to the component.
  76.      * @param upDiff Maximal upper brightness/color difference between the currently
  77.      * observed pixel and one of its neighbors belonging to the component, or a seed
  78.      * pixel being added to the component.
  79.      * @param flags Operation flags. Lower bits contain a connectivity value, 4
  80.      * (default) or 8, used within the function. Connectivity determines which
  81.      * neighbors of a pixel are considered. Upper bits can be 0 or a combination of
  82.      * the following flags:
  83.      *   * FLOODFILL_FIXED_RANGE If set, the difference between the current pixel
  84.      * and seed pixel is considered. Otherwise, the difference between neighbor
  85.      * pixels is considered (that is, the range is floating).
  86.      *   * FLOODFILL_MASK_ONLY If set, the function does not change the image
  87.      * ("newVal" is ignored), but fills the mask. The flag can be used for the
  88.      * second variant only.
  89.      *
  90.      * @see <a href="http://opencv.itseez.com/modules/imgproc/doc/miscellaneous_transformations.html#floodfill">org.opencv.imgproc.Imgproc.floodFill</a>
  91.      * @see org.opencv.imgproc.Imgproc.findContours
  92.      */
  93.     public static int floodFill(Mat image, Mat mask, Point seedPoint, Scalar newVal, Rect rect, Scalar loDiff, Scalar upDiff, int flags)
  94.     {
  95.         double[] rect_out = new double[4];
  96.         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);
  97.         rect.x = (int)rect_out[0]; rect.y = (int)rect_out[1]; rect.width = (int)rect_out[2]; rect.height = (int)rect_out[3];
  98.         return retVal;
  99.     }
  100.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement