예제 #1
0
파일: test_grey.py 프로젝트: fmg30/diss
 def setUp(self):
     self.black_pixel = 255 * np.ones((4, 4), dtype=np.uint8)
     self.black_pixel[1, 1] = 0
     self.white_pixel = 255 - self.black_pixel
     self.selems = [
         selem.square(2),
         selem.rectangle(2, 2),
         selem.rectangle(2, 1),
         selem.rectangle(1, 2)
     ]
예제 #2
0
 def test_rectangle_selem(self):
     """Test rectangle structuring elements"""
     for i in range(0, 5):
         for j in range(0, 5):
             actual_mask = selem.rectangle(i, j)
             expected_mask = np.ones((i, j), dtype='uint8')
             assert_equal(expected_mask, actual_mask)
예제 #3
0
 def test_rectangle_selem(self):
     """Test rectangle structuring elements"""
     for i in range(0, 5):
         for j in range(0, 5):
             actual_mask = selem.rectangle(i, j)
             expected_mask = np.ones((i, j), dtype='uint8')
             assert_equal(expected_mask, actual_mask)
예제 #4
0
def _define_kernel(shape, size, dtype):
    """Build a kernel to apply a filter on images.

    Parameters
    ----------
    shape : str
        Shape of the kernel used to compute the filter ('diamond', 'disk',
        'rectangle' or 'square').
    size : int, Tuple(int) or List(int)
        The size of the kernel:
            - For the rectangle we expect two values (width, height).
            - For the square one value (width).
            - For the disk and the diamond one value (radius).
    dtype : type
        Dtype used for the kernel (the same as the image).

    Returns
    -------
    kernel : skimage.morphology.selem object
        Kernel to use with a skimage filter.

    """
    # build the kernel
    if shape == "diamond":
        kernel = diamond(size, dtype=dtype)
    elif shape == "disk":
        kernel = disk(size, dtype=dtype)
    elif shape == "rectangle" and isinstance(size, tuple):
        kernel = rectangle(size[0], size[1], dtype=dtype)
    elif shape == "square":
        kernel = square(size, dtype=dtype)
    else:
        raise ValueError("Kernel definition is wrong.")

    return kernel
예제 #5
0
def _define_kernel(shape, size, dtype):
    """Build a kernel to apply a filter on images.

    Parameters
    ----------
    shape : str
        Shape of the kernel used to compute the filter (`diamond`, `disk`,
        `rectangle` or `square`).
    size : int, Tuple(int) or List(int)
        The size of the kernel:
            - For the rectangle we expect two values (`height`, `width`).
            - For the square one value (`width`).
            - For the disk and the diamond one value (`radius`).
    dtype : type
        Dtype used for the kernel (the same as the image).

    Returns
    -------
    kernel : skimage.morphology.selem object
        Kernel to use with a skimage filter.

    """
    # build the kernel
    if shape == "diamond":
        kernel = diamond(size, dtype=dtype)
    elif shape == "disk":
        kernel = disk(size, dtype=dtype)
    elif shape == "rectangle" and isinstance(size, (tuple, list)):
        kernel = rectangle(size[0], size[1], dtype=dtype)
    elif shape == "square":
        kernel = square(size, dtype=dtype)
    else:
        raise ValueError("Kernel definition is wrong. Shape of the kernel "
                         "should be 'diamond', 'disk', 'rectangle' or "
                         "'square'. Not {0}.".format(shape))

    return kernel
예제 #6
0
 def setUp(self):
     self.black_pixel = 255 * np.ones((4, 4), dtype=np.uint8)
     self.black_pixel[1, 1] = 0
     self.white_pixel = 255 - self.black_pixel
     self.selems = [selem.square(2), selem.rectangle(2, 2),
                    selem.rectangle(2, 1), selem.rectangle(1, 2)]
예제 #7
0
 def test_rectangle_selem(self):
     for i in range(0, 5):
         for j in range(0, 5):
             actual_mask = selem.rectangle(i, j)
             expected_mask = np.ones((i, j), dtype="uint8")
             assert_equal(expected_mask, actual_mask)
예제 #8
0
 def erode_patch(self, patch):
     k = np.random.randint(0, 3) * 2 + 3  # 3, 5, 7
     return 255 * binary_erosion(patch, selem=selem.rectangle(k, k))