Exemple #1
0
def test_smallest_selem16():
    # check that min, max and mean returns identity if structuring element
    # contains only central pixel

    image = np.zeros((5, 5), dtype=np.uint16)
    out = np.zeros_like(image)
    mask = np.ones_like(image, dtype=np.uint8)
    image[2, 2] = 255
    image[2, 3] = 128
    image[1, 2] = 16

    elem = np.array([[1]], dtype=np.uint8)
    rank.mean(image=image,
              selem=elem,
              out=out,
              mask=mask,
              shift_x=0,
              shift_y=0)
    assert_equal(image, out)
    rank.minimum(image=image,
                 selem=elem,
                 out=out,
                 mask=mask,
                 shift_x=0,
                 shift_y=0)
    assert_equal(image, out)
    rank.maximum(image=image,
                 selem=elem,
                 out=out,
                 mask=mask,
                 shift_x=0,
                 shift_y=0)
    assert_equal(image, out)
def trim(image):
    '''transforms the given image to crop and orient the strips'''
    scale_factor = 5
    temp = rgb2gray(image)
    temp = downscale_local_mean(temp, (scale_factor, scale_factor))

    e = rank.entropy(temp, disk(10))
    fred = binary_fill_holes(e > threshold_isodata(e))
    fred = rank.minimum(fred, disk(10))
    labels = label(fred)

    props = regionprops(labels)
    areas = [prop['area'] for prop in props]
    selection = labels == props[np.argmax(areas)]['label']
    angles = np.linspace(-45, 45)
    rotations = [rotate(selection, angle, resize=True) for angle in angles]
    props = [regionprops(label(r)) for r in rotations]
    bboxes = [prop[0]['bbox'] for prop in props]
    areas = [(bbox[2] - bbox[0]) * (bbox[3] - bbox[1]) for bbox in bboxes]
    best = np.argmin(areas)

    rotated = rotations[best]
    mask = rank.minimum(rotated, square(10)) > 0

    bbox = np.array(regionprops(label(mask))[0]['bbox'])
    rmin, cmin, rmax, cmax = bbox * scale_factor

    transformed = rotate(image, angles[best], resize=True)
    transformed = transformed[rmin:rmax, cmin:cmax]
    return transformed
Exemple #3
0
def test_empty_selem():
    # check that min, max and mean returns zeros if structuring element is
    # empty

    image = np.zeros((5, 5), dtype=np.uint16)
    out = np.zeros_like(image)
    mask = np.ones_like(image, dtype=np.uint8)
    res = np.zeros_like(image)
    image[2, 2] = 255
    image[2, 3] = 128
    image[1, 2] = 16

    elem = np.array([[0, 0, 0], [0, 0, 0]], dtype=np.uint8)

    rank.mean(image=image,
              selem=elem,
              out=out,
              mask=mask,
              shift_x=0,
              shift_y=0)
    assert_equal(res, out)
    rank.minimum(image=image,
                 selem=elem,
                 out=out,
                 mask=mask,
                 shift_x=0,
                 shift_y=0)
    assert_equal(res, out)
    rank.maximum(image=image,
                 selem=elem,
                 out=out,
                 mask=mask,
                 shift_x=0,
                 shift_y=0)
    assert_equal(res, out)
Exemple #4
0
def test_empty_selem():
    # check that min, max and mean returns zeros if structuring element is
    # empty

    image = np.zeros((5, 5), dtype=np.uint16)
    out = np.zeros_like(image)
    mask = np.ones_like(image, dtype=np.uint8)
    res = np.zeros_like(image)
    image[2, 2] = 255
    image[2, 3] = 128
    image[1, 2] = 16

    elem = np.array([[0, 0, 0], [0, 0, 0]], dtype=np.uint8)

    rank.mean(image=image, selem=elem, out=out, mask=mask,
              shift_x=0, shift_y=0)
    assert_equal(res, out)
    rank.geometric_mean(image=image, selem=elem, out=out, mask=mask,
                        shift_x=0, shift_y=0)
    assert_equal(res, out)
    rank.minimum(image=image, selem=elem, out=out, mask=mask,
                 shift_x=0, shift_y=0)
    assert_equal(res, out)
    rank.maximum(image=image, selem=elem, out=out, mask=mask,
                 shift_x=0, shift_y=0)
    assert_equal(res, out)
Exemple #5
0
def test_compare_with_grey_erosion():
    # compare the result of maximum filter with erode

    image = (np.random.rand(100, 100) * 256).astype(np.uint8)
    out = np.empty_like(image)
    mask = np.ones(image.shape, dtype=np.uint8)

    for r in range(3, 20, 2):
        elem = np.ones((r, r), dtype=np.uint8)
        rank.minimum(image=image, selem=elem, out=out, mask=mask)
        cm = grey.erosion(image=image, selem=elem)
        assert_equal(out, cm)
Exemple #6
0
def test_compare_with_grey_erosion():
    # compare the result of maximum filter with erode

    image = (np.random.rand(100, 100) * 256).astype(np.uint8)
    out = np.empty_like(image)
    mask = np.ones(image.shape, dtype=np.uint8)

    for r in range(3, 20, 2):
        elem = np.ones((r, r), dtype=np.uint8)
        rank.minimum(image=image, selem=elem, out=out, mask=mask)
        cm = grey.erosion(image=image, selem=elem)
        assert_equal(out, cm)
Exemple #7
0
def test_percentile_min():
    # check that percentile p0 = 0 is identical to local min
    img = data.camera()
    img16 = img.astype(np.uint16)
    selem = disk(15)
    # check for 8bit
    img_p0 = rank.percentile(img, selem=selem, p0=0)
    img_min = rank.minimum(img, selem=selem)
    assert_equal(img_p0, img_min)
    # check for 16bit
    img_p0 = rank.percentile(img16, selem=selem, p0=0)
    img_min = rank.minimum(img16, selem=selem)
    assert_equal(img_p0, img_min)
Exemple #8
0
def test_percentile_min():
    # check that percentile p0 = 0 is identical to local min
    img = data.camera()
    img16 = img.astype(np.uint16)
    selem = disk(15)
    # check for 8bit
    img_p0 = rank.percentile(img, selem=selem, p0=0)
    img_min = rank.minimum(img, selem=selem)
    assert_equal(img_p0, img_min)
    # check for 16bit
    img_p0 = rank.percentile(img16, selem=selem, p0=0)
    img_min = rank.minimum(img16, selem=selem)
    assert_equal(img_p0, img_min)
Exemple #9
0
def minimumPixelIntensityNeighborhoodFiltering(s,params):
    logging.info(f"{s['filename']} - \tLightDarkModule.minimumPixelNeighborhoodFiltering")
    disk_size = int(params.get("disk_size", 10000))
    threshold = int(params.get("upper_threshold", 200))

    img = s.getImgThumb(s["image_work_size"])
    img = color.rgb2gray(img)
    img = (img * 255).astype(np.uint8)
    selem = disk(disk_size)

    imgfilt = rank.minimum(img, selem)
    s["img_mask_bright"] = imgfilt > threshold


    if strtobool(params.get("invert", "True")):
        s["img_mask_bright"] = ~s["img_mask_bright"]

    prev_mask = s["img_mask_use"]
    s["img_mask_use"] = s["img_mask_use"] & s["img_mask_bright"]

    io.imsave(s["outdir"] + os.sep + s["filename"] + "_bright.png", img_as_ubyte(prev_mask & ~s["img_mask_bright"]))

    s.addToPrintList("brightestPixels",
                     printMaskHelper(params.get("mask_statistics", s["mask_statistics"]), prev_mask, s["img_mask_use"]))

    if len(s["img_mask_use"].nonzero()[0]) == 0:  # add warning in case the final tissue is empty
        logging.warning(f"{s['filename']} - After LightDarkModule.minimumPixelNeighborhoodFiltering NO tissue "
                        f"remains detectable! Downstream modules likely to be incorrect/fail")
        s["warnings"].append(f"After LightDarkModule.minimumPixelNeighborhoodFiltering NO tissue remains "
                             f"detectable! Downstream modules likely to be incorrect/fail")

    return
Exemple #10
0
    def __otsu_method(
            image: Union[np.ndarray, Iterable, np.uint8]) -> np.ndarray:
        selem = disk(20)
        t_otsu = otsu(image, selem=selem)
        print(t_otsu)
        imshow(t_otsu)
        # th_motsu = threshold_multiotsu(image, classes=2)
        # im = np.digitize(image, bins=th_motsu)
        # imshow(im)
        plt.show()
        test = (image * 255 + 15) <= t_otsu
        result = np.zeros(image.shape, dtype=np.uint8)
        for i, l in enumerate(test):
            for j, v in enumerate(l):
                if v:
                    result[i, j] = 255
        imshow(result)
        plt.show()
        # result = gaussian(gaussian(result, 7), 7)
        result = gaussian(result, 7)
        imshow(result)
        plt.show()
        result = minimum(maximum(result, disk(5)), disk(12))
        imshow(result)
        plt.show()
        result = gaussian(result, 3)
        imshow(result)
        plt.show()

        # return self.__ending(gaussian(self.__ending(result), 7))
        # return self.__ending(result)
        return result
Exemple #11
0
 def calculate(self, image: np.ndarray, mask: np.ndarray,
               **kwargs) -> np.ndarray:
     # imshow(image)
     # plt.show()
     stream = kwargs["stream"]
     progress = kwargs["progress"]
     lap = maximum(minimum(image, disk(8)), disk(5))
     progress.progress(30)
     # imshow(lap)
     # plt.show()
     stream[1].append(lap)
     stream[0].image(stream[1], width=300)
     res = meijering(lap)
     progress.progress(60)
     # imshow(res)
     # plt.show()
     stream[1].append(res)
     stream[0].image(stream[1], width=300)
     for i, l in enumerate(res):
         for j, v in enumerate(l):
             if v >= 0.15:
                 res[i, j] = 1.0
             else:
                 res[i, j] = 0.0
         progress.progress(60 + int(40 * ((i + 1) / len(res))))
     # imshow(res)
     # plt.show()
     # stream[1].append(res)
     # stream[0].image(stream[1], width=300)
     return res
Exemple #12
0
def minimum_filter(image, kernel_shape, kernel_size):
    """Apply a minimum filter to a 2-d image.

    Parameters
    ----------
    image : np.ndarray, np.uint
        Image with shape (y, x).
    kernel_shape : str
        Shape of the kernel used to compute the filter ('diamond', 'disk',
        'rectangle' or 'square').
    kernel_size : int or Tuple(int)
        The size of the kernel. For the rectangle we expect two integers
        (width, height).

    Returns
    -------
    image_filtered : np.ndarray, np.uint
        Filtered 2-d image with shape (y, x).

    """
    # check parameters
    check_array(image, ndim=2, dtype=[np.uint8, np.uint16])
    check_parameter(kernel_shape=str, kernel_size=(int, tuple, list))

    # get kernel
    kernel = _define_kernel(shape=kernel_shape,
                            size=kernel_size,
                            dtype=image.dtype)

    # apply filter
    image_filtered = rank.minimum(image, kernel)

    return image_filtered
Exemple #13
0
def minimum_image(image_array,
                  windows_size,
                  window_shape="square",
                  im_show=True):
    """The lower algorithm complexity makes skimage.filters.rank.minimum more efficient for larger images and structuring elements.

    Parameters
    ----------
    image_array:numpy.array:
        input image

    windows_size:int
        the size of window

    window_shape: str
        str is element from dict:{square, disk}

    im_show : Bool
        if True show result

    """
    check_windows_size(windows_size)
    kernel = make_kernel(window_shape, windows_size)

    #min
    img = minimum(image_array, kernel)

    #show image
    if im_show:
        show_image(img)
Exemple #14
0
def test_smallest_selem16():
    # check that min, max and mean returns identity if structuring element
    # contains only central pixel

    image = np.zeros((5, 5), dtype=np.uint16)
    out = np.zeros_like(image)
    mask = np.ones_like(image, dtype=np.uint8)
    image[2, 2] = 255
    image[2, 3] = 128
    image[1, 2] = 16

    elem = np.array([[1]], dtype=np.uint8)
    rank.mean(image=image, selem=elem, out=out, mask=mask, shift_x=0, shift_y=0)
    assert_equal(image, out)
    rank.minimum(image=image, selem=elem, out=out, mask=mask, shift_x=0, shift_y=0)
    assert_equal(image, out)
    rank.maximum(image=image, selem=elem, out=out, mask=mask, shift_x=0, shift_y=0)
    assert_equal(image, out)
Exemple #15
0
def test_16bit():
    image = np.zeros((21, 21), dtype=np.uint16)
    selem = np.ones((3, 3), dtype=np.uint8)

    for bitdepth in range(17):
        value = 2 ** bitdepth - 1
        image[10, 10] = value
        assert rank.minimum(image, selem)[10, 10] == 0
        assert rank.maximum(image, selem)[10, 10] == value
        assert rank.mean(image, selem)[10, 10] == int(value / selem.size)
Exemple #16
0
def test_16bit():
    image = np.zeros((21, 21), dtype=np.uint16)
    selem = np.ones((3, 3), dtype=np.uint8)

    for bitdepth in range(17):
        value = 2**bitdepth - 1
        image[10, 10] = value
        assert rank.minimum(image, selem)[10, 10] == 0
        assert rank.maximum(image, selem)[10, 10] == value
        assert rank.mean(image, selem)[10, 10] == int(value / selem.size)
        def check_all():
            selem = morphology.disk(1)
            refs = np.load(
                os.path.join(skimage.data_dir, "rank_filter_tests.npz"))

            assert_equal(refs["autolevel"], rank.autolevel(self.image, selem))
            assert_equal(refs["autolevel_percentile"],
                         rank.autolevel_percentile(self.image, selem))
            assert_equal(refs["bottomhat"], rank.bottomhat(self.image, selem))
            assert_equal(refs["equalize"], rank.equalize(self.image, selem))
            assert_equal(refs["gradient"], rank.gradient(self.image, selem))
            assert_equal(refs["gradient_percentile"],
                         rank.gradient_percentile(self.image, selem))
            assert_equal(refs["maximum"], rank.maximum(self.image, selem))
            assert_equal(refs["mean"], rank.mean(self.image, selem))
            assert_equal(refs["geometric_mean"],
                         rank.geometric_mean(self.image, selem)),
            assert_equal(refs["mean_percentile"],
                         rank.mean_percentile(self.image, selem))
            assert_equal(refs["mean_bilateral"],
                         rank.mean_bilateral(self.image, selem))
            assert_equal(refs["subtract_mean"],
                         rank.subtract_mean(self.image, selem))
            assert_equal(refs["subtract_mean_percentile"],
                         rank.subtract_mean_percentile(self.image, selem))
            assert_equal(refs["median"], rank.median(self.image, selem))
            assert_equal(refs["minimum"], rank.minimum(self.image, selem))
            assert_equal(refs["modal"], rank.modal(self.image, selem))
            assert_equal(refs["enhance_contrast"],
                         rank.enhance_contrast(self.image, selem))
            assert_equal(refs["enhance_contrast_percentile"],
                         rank.enhance_contrast_percentile(self.image, selem))
            assert_equal(refs["pop"], rank.pop(self.image, selem))
            assert_equal(refs["pop_percentile"],
                         rank.pop_percentile(self.image, selem))
            assert_equal(refs["pop_bilateral"],
                         rank.pop_bilateral(self.image, selem))
            assert_equal(refs["sum"], rank.sum(self.image, selem))
            assert_equal(refs["sum_bilateral"],
                         rank.sum_bilateral(self.image, selem))
            assert_equal(refs["sum_percentile"],
                         rank.sum_percentile(self.image, selem))
            assert_equal(refs["threshold"], rank.threshold(self.image, selem))
            assert_equal(refs["threshold_percentile"],
                         rank.threshold_percentile(self.image, selem))
            assert_equal(refs["tophat"], rank.tophat(self.image, selem))
            assert_equal(refs["noise_filter"],
                         rank.noise_filter(self.image, selem))
            assert_equal(refs["entropy"], rank.entropy(self.image, selem))
            assert_equal(refs["otsu"], rank.otsu(self.image, selem))
            assert_equal(refs["percentile"],
                         rank.percentile(self.image, selem))
            assert_equal(refs["windowed_histogram"],
                         rank.windowed_histogram(self.image, selem))
Exemple #18
0
    def test_trivial_footprint16(self):
        # check that min, max and mean returns identity if footprint
        # contains only central pixel

        image = np.zeros((5, 5), dtype=np.uint16)
        out = np.zeros_like(image)
        mask = np.ones_like(image, dtype=np.uint8)
        image[2, 2] = 255
        image[2, 3] = 128
        image[1, 2] = 16

        elem = np.array([[0, 0, 0], [0, 1, 0], [0, 0, 0]], dtype=np.uint8)
        rank.mean(image=image,
                  footprint=elem,
                  out=out,
                  mask=mask,
                  shift_x=0,
                  shift_y=0)
        assert_equal(image, out)
        rank.geometric_mean(image=image,
                            footprint=elem,
                            out=out,
                            mask=mask,
                            shift_x=0,
                            shift_y=0)
        assert_equal(image, out)
        rank.minimum(image=image,
                     footprint=elem,
                     out=out,
                     mask=mask,
                     shift_x=0,
                     shift_y=0)
        assert_equal(image, out)
        rank.maximum(image=image,
                     footprint=elem,
                     out=out,
                     mask=mask,
                     shift_x=0,
                     shift_y=0)
        assert_equal(image, out)
Exemple #19
0
def test_16bit():
    image = np.zeros((21, 21), dtype=np.uint16)
    selem = np.ones((3, 3), dtype=np.uint8)

    for bitdepth in range(17):
        value = 2 ** bitdepth - 1
        image[10, 10] = value
        if bitdepth > 11:
            expected = ['Bitdepth of %s' % (bitdepth - 1)]
        else:
            expected = []
        with expected_warnings(expected):
            assert rank.minimum(image, selem)[10, 10] == 0
            assert rank.maximum(image, selem)[10, 10] == value
            assert rank.mean(image, selem)[10, 10] == int(value / selem.size)
Exemple #20
0
def test_16bit():
    image = np.zeros((21, 21), dtype=np.uint16)
    selem = np.ones((3, 3), dtype=np.uint8)

    for bitdepth in range(17):
        value = 2**bitdepth - 1
        image[10, 10] = value
        if bitdepth > 11:
            expected = ['Bitdepth of %s' % (bitdepth - 1)]
        else:
            expected = []
        with expected_warnings(expected):
            assert rank.minimum(image, selem)[10, 10] == 0
            assert rank.maximum(image, selem)[10, 10] == value
            assert rank.mean(image, selem)[10, 10] == int(value / selem.size)
Exemple #21
0
    def test_16bit(self):
        image = np.zeros((21, 21), dtype=np.uint16)
        footprint = np.ones((3, 3), dtype=np.uint8)

        for bitdepth in range(17):
            value = 2**bitdepth - 1
            image[10, 10] = value
            if bitdepth >= 11:
                expected = ['Bad rank filter performance']
            else:
                expected = []
            with expected_warnings(expected):
                assert rank.minimum(image, footprint)[10, 10] == 0
                assert rank.maximum(image, footprint)[10, 10] == value
                mean_val = rank.mean(image, footprint)[10, 10]
                assert mean_val == int(value / footprint.size)
Exemple #22
0
        def process(self, frame):
            # like erosion, but faster
            from skimage.filters.rank import minimum

            # parameter: minimum lighting (dynamic range), threshold below
            min_range = 20

            if len(self.que) < self.window_size:
                self.que.append(frame)
            elif len(self.que) == self.window_size:
                # print("computing bg...")
                if self.bg is None:
                    bg = np.max(self.que, axis=0)
                    bg[bg < min_range] = 0
                    bg = minimum(bg.squeeze(), square(8))
                    bg = np.expand_dims(bg, axis=-1)
                    self.bg = bg
            return self.bg
Exemple #23
0
def feng(image, mask=None,
         window_size=15, window_size2=30,
         a1=0.12, gamma=2, k1=0.25, k2=0.04,
         return_threshold=False, **kwargs):
    """
    Thresholding method as developed by [Feng2004]_.

    .. [Feng2004] Fend & Tan (2004) IEICE Electronics Express
       DOI: `10.1587/elex.1.501 <https://dx.doi.org/10.1587/elex.1.501>`_

    :param image: Input image
    :param mask: Possible mask denoting a ROI
    :param window_size: Window size
    :param window_size2: Second window size
    :param a1: a1 value
    :param gamma: gamma value
    :param k1: k1 value
    :param k2: k2 value
    :param return_threshold: Whether to return a binarization, or the actual threshold values
    :param kwargs: For compatibility
    :return:
    """

    mean, std = mean_and_std(image, window_size)

    mean2, std2 = mean_and_std(image, window_size2)

    M = rank.minimum(image, np.ones((window_size, window_size)))
    # what exactly do they mean? maximum of window?
    Rs = rank.maximum(std2.astype(np.uint8), np.ones((window_size2, window_size2)))

    if numexpr:
        threshold = numexpr.evaluate("""(
        (1 - a1) * mean + (k1 * (std / Rs) ** gamma) * (std/Rs) * (mean - M) + (k2 * (std / Rs) ** gamma) * M
        )""")
    else:
        a2 = k1 * (std / Rs) ** gamma
        a3 = k2 * (std / Rs) ** gamma
        threshold = (1 - a1) * mean + a2 * (std/Rs) * (mean - M) + a3 * M

    if return_threshold:
        return threshold
    else:
        return image < threshold
    def _generate_scribble_mask(self, mask):
        """ Generate the skeleton from a mask
        Given an error mask, the medial axis is computed to obtain the
        skeleton of the objects. In order to obtain smoother skeleton and
        remove small objects, an erosion and dilation operations are performed.
        The kernel size used is proportional the squared of the area.

        # Arguments
            mask: Numpy Array. Error mask

        Returns:
            skel: Numpy Array. Skeleton mask
        """
        mask = np.asarray(mask, dtype=np.uint8)
        side = np.sqrt(np.sum(mask > 0))

        mask_ = mask
        # kernel_size = int(self.kernel_size * side)
        kernel_radius = self.kernel_size * side * .5
        kernel_radius = min(kernel_radius, self.max_kernel_radius)
        logging.verbose(
            'Erosion and dilation with kernel radius: {:.1f}'.format(
                kernel_radius), 2)
        compute = True
        while kernel_radius > 1. and compute:
            kernel = disk(kernel_radius)
            mask_ = rank.minimum(mask.copy(), kernel)
            mask_ = rank.maximum(mask_, kernel)
            compute = False
            if mask_.astype(np.bool).sum() == 0:
                compute = True
                prev_kernel_radius = kernel_radius
                kernel_radius *= .9
                logging.verbose(
                    'Reducing kernel radius from {:.1f} '.format(
                        prev_kernel_radius) +
                    'pixels to {:.1f}'.format(kernel_radius), 1)

        mask_ = np.pad(mask_, ((1, 1), (1, 1)),
                       mode='constant',
                       constant_values=False)
        skel = medial_axis(mask_.astype(np.bool))
        skel = skel[1:-1, 1:-1]
        return skel
Exemple #25
0
def check_all():
    np.random.seed(0)
    image = np.random.rand(25, 25)
    selem = morphology.disk(1)
    refs = np.load(os.path.join(skimage.data_dir, "rank_filter_tests.npz"))

    assert_equal(refs["autolevel"], rank.autolevel(image, selem))
    assert_equal(refs["autolevel_percentile"], rank.autolevel_percentile(image, selem))
    assert_equal(refs["bottomhat"], rank.bottomhat(image, selem))
    assert_equal(refs["equalize"], rank.equalize(image, selem))
    assert_equal(refs["gradient"], rank.gradient(image, selem))
    assert_equal(refs["gradient_percentile"], rank.gradient_percentile(image, selem))
    assert_equal(refs["maximum"], rank.maximum(image, selem))
    assert_equal(refs["mean"], rank.mean(image, selem))
    assert_equal(refs["mean_percentile"], rank.mean_percentile(image, selem))
    assert_equal(refs["mean_bilateral"], rank.mean_bilateral(image, selem))
    assert_equal(refs["subtract_mean"], rank.subtract_mean(image, selem))
    assert_equal(refs["subtract_mean_percentile"], rank.subtract_mean_percentile(image, selem))
    assert_equal(refs["median"], rank.median(image, selem))
    assert_equal(refs["minimum"], rank.minimum(image, selem))
    assert_equal(refs["modal"], rank.modal(image, selem))
    assert_equal(refs["enhance_contrast"], rank.enhance_contrast(image, selem))
    assert_equal(refs["enhance_contrast_percentile"], rank.enhance_contrast_percentile(image, selem))
    assert_equal(refs["pop"], rank.pop(image, selem))
    assert_equal(refs["pop_percentile"], rank.pop_percentile(image, selem))
    assert_equal(refs["pop_bilateral"], rank.pop_bilateral(image, selem))
    assert_equal(refs["sum"], rank.sum(image, selem))
    assert_equal(refs["sum_bilateral"], rank.sum_bilateral(image, selem))
    assert_equal(refs["sum_percentile"], rank.sum_percentile(image, selem))
    assert_equal(refs["threshold"], rank.threshold(image, selem))
    assert_equal(refs["threshold_percentile"], rank.threshold_percentile(image, selem))
    assert_equal(refs["tophat"], rank.tophat(image, selem))
    assert_equal(refs["noise_filter"], rank.noise_filter(image, selem))
    assert_equal(refs["entropy"], rank.entropy(image, selem))
    assert_equal(refs["otsu"], rank.otsu(image, selem))
    assert_equal(refs["percentile"], rank.percentile(image, selem))
    assert_equal(refs["windowed_histogram"], rank.windowed_histogram(image, selem))
Exemple #26
0
        def process(self, frame):
            # like erosion, but faster
            from skimage.filters.rank import minimum

            # parameter: minimum lighting (dynamic range), threshold below
            min_range = 20
            self.que.append(frame)
            # print("Model que len "+str(len(self.que))+" awaiting "+str(self.window_size))
            if len(self.que) == self.window_size:
                # print("computing bg...")
                if self.bg is None:
                    bg = np.max(self.que, axis=0)
                    bg[bg < min_range] = 0
                    bg = minimum(bg.squeeze(), square(8))
                    bg = np.expand_dims(bg, axis=-1)
                    self.bg = bg.astype("uint8")
                    # print("bg computed...")
                    import cv2

                    cv2.imwrite("/home/mot/tmp/bg.png", self.bg)
            else:
                pass
                # print("Awaiting more frames...")
            return self.bg
# Local maximum and local minimum are the base operators for gray-level
# morphology.
#
# .. note::
#
#     `skimage.dilate` and `skimage.erode` are equivalent filters (see below
#     for comparison).
#
# Here is an example of the classical morphological gray-level filters:
# opening, closing and morphological gradient.

from skimage.filters.rank import maximum, minimum, gradient

noisy_image = img_as_ubyte(data.camera())

closing = maximum(minimum(noisy_image, disk(5)), disk(5))
opening = minimum(maximum(noisy_image, disk(5)), disk(5))
grad = gradient(noisy_image, disk(5))

# display results
fig, ax = plt.subplots(2, 2, figsize=[10, 7], sharex=True, sharey=True)
ax1, ax2, ax3, ax4 = ax.ravel()

ax1.imshow(noisy_image, cmap=plt.cm.gray)
ax1.set_title('Original')

ax2.imshow(closing, cmap=plt.cm.gray)
ax2.set_title('Gray-level closing')

ax3.imshow(opening, cmap=plt.cm.gray)
ax3.set_title('Gray-level opening')
    def TestSample(self):  # Run pump, take samples and analyse
        global currentPhoto
        self.im1Count["text"] = "-"  # Reset text fields
        self.im2Count["text"] = "-"
        self.im3Count["text"] = "-"

        self.im1Average["text"] = "-"
        self.im2Average["text"] = "-"
        self.im3Average["text"] = "-"

        self.imFinalCount["text"] = "-"
        self.imFinalAverage["text"] = "-"
        self.sizeAct["text"] = "-"
        self.Confidence["text"] = "-"
        self.ConfDisp["bg"] = "grey"

        ##'''
        global camera
        camera.stop_preview()  # Quit preview if open

        ###########################     Run pump and take Pictures       ###############################

        self.pump_On()  # Turn on pump
        self.update_idletasks()  # Refresh Gui

        for x in range(0, 25):  # Wait 25 seconds
            self.labelCurrentAction["text"] = "Pumping Liquid - %d" % (25 - x)
            self.update_idletasks()
            time.sleep(1)
        self.pump_Off()  # Turn off pump

        for x in range(1, 4):  # Take 3 images
            self.pump_Off()
            self.labelCurrentAction["text"] = "Powder Settle Time"
            self.update_idletasks()
            time.sleep(2)
            self.labelCurrentAction["text"] = "Capturing Image %d" % x
            camera.hflip = True  # Flip camera orientation appropriately
            camera.vflip = True
            camera.capture("/home/pi/PythonTempFolder/OrigPic" + str(x) + ".jpg")  # Save image to default directory

            self.update_idletasks()
            time.sleep(2)

            if x < 3:
                self.pump_On()  # Turn on pump
                for y in range(0, 6):  # Wait 6 seconds
                    self.labelCurrentAction["text"] = "Pumping Liquid - %d" % (6 - y)
                    self.update_idletasks()
                    time.sleep(1)

                self.pump_Off()  # Turn off pump
        ##'''
        ################################################################################################

        ###########################              Analyse Pictures        ###############################
        for x in range(1, 4):
            self.labelCurrentAction["text"] = "Loading image as greyscale - im %d" % x
            self.update_idletasks()

            image1 = io.imread(
                "/home/pi/PythonTempFolder/OrigPic" + str(x) + ".jpg", as_grey=True
            )  # Load image as greyscale

            ##
            ##image1 = io.imread('/home/pi/SDP Project/PowderTests/PPIM169041/169041Pic' + str(x) + '.jpg', as_grey=True)   ##Comment Out
            ##

            self.labelCurrentAction["text"] = "Cropping"  # Crop image
            self.update_idletasks()
            fromFile = np.asarray(image1, dtype=np.float32)
            orig = fromFile[0:1080, 420:1500]
            currentPhoto = orig
            self.showCurrent()
            self.update_idletasks()
            time.sleep(2)

            self.labelCurrentAction["text"] = "Applying minimum filter"  # Apply minimum filter
            self.update_idletasks()
            image2 = minimum(orig, disk(6))
            currentPhoto = image2
            self.t.destroy()
            self.update_idletasks()
            self.showCurrent()
            self.update_idletasks()

            self.labelCurrentAction["text"] = "Applying mean filter"  # Apply mean filter
            self.update_idletasks()
            image3 = mean(image2, disk(22))
            currentPhoto = image3
            self.t.destroy()
            self.update_idletasks()
            self.showCurrent()
            self.update_idletasks()

            self.labelCurrentAction["text"] = "Applying maximum filter"  # Apply maximum filter
            self.update_idletasks()
            image4 = maximum(image3, disk(6))
            currentPhoto = image4
            self.t.destroy()
            self.update_idletasks()
            self.showCurrent()
            self.update_idletasks()
            time.sleep(2)

            self.labelCurrentAction["text"] = "Normalising"  # Subtract filtered image from original
            self.update_idletasks()
            new = np.asarray(image4, dtype=np.float32)
            new[0:, 0:] = new[0:, 0:] / 255

            sub = np.subtract(orig, new)
            sub[0:, 0:] += 128 / 255  # Scale appropriately

            imFinal = sub
            currentPhoto = sub
            self.t.destroy()
            self.update_idletasks()
            self.showCurrent()
            self.update_idletasks()
            time.sleep(1)

            self.labelCurrentAction["text"] = "Thresholding (Otsu)"  # Get Otsu threshold value from image
            self.update_idletasks()
            thresh = threshold_otsu(imFinal)  ##Threshold
            print("T - " + str(thresh))

            intensity = float(self.entryIntensity.get())  # Get manual threshold value from text field

            self.labelCurrentAction[
                "text"
            ] = "Creating Binary Image"  # Create binary image from threshold value (changed to manual - ignore otsu)
            self.update_idletasks()
            binary = sub <= intensity  # 0.095 #(thresh+0.2)
            scipy.misc.imsave(
                "/home/pi/PythonTempFolder/binary" + str(x) + ".jpg", binary
            )  # Save binary image to default directory
            currentPhoto = binary
            self.t.destroy()
            self.update_idletasks()
            self.showCurrent()
            self.update_idletasks()

            labels = label(binary)
            self.labelCurrentAction["text"] = "Analysing Particles"
            self.update_idletasks()

            counter = 0
            areaCount = 0
            Tmin = int(self.entryTmin.get())  # Get size thresholds from text input
            Tmax = int(self.entryTmax.get())
            ################################################################################################

            # Tmin = 10
            # Tmax = 300

            for region in regionprops(labels):  # Iterate through particles in the binary image
                if region.area <= Tmax and region.area >= Tmin:
                    counter = counter + 1  # Count number of particles found
                    areaCount = areaCount + region.area  # Sum area of all particles

            average = areaCount / counter  # Calculate average area
            if x == 1:
                self.im1Count["text"] = counter
                self.im1Average["text"] = round(average, 5)  # Display average image 1
                counter1 = counter
                average1 = average

            if x == 2:
                self.im2Count["text"] = counter
                self.im2Average["text"] = round(average, 5)  # Display average image 2
                counter2 = counter
                average2 = average

            if x == 3:
                self.im3Count["text"] = counter
                self.im3Average["text"] = round(average, 5)  # Display average image 3
                counter3 = counter
                average3 = average

            print(counter)
            average = areaCount / counter
            # print(average)

            self.t.destroy()
            self.update_idletasks()

        finalCount = (counter1 + counter2 + counter3) / 3  # Calculate final count all images
        finalAverage = (average1 + average2 + average3) / 3  # Calculate final average all images

        self.imFinalCount["text"] = finalCount
        self.imFinalAverage["text"] = round(finalAverage, 3)
        microns = (math.sqrt((finalAverage * 113.0989232) / 3.14159265359)) * 2  # Size approximation

        self.sizeAct["text"] = "~ " + str(round(microns, 3)) + " microns"

        maxCount = max(counter1, counter2, counter3)
        Conf = float(finalCount) / float(maxCount)
        self.Confidence["text"] = str(round(Conf, 3)) + " %"
        print(finalCount)
        # print(maxCount)
        print(Conf)

        self.ConfDisp["bg"] = "red"  # Change confidence colours
        if Conf >= 0.84:
            self.ConfDisp["bg"] = "yellow"
        if Conf >= 0.93:
            self.ConfDisp["bg"] = "green"

        self.labelCurrentAction["text"] = "Complete!"
        self.update_idletasks()
        time.sleep(2)
        self.labelCurrentAction["text"] = "idle"
        self.update_idletasks()
Exemple #29
0
from skimage.morphology import disk
import skimage.filters.rank as sfr

original_image = color.rgb2gray(data.camera())
plt.imshow(original_image, cmap=plt.cm.gray)

filtered_images = []
filtered_images.append(sfr.autolevel(original_image, disk(5)))
filtered_images.append(sfr.bottomhat(original_image, disk(5)))
filtered_images.append(sfr.tophat(original_image, disk(5)))
filtered_images.append(sfr.enhance_contrast(original_image, disk(5)))
filtered_images.append(sfr.entropy(original_image, disk(5)))
filtered_images.append(sfr.equalize(original_image, disk(5)))
filtered_images.append(sfr.gradient(original_image, disk(5)))
filtered_images.append(sfr.maximum(original_image, disk(5)))
filtered_images.append(sfr.minimum(original_image, disk(5)))
filtered_images.append(sfr.mean(original_image, disk(5)))
filtered_images.append(sfr.median(original_image, disk(5)))
filtered_images.append(sfr.modal(original_image, disk(5)))
filtered_images.append(sfr.otsu(original_image, disk(5)))
filtered_images.append(sfr.threshold(original_image, disk(5)))
filtered_images.append(sfr.subtract_mean(original_image, disk(5)))
filtered_images.append(sfr.sum(original_image, disk(5)))

name_list = [
    'autolevel', 'bottomhat', 'tophat', 'enhance_contrast', 'entropy',
    'equalize', 'gradient', 'maximum', 'minimum', 'mean', 'median', 'modal',
    'otsu', 'threshold', 'subtract_mean', 'sum'
]

fig, axes = plt.subplots(nrows=4, ncols=4, figsize=(8, 8))
Exemple #30
0
def min_box(image, kernel_size=15):
    # 半径为15的最小值滤波器
    min_image = sfr.minimum(image, disk(kernel_size))
    return min_image
Exemple #31
0
def compute_local_features(retinal_image):
    red_channel=retinal_image.preprocessed_image[:,:,0]
    green_channel=retinal_image.preprocessed_image[:,:,1]
    blue_channel=retinal_image.preprocessed_image[:,:,2]
    hue_channel=color.rgb2hsv(retinal_image.preprocessed_image)[:,:,0]
    saturation_channel=color.rgb2hsv(retinal_image.preprocessed_image)[:,:,1]
    value_channel=color.rgb2hsv(retinal_image.preprocessed_image)[:,:,2]
    gray_level_image = color.rgb2gray(retinal_image.preprocessed_image)
    #mean- large
    mean_red_intensity_large=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_blue_intensity_large=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_green_intensity_large=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_hue_large=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_saturation_large=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_value_large=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    #mean- small
    mean_red_intensity=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_green_intensity=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_blue_intensity=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_hue=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_saturation=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_value=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    #minimum- large
    minimum_red_intensity_large=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    minimum_green_intensity_large=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    minimum_blue_intensity_large=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    minimum_hue_large=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    minimum_saturation_large=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    minimum_value_large=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))  
    #minimum- small
    minimum_red_intensity=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    minimum_green_intensity=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    minimum_blue_intensity=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    minimum_hue=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    minimum_saturation=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    minimum_value=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    #maximum- large
    maximum_red_intensity_large=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    maximum_green_intensity_large=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    maximum_blue_intensity_large=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    maximum_hue_large=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    maximum_saturation_large=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    maximum_value_large=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    #maximum- small
    maximum_red_intensity=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    maximum_green_intensity=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    maximum_blue_intensity=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    maximum_hue=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    maximum_saturation=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    maximum_value=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    # std- large
    mean_red_intensity_large1 = np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_red_intensity_large_potency=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_green_intensity_large1=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_green_intensity_large_potency=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_blue_intensity_large1=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_blue_intensity_large_potency=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_hue_large1=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_hue_large_potency=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_saturation_large1=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_saturation_large_potency=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_value_large1=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_value_large_potency=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    # std- small
    mean_red_intensity_1 = np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_red_intensity_potency=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_green_intensity_1=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_green_intensity_potency=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_blue_intensity_1=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_blue_intensity_potency=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_hue_1=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_hue_potency=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_saturation_1=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_saturation_potency=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_value_1=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_value_potency=np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    #GCLM Feature (Line Entropy)
    glcm_temp_image_entropy = np.ones((retinal_image.labels.shape[0],retinal_image.labels.shape[1]))
    glcm_image_line_entropy = np.zeros((retinal_image.labels.shape[0],retinal_image.labels.shape[1]))
    
    #GLCM Features Large Diameter
#    glcm_image_entropy_large = np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
#    glcm_image_large = np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
#    glcm_image_contrast_large = np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
#    glcm_image_dissimilarity_large = np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
#    glcm_image_homogeneity_large = np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
#    glcm_image_energy_large = np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
#    glcm_image_correlation_large = np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
#    glcm_image_ASM_large = np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    
    #GLCM Features Small Diameter
#    glcm_image_entropy_small = np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
#    glcm_image_small = np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
#    glcm_image_contrast_small = np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
#    glcm_image_dissimilarity_small = np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
#    glcm_image_homogeneity_small = np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
#    glcm_image_energy_small = np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
#    glcm_image_correlation_small = np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
#    glcm_image_ASM_small = np.zeros((retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    
    
    max_labels=np.amax(retinal_image.labels)
    distanceTransform=ndimage.distance_transform_edt(retinal_image.vessels)
    diameter=distanceTransform * retinal_image.skeletonWithoutCrossings
    meanDiameterInRegion=np.zeros(np.max(retinal_image.labels))

    for i in range(1, max_labels + 1):
        meanDiameterInRegion[i-1]=np.mean(diameter[retinal_image.labels==(i)])
        disk_diameter=meanDiameterInRegion[i-1]
#        disk_diameter=2; 
        disk_diameter_large=2*disk_diameter
        labels_points=(retinal_image.labels==i)
        labels_points_indexes=np.nonzero(labels_points)
        labels_points_indexes=list(labels_points_indexes)
        rows=(labels_points_indexes)[0]
        cols=(labels_points_indexes)[1]
        #labels_points_int=labels_points.astype(int)
        #mean_intensity[rows,cols]=mean(img_rgb[labels_points==True], disk(disk_diameter)) 
        #mean_intensity[rows,cols]=mean(red_channel[rows,cols], disk(disk_diameter)) 
        #mean- large
        mean_red_intensity_large_iteration=mean(red_channel,disk(disk_diameter_large))
        mean_red_intensity_large[rows,cols]=mean_red_intensity_large_iteration[rows,cols]
        mean_green_intensity_large_iteration=mean(green_channel,disk(disk_diameter_large))
        mean_green_intensity_large[rows,cols]=mean_green_intensity_large_iteration[rows,cols]
        mean_blue_intensity_large_iteration=mean(blue_channel,disk(disk_diameter_large))
        mean_blue_intensity_large[rows,cols]=mean_blue_intensity_large_iteration[rows,cols]
        mean_hue_large_iteration=mean(hue_channel,disk(disk_diameter_large))
        mean_hue_large[rows,cols]=mean_hue_large_iteration[rows,cols]
        mean_saturation_large_iteration=mean(saturation_channel,disk(disk_diameter_large))
        mean_saturation_large[rows,cols]=mean_saturation_large_iteration[rows,cols]
        mean_value_large_iteration=mean(value_channel,disk(disk_diameter_large))
        mean_value_large[rows,cols]=mean_value_large_iteration[rows,cols]
        #mean- small
        mean_red_intensity_iteration=mean(red_channel,disk(disk_diameter))
        mean_red_intensity[rows,cols]=mean_red_intensity_iteration[rows,cols]
        mean_green_intensity_iteration=mean(green_channel,disk(disk_diameter))
        mean_green_intensity[rows,cols]=mean_green_intensity_iteration[rows,cols]
        mean_blue_intensity_iteration=mean(blue_channel,disk(disk_diameter))
        mean_blue_intensity[rows,cols]=mean_blue_intensity_iteration[rows,cols]
        mean_hue_iteration=mean(hue_channel,disk(disk_diameter))
        mean_hue[rows,cols]=mean_hue_iteration[rows,cols]
        mean_saturation_iteration=mean(saturation_channel,disk(disk_diameter))
        mean_saturation[rows,cols]=mean_saturation_iteration[rows,cols]
        mean_value_iteration=mean(value_channel,disk(disk_diameter))
        mean_value[rows,cols]=mean_value_iteration[rows,cols]
        #minimum- large
        minimum_red_intensity_iteration=minimum(red_channel,disk(disk_diameter))
        minimum_red_intensity[rows,cols]=minimum_red_intensity_iteration[rows,cols]
        minimum_green_intensity_iteration=minimum(green_channel,disk(disk_diameter))
        minimum_green_intensity[rows,cols]=minimum_green_intensity_iteration[rows,cols]
        minimum_blue_intensity_iteration=minimum(blue_channel,disk(disk_diameter))
        minimum_blue_intensity[rows,cols]=minimum_blue_intensity_iteration[rows,cols]
        minimum_hue_iteration=minimum(hue_channel,disk(disk_diameter))
        minimum_hue[rows,cols]=minimum_hue_iteration[rows,cols]
        minimum_saturation_iteration=minimum(saturation_channel,disk(disk_diameter))
        minimum_saturation[rows,cols]=minimum_saturation_iteration[rows,cols]
        minimum_value_iteration=minimum(value_channel,disk(disk_diameter))
        minimum_value[rows,cols]=minimum_value_iteration[rows,cols]
        #minimum- small
        minimum_red_intensity_large_iteration=minimum(red_channel,disk(disk_diameter_large))
        minimum_red_intensity_large[rows,cols]=minimum_red_intensity_large_iteration[rows,cols]
        minimum_green_intensity_large_iteration=minimum(green_channel,disk(disk_diameter_large))
        minimum_green_intensity_large[rows,cols]=minimum_green_intensity_large_iteration[rows,cols]
        minimum_blue_intensity_large_iteration=minimum(blue_channel,disk(disk_diameter_large))
        minimum_blue_intensity_large[rows,cols]=minimum_blue_intensity_large_iteration[rows,cols]
        minimum_hue_large_iteration=minimum(hue_channel,disk(disk_diameter_large))
        minimum_hue_large[rows,cols]=minimum_hue_large_iteration[rows,cols]
        minimum_saturation_large_iteration=minimum(saturation_channel,disk(disk_diameter_large))
        minimum_saturation_large[rows,cols]=minimum_saturation_large_iteration[rows,cols]
        minimum_value_large_iteration=minimum(value_channel,disk(disk_diameter_large))
        minimum_value_large[rows,cols]=minimum_value_large_iteration[rows,cols]
        #maximum- large
        maximum_red_intensity_large_iteration=maximum(red_channel,disk(disk_diameter_large))
        maximum_red_intensity_large[rows,cols]=maximum_red_intensity_large_iteration[rows,cols]
        maximum_green_intensity_large_iteration=maximum(green_channel,disk(disk_diameter_large))
        maximum_green_intensity_large[rows,cols]=maximum_green_intensity_large_iteration[rows,cols]
        maximum_blue_intensity_large_iteration=maximum(blue_channel,disk(disk_diameter_large))
        maximum_blue_intensity_large[rows,cols]=maximum_blue_intensity_large_iteration[rows,cols]
        maximum_hue_large_iteration=maximum(hue_channel,disk(disk_diameter_large))
        maximum_hue_large[rows,cols]=maximum_hue_large_iteration[rows,cols]
        maximum_saturation_large_iteration=maximum(saturation_channel,disk(disk_diameter_large))
        maximum_saturation_large[rows,cols]=maximum_saturation_large_iteration[rows,cols]
        maximum_value_large_iteration=maximum(value_channel,disk(disk_diameter_large))
        maximum_value_large[rows,cols]=maximum_value_large_iteration[rows,cols]
        #maximum- small
        maximum_red_intensity_iteration=maximum(red_channel,disk(disk_diameter))
        maximum_red_intensity[rows,cols]=maximum_red_intensity_iteration[rows,cols]
        maximum_green_intensity_iteration=maximum(green_channel,disk(disk_diameter))
        maximum_green_intensity[rows,cols]=maximum_green_intensity_iteration[rows,cols]
        maximum_blue_intensity_iteration=maximum(blue_channel,disk(disk_diameter))
        maximum_blue_intensity[rows,cols]=maximum_blue_intensity_iteration[rows,cols]
        maximum_hue_iteration=maximum(hue_channel,disk(disk_diameter))
        maximum_hue[rows,cols]=maximum_hue_iteration[rows,cols]
        maximum_saturation_iteration=maximum(saturation_channel,disk(disk_diameter))
        maximum_saturation[rows,cols]=maximum_saturation_iteration[rows,cols]
        maximum_value_iteration=maximum(value_channel,disk(disk_diameter))
        maximum_value[rows,cols]=maximum_value_iteration[rows,cols]
        #std-large
        #std red
        mean_red_intensity_large_iteration1=mean(red_channel ** 2,disk(disk_diameter_large))
        mean_red_intensity_large1[rows,cols]=mean_red_intensity_large_iteration1[rows,cols] 
        mean_red_intensity_large_potency_iteration = mean(red_channel,disk(disk_diameter_large))
        mean_red_intensity_large_potency[rows,cols] =  mean_red_intensity_large_potency_iteration[rows,cols] ** 2  
        std_red = mean_red_intensity_large_potency-mean_red_intensity_large1
        std_red = np.abs(std_red)
        std_red_final = np.sqrt(std_red)
        #std green
        mean_green_intensity_large_iteration1=mean(green_channel ** 2,disk(disk_diameter_large))
        mean_green_intensity_large1[rows,cols]=mean_green_intensity_large_iteration1[rows,cols] 
        mean_green_intensity_large_potency_iteration = mean(green_channel,disk(disk_diameter_large))
        mean_green_intensity_large_potency[rows,cols] =  mean_green_intensity_large_potency_iteration[rows,cols] ** 2  
        std_green = mean_green_intensity_large_potency-mean_green_intensity_large1
        std_green = np.abs(std_green)
        std_green_final = np.sqrt(std_green)
        #std Blue 
        mean_blue_intensity_large_iteration1=mean(blue_channel ** 2,disk(disk_diameter_large))
        mean_blue_intensity_large1[rows,cols]=mean_blue_intensity_large_iteration1[rows,cols] 
        mean_blue_intensity_large_potency_iteration = mean(blue_channel,disk(disk_diameter_large))
        mean_blue_intensity_large_potency[rows,cols] =  mean_blue_intensity_large_potency_iteration[rows,cols] ** 2 
        std_blue =mean_blue_intensity_large_potency - mean_blue_intensity_large1
        std_blue =np.abs(std_blue)
        std_blue_final = np.sqrt(std_blue)
        #std hue
        mean_hue_large_iteration1=mean(hue_channel ** 2,disk(disk_diameter_large))
        mean_hue_large1[rows,cols]=mean_hue_large_iteration1[rows,cols] 
        mean_hue_large_potency_iteration = mean(hue_channel,disk(disk_diameter_large))
        mean_hue_large_potency[rows,cols] =  mean_hue_large_potency_iteration[rows,cols] ** 2
        std_hue =mean_hue_large_potency-mean_hue_large1
        std_hue = np.abs(std_hue)
        std_hue_final = np.sqrt(std_hue)
        #std saturation
        mean_saturation_large_iteration1=mean(saturation_channel ** 2,disk(disk_diameter_large))
        mean_saturation_large1[rows,cols]=mean_saturation_large_iteration1[rows,cols] 
        mean_saturation_large_potency_iteration = mean(saturation_channel,disk(disk_diameter_large))
        mean_saturation_large_potency[rows,cols] =  mean_saturation_large_potency_iteration[rows,cols] ** 2
        std_saturation =mean_saturation_large_potency-mean_saturation_large1
        std_saturation = np.abs(std_saturation)
        std_saturation_final = np.sqrt(std_saturation)
        #std Value
        mean_value_large_iteration1=mean(value_channel ** 2,disk(disk_diameter_large))
        mean_value_large1[rows,cols]=mean_value_large_iteration1[rows,cols] 
        mean_value_large_potency_iteration = mean(value_channel,disk(disk_diameter_large))
        mean_value_large_potency[rows,cols] =  mean_value_large_potency_iteration[rows,cols] ** 2
        std_value =mean_value_large_potency-mean_value_large1
        std_value = np.abs(std_value)
        std_value_final = np.sqrt(std_value)
        #std-small
        #std red
        mean_red_intensity_iteration1=mean(red_channel ** 2,disk(disk_diameter))
        mean_red_intensity_1[rows,cols]=mean_red_intensity_iteration1[rows,cols] 
        mean_red_intensity_potency_iteration = mean(red_channel,disk(disk_diameter))
        mean_red_intensity_potency[rows,cols] =  mean_red_intensity_potency_iteration[rows,cols] ** 2  
        std_red_small = mean_red_intensity_potency-mean_red_intensity_1
        std_red_small = np.abs(std_red_small)
        std_red_final_small = np.sqrt(std_red_small)
        #std green
        mean_green_intensity_iteration1=mean(green_channel ** 2,disk(disk_diameter))
        mean_green_intensity_1[rows,cols]=mean_green_intensity_iteration1[rows,cols] 
        mean_green_intensity_potency_iteration = mean(green_channel,disk(disk_diameter))
        mean_green_intensity_potency[rows,cols] =  mean_green_intensity_potency_iteration[rows,cols] ** 2  
        std_green_small = mean_green_intensity_potency-mean_green_intensity_1
        std_green_small = np.abs(std_green_small)
        std_green_final_small = np.sqrt(std_green_small)
        #std Blue 
        mean_blue_intensity_iteration1=mean(blue_channel ** 2,disk(disk_diameter))
        mean_blue_intensity_1[rows,cols]=mean_blue_intensity_iteration1[rows,cols] 
        mean_blue_intensity_potency_iteration = mean(blue_channel,disk(disk_diameter))
        mean_blue_intensity_potency[rows,cols] =  mean_blue_intensity_potency_iteration[rows,cols] ** 2 
        std_blue_small =mean_blue_intensity_potency - mean_blue_intensity_1
        std_blue_small =np.abs(std_blue_small)
        std_blue_final_small = np.sqrt(std_blue_small)
        #std hue
        mean_hue_iteration1=mean(hue_channel ** 2,disk(disk_diameter))
        mean_hue_1[rows,cols]=mean_hue_iteration1[rows,cols] 
        mean_hue_potency_iteration = mean(hue_channel,disk(disk_diameter))
        mean_hue_potency[rows,cols] =  mean_hue_potency_iteration[rows,cols] ** 2
        std_hue_small =mean_hue_potency-mean_hue_1
        std_hue_small = np.abs(std_hue_small)
        std_hue_final_small = np.sqrt(std_hue_small)
        #std saturation
        mean_saturation_iteration1=mean(saturation_channel ** 2,disk(disk_diameter))
        mean_saturation_1[rows,cols]=mean_saturation_iteration1[rows,cols] 
        mean_saturation_potency_iteration = mean(saturation_channel,disk(disk_diameter))
        mean_saturation_potency[rows,cols] =  mean_saturation_potency_iteration[rows,cols] ** 2
        std_saturation_small =mean_saturation_potency-mean_saturation_1
        std_saturation_small = np.abs(std_saturation_small)
        std_saturation_final_small = np.sqrt(std_saturation_small)
        #std Value
        mean_value_iteration1=mean(value_channel ** 2,disk(disk_diameter))
        mean_value_1[rows,cols]=mean_value_iteration1[rows,cols] 
        mean_value_potency_iteration = mean(value_channel,disk(disk_diameter))
        mean_value_potency[rows,cols] =  mean_value_potency_iteration[rows,cols] ** 2
        std_value_small =mean_value_potency-mean_value_1
        std_value_small = np.abs(std_value_small)
        std_value_final_small = np.sqrt(std_value_small)
        
        #Run GLCM Feauture (Entropy) in the label
        #Line Entropy
        #It must be calculated by loading the imagem in grayscale: astype(np.float64)
#        glcm_image_line_entropy_iteration = shannon_entropy(gray_level_image[rows, cols])
#        glcm_temp_image_entropy = glcm_temp_image_entropy*glcm_image_line_entropy_iteration
#        glcm_image_line_entropy[rows, cols] = glcm_temp_image_entropy[rows, cols]
#        
#        #This creates the GLCM local matrix which is arg of the functions under:
#        glcm_image_iteration_large = greycomatrix((retinal_image.preprocessed_image, disk_diameter_large, [1],[0]))
#        glcm_image_iteration_small = greycomatrix((retinal_image.preprocessed_image, disk_diameter), [1],[0])
#
#        #Contrast
#        glcm_image_contrast_large_iteration = mean(greycoprops(glcm_image_iteration_large, 'contrast'), disk(disk_diameter_large))
#        glcm_image_contrast_large[rows,cols] = glcm_image_contrast_large_iteration[rows,cols]
#        glcm_image_contrast_small_iteration = mean(greycoprops( glcm_image_iteration_small, 'contrast'), disk(disk_diameter))
#        glcm_image_contrast_small[rows,cols] = glcm_image_contrast_small_iteration[rows,cols]
#        
#        #Dissimilarity
#        glcm_image_dissimilarity_large_iteration = mean(greycoprops(glcm_image_iteration_large, 'dissimilarity'), disk(disk_diameter_large))
#        glcm_image_dissimilarity_large[rows,cols] = glcm_image_dissimilarity_large_iteration[rows,cols]
#        glcm_image_dissimilarity_small_iteration = mean(greycoprops( glcm_image_iteration_small, 'dissimilarity'), disk(disk_diameter))
#        glcm_image_dissimilarity_small[rows,cols] = glcm_image_dissimilarity_small_iteration[rows,cols]
#
#        #Homogeneity
#        glcm_image_homogeneity_large_iteration = mean(greycoprops(glcm_image_iteration_large, 'homogeneity'), disk(disk_diameter_large))
#        glcm_image_homogeneity_large[rows,cols] = glcm_image_homogeneity_large_iteration[rows,cols]
#        glcm_image_homogeneity_small_iteration = mean(greycoprops( glcm_image_iteration_small, 'homogeneity'), disk(disk_diameter))
#        glcm_image_homogeneity_small[rows,cols] = glcm_image_homogeneity_small_iteration[rows,cols]
#
#        #Energy
#        glcm_image_energy_large_iteration = mean(greycoprops(glcm_image_iteration_large, 'energy'), disk(disk_diameter_large))
#        glcm_image_energy_large[rows,cols] = glcm_image_energy_large_iteration[rows,cols]
#        glcm_image_energy_small_iteration = mean(greycoprops( glcm_image_iteration_small, 'energy'), disk(disk_diameter))
#        glcm_image_energy_small[rows,cols] = glcm_image_energy_small_iteration[rows,cols]
#        
#        #Correlation
#        glcm_image_correlation_large_iteration = mean(greycoprops(glcm_image_iteration_large, 'correlation'), disk(disk_diameter_large))
#        glcm_image_correlation_large[rows,cols] = glcm_image_correlation_large_iteration[rows,cols]
#        glcm_image_correlation_small_iteration = mean(greycoprops(glcm_image_iteration_small, 'correlation'), disk(disk_diameter))
#        glcm_image_correlation_small[rows,cols] = glcm_image_correlation_small_iteration[rows,cols]
#        
#        #ASM
#        glcm_image_ASM_large_iteration = mean(greycoprops(glcm_image_iteration_large, 'ASM'), disk(disk_diameter_large))
#        glcm_image_ASM_large[rows,cols] = glcm_image_ASM_large_iteration[rows,cols]
#        glcm_image_ASM_small_iteration = mean(greycoprops(glcm_image_iteration_small, 'ASM'), disk(disk_diameter))
#        glcm_image_ASM_small[rows,cols] = glcm_image_ASM_small_iteration[rows,cols]
        

        #print(mean_intensity)
        print(i, ':',disk_diameter)
    return mean_red_intensity_large, mean_green_intensity_large, mean_blue_intensity_large, mean_hue_large, mean_saturation_large, mean_value_large, mean_red_intensity, mean_green_intensity, mean_blue_intensity, mean_hue, mean_saturation, mean_value, minimum_red_intensity_large, minimum_green_intensity_large, minimum_blue_intensity_large, minimum_hue_large, minimum_saturation_large, minimum_value_large, minimum_red_intensity, minimum_green_intensity, minimum_blue_intensity, minimum_hue, minimum_saturation, minimum_value, maximum_red_intensity_large, maximum_green_intensity_large, maximum_blue_intensity_large, maximum_hue_large, maximum_saturation_large, maximum_value_large, maximum_red_intensity, maximum_green_intensity, maximum_blue_intensity, maximum_hue, maximum_saturation, maximum_value, std_red_final, std_green_final, std_blue_final, std_hue_final, std_saturation_final, std_value_final, std_red_final_small, std_green_final_small, std_blue_final_small, std_hue_final_small, std_saturation_final_small, std_value_final_small, glcm_image_line_entropy
Exemple #32
0
def precrocessing(img_gray, size):
    bk = sfr.minimum(img_gray, disk(size))  #min
    bk = cv2.blur(bk, (size, size))  #mean
    newIm = img_gray - bk
    #dst = cv2.blur(dst1, (2,2))
    return newIm
def min_box(image, kernel_size=15):
    min_image = sfr.minimum(
        image, disk(kernel_size))  #skimage.filters.rank.minimum()返回图像的局部最小值

    return min_image
 labels_points = (retinal_image.labels == i)
 labels_points_indexes = np.nonzero(labels_points)
 labels_points_indexes = list(labels_points_indexes)
 rows = (labels_points_indexes)[0]
 cols = (labels_points_indexes)[1]
 #labels_points_int=labels_points.astype(int)
 #mean_intensity[rows,cols]=mean(img_rgb[labels_points==True], disk(disk_diameter))
 #mean_intensity[rows,cols]=mean(red_channel[rows,cols], disk(disk_diameter))
 mean_red_intensity_large_iteration = mean(red_channel,
                                           disk(disk_diameter_large))
 mean_red_intensity_large[rows,
                          cols] = mean_red_intensity_large_iteration[rows,
                                                                     cols]
 mean_value_large_iteration = mean(value_channel, disk(disk_diameter_large))
 mean_value_large[rows, cols] = mean_value_large_iteration[rows, cols]
 minimum_red_intensity_iteration = minimum(red_channel, disk(disk_diameter))
 minimum_red_intensity[rows, cols] = minimum_red_intensity_iteration[rows,
                                                                     cols]
 minimum_value_iteration = minimum(value_channel, disk(disk_diameter))
 minimum_value[rows, cols] = minimum_value_iteration[rows, cols]
 minimum_blue_intensity_large_iteration = minimum(blue_channel,
                                                  disk(disk_diameter_large))
 minimum_blue_intensity_large[
     rows, cols] = minimum_blue_intensity_large_iteration[rows, cols]
 minimum_hue_large_iteration = minimum(hue_channel,
                                       disk(disk_diameter_large))
 minimum_hue_large[rows, cols] = minimum_hue_large_iteration[rows, cols]
 maximum_blue_intensity_large_iteration = maximum(blue_channel,
                                                  disk(disk_diameter_large))
 maximum_blue_intensity_large[
     rows, cols] = maximum_blue_intensity_large_iteration[rows, cols]
Exemple #35
0
    def TestSample(self):  #Run pump, take samples and analyse
        global currentPhoto
        self.im1Count["text"] = "-"  #Reset text fields
        self.im2Count["text"] = "-"
        self.im3Count["text"] = "-"

        self.im1Average["text"] = "-"
        self.im2Average["text"] = "-"
        self.im3Average["text"] = "-"

        self.imFinalCount["text"] = "-"
        self.imFinalAverage["text"] = "-"
        self.sizeAct["text"] = "-"
        self.Confidence["text"] = "-"
        self.ConfDisp["bg"] = "grey"

        ##'''
        global camera
        camera.stop_preview()  #Quit preview if open

        ###########################     Run pump and take Pictures       ###############################

        self.pump_On()  #Turn on pump
        self.update_idletasks()  #Refresh Gui

        for x in range(0, 25):  #Wait 25 seconds
            self.labelCurrentAction["text"] = "Pumping Liquid - %d" % (25 - x)
            self.update_idletasks()
            time.sleep(1)
        self.pump_Off()  #Turn off pump

        for x in range(1, 4):  #Take 3 images
            self.pump_Off()
            self.labelCurrentAction["text"] = "Powder Settle Time"
            self.update_idletasks()
            time.sleep(2)
            self.labelCurrentAction["text"] = "Capturing Image %d" % x
            camera.hflip = True  #Flip camera orientation appropriately
            camera.vflip = True
            camera.capture('/home/pi/PythonTempFolder/OrigPic' + str(x) +
                           '.jpg')  #Save image to default directory

            self.update_idletasks()
            time.sleep(2)

            if (x < 3):
                self.pump_On()  #Turn on pump
                for y in range(0, 6):  #Wait 6 seconds
                    self.labelCurrentAction["text"] = "Pumping Liquid - %d" % (
                        6 - y)
                    self.update_idletasks()
                    time.sleep(1)

                self.pump_Off()  #Turn off pump
        ##'''
        ################################################################################################

        ###########################              Analyse Pictures        ###############################
        for x in range(1, 4):
            self.labelCurrentAction[
                "text"] = "Loading image as greyscale - im %d" % x
            self.update_idletasks()

            image1 = io.imread('/home/pi/PythonTempFolder/OrigPic' + str(x) +
                               '.jpg',
                               as_grey=True)  #Load image as greyscale

            ##
            ##image1 = io.imread('/home/pi/SDP Project/PowderTests/PPIM169041/169041Pic' + str(x) + '.jpg', as_grey=True)   ##Comment Out
            ##

            self.labelCurrentAction["text"] = "Cropping"  #Crop image
            self.update_idletasks()
            fromFile = np.asarray(image1, dtype=np.float32)
            orig = fromFile[0:1080, 420:1500]
            currentPhoto = orig
            self.showCurrent()
            self.update_idletasks()
            time.sleep(2)

            self.labelCurrentAction[
                "text"] = "Applying minimum filter"  #Apply minimum filter
            self.update_idletasks()
            image2 = minimum(orig, disk(6))
            currentPhoto = image2
            self.t.destroy()
            self.update_idletasks()
            self.showCurrent()
            self.update_idletasks()

            self.labelCurrentAction[
                "text"] = "Applying mean filter"  #Apply mean filter
            self.update_idletasks()
            image3 = mean(image2, disk(22))
            currentPhoto = image3
            self.t.destroy()
            self.update_idletasks()
            self.showCurrent()
            self.update_idletasks()

            self.labelCurrentAction[
                "text"] = "Applying maximum filter"  #Apply maximum filter
            self.update_idletasks()
            image4 = maximum(image3, disk(6))
            currentPhoto = image4
            self.t.destroy()
            self.update_idletasks()
            self.showCurrent()
            self.update_idletasks()
            time.sleep(2)

            self.labelCurrentAction[
                "text"] = "Normalising"  #Subtract filtered image from original
            self.update_idletasks()
            new = np.asarray(image4, dtype=np.float32)
            new[0:, 0:] = new[0:, 0:] / 255

            sub = np.subtract(orig, new)
            sub[0:, 0:] += (128 / 255)  #Scale appropriately

            imFinal = sub
            currentPhoto = sub
            self.t.destroy()
            self.update_idletasks()
            self.showCurrent()
            self.update_idletasks()
            time.sleep(1)

            self.labelCurrentAction[
                "text"] = "Thresholding (Otsu)"  #Get Otsu threshold value from image
            self.update_idletasks()
            thresh = threshold_otsu(imFinal)  ##Threshold
            print("T - " + str(thresh))

            intensity = float(self.entryIntensity.get()
                              )  #Get manual threshold value from text field

            self.labelCurrentAction[
                "text"] = "Creating Binary Image"  #Create binary image from threshold value (changed to manual - ignore otsu)
            self.update_idletasks()
            binary = sub <= intensity  #0.095 #(thresh+0.2)
            scipy.misc.imsave('/home/pi/PythonTempFolder/binary' + str(x) +
                              '.jpg',
                              binary)  #Save binary image to default directory
            currentPhoto = binary
            self.t.destroy()
            self.update_idletasks()
            self.showCurrent()
            self.update_idletasks()

            labels = label(binary)
            self.labelCurrentAction["text"] = "Analysing Particles"
            self.update_idletasks()

            counter = 0
            areaCount = 0
            Tmin = int(
                self.entryTmin.get())  #Get size thresholds from text input
            Tmax = int(self.entryTmax.get())
            ################################################################################################

            #Tmin = 10
            #Tmax = 300

            for region in regionprops(
                    labels):  #Iterate through particles in the binary image
                if (region.area <= Tmax and region.area >= Tmin):
                    counter = counter + 1  #Count number of particles found
                    areaCount = areaCount + region.area  #Sum area of all particles

            average = areaCount / counter  #Calculate average area
            if (x == 1):
                self.im1Count["text"] = counter
                self.im1Average["text"] = round(average,
                                                5)  #Display average image 1
                counter1 = counter
                average1 = average

            if (x == 2):
                self.im2Count["text"] = counter
                self.im2Average["text"] = round(average,
                                                5)  #Display average image 2
                counter2 = counter
                average2 = average

            if (x == 3):
                self.im3Count["text"] = counter
                self.im3Average["text"] = round(average,
                                                5)  #Display average image 3
                counter3 = counter
                average3 = average

            print(counter)
            average = areaCount / counter
            #print(average)

            self.t.destroy()
            self.update_idletasks()

        finalCount = (counter1 + counter2 +
                      counter3) / 3  #Calculate final count all images
        finalAverage = (average1 + average2 +
                        average3) / 3  #Calculate final average all images

        self.imFinalCount["text"] = finalCount
        self.imFinalAverage["text"] = round(finalAverage, 3)
        microns = (math.sqrt((finalAverage * 113.0989232) /
                             3.14159265359)) * 2  #Size approximation

        self.sizeAct["text"] = "~ " + str(round(microns, 3)) + " microns"

        maxCount = max(counter1, counter2, counter3)
        Conf = float(finalCount) / float(maxCount)
        self.Confidence["text"] = str(round(Conf, 3)) + " %"
        print(finalCount)
        #print(maxCount)
        print(Conf)

        self.ConfDisp["bg"] = "red"  #Change confidence colours
        if (Conf >= 0.84):
            self.ConfDisp["bg"] = "yellow"
        if (Conf >= 0.93):
            self.ConfDisp["bg"] = "green"

        self.labelCurrentAction["text"] = "Complete!"
        self.update_idletasks()
        time.sleep(2)
        self.labelCurrentAction["text"] = "idle"
        self.update_idletasks()
 def min_filter(img, n):
     img = sfr.minimum(img, disk(n))
     return (img_as_ubyte(img))
Exemple #37
0
def compute_local_features(retinal_image):
    red_channel = retinal_image.preprocessed_image[:, :, 0]
    green_channel = retinal_image.preprocessed_image[:, :, 1]
    blue_channel = retinal_image.preprocessed_image[:, :, 2]
    hue_channel = color.rgb2hsv(retinal_image.preprocessed_image)[:, :, 0]
    saturation_channel = color.rgb2hsv(retinal_image.preprocessed_image)[:, :,
                                                                         1]
    value_channel = color.rgb2hsv(retinal_image.preprocessed_image)[:, :, 2]

    #mean- large
    mean_red_intensity_large = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_blue_intensity_large = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_green_intensity_large = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_hue_large = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_saturation_large = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_value_large = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    #mean- small
    mean_red_intensity = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_green_intensity = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_blue_intensity = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_hue = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_saturation = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_value = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    #minimum- large
    minimum_red_intensity_large = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    minimum_green_intensity_large = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    minimum_blue_intensity_large = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    minimum_hue_large = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    minimum_saturation_large = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    minimum_value_large = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    #minimum- small
    minimum_red_intensity = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    minimum_green_intensity = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    minimum_blue_intensity = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    minimum_hue = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    minimum_saturation = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    minimum_value = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    #maximum- large
    maximum_red_intensity_large = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    maximum_green_intensity_large = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    maximum_blue_intensity_large = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    maximum_hue_large = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    maximum_saturation_large = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    maximum_value_large = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    #maximum- small
    maximum_red_intensity = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    maximum_green_intensity = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    maximum_blue_intensity = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    maximum_hue = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    maximum_saturation = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    maximum_value = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    # std- large
    mean_red_intensity_large1 = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_red_intensity_large_potency = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_green_intensity_large1 = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_green_intensity_large_potency = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_blue_intensity_large1 = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_blue_intensity_large_potency = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_hue_large1 = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_hue_large_potency = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_saturation_large1 = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_saturation_large_potency = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_value_large1 = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_value_large_potency = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    # std- small
    mean_red_intensity_1 = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_red_intensity_potency = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_green_intensity_1 = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_green_intensity_potency = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_blue_intensity_1 = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_blue_intensity_potency = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_hue_1 = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_hue_potency = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_saturation_1 = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_saturation_potency = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_value_1 = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))
    mean_value_potency = np.zeros(
        (retinal_image.labels.shape[0], retinal_image.labels.shape[1]))

    max_labels = np.amax(retinal_image.labels)
    distanceTransform = ndimage.distance_transform_edt(retinal_image.vessels)
    diameter = distanceTransform * retinal_image.skeletonWithoutCrossings
    meanDiameterInRegion = np.zeros(np.max(retinal_image.labels))

    for i in range(1, max_labels + 1):
        meanDiameterInRegion[i - 1] = np.mean(
            diameter[retinal_image.labels == (i)])
        disk_diameter = meanDiameterInRegion[i - 1]
        #        disk_diameter=2;
        disk_diameter_large = 2 * disk_diameter
        labels_points = (retinal_image.labels == i)
        labels_points_indexes = np.nonzero(labels_points)
        labels_points_indexes = list(labels_points_indexes)
        rows = (labels_points_indexes)[0]
        cols = (labels_points_indexes)[1]
        #labels_points_int=labels_points.astype(int)
        #mean_intensity[rows,cols]=mean(img_rgb[labels_points==True], disk(disk_diameter))
        #mean_intensity[rows,cols]=mean(red_channel[rows,cols], disk(disk_diameter))
        #mean- large
        mean_red_intensity_large_iteration = mean(red_channel,
                                                  disk(disk_diameter_large))
        mean_red_intensity_large[
            rows, cols] = mean_red_intensity_large_iteration[rows, cols]
        mean_green_intensity_large_iteration = mean(green_channel,
                                                    disk(disk_diameter_large))
        mean_green_intensity_large[
            rows, cols] = mean_green_intensity_large_iteration[rows, cols]
        mean_blue_intensity_large_iteration = mean(blue_channel,
                                                   disk(disk_diameter_large))
        mean_blue_intensity_large[
            rows, cols] = mean_blue_intensity_large_iteration[rows, cols]
        mean_hue_large_iteration = mean(hue_channel, disk(disk_diameter_large))
        mean_hue_large[rows, cols] = mean_hue_large_iteration[rows, cols]
        mean_saturation_large_iteration = mean(saturation_channel,
                                               disk(disk_diameter_large))
        mean_saturation_large[rows,
                              cols] = mean_saturation_large_iteration[rows,
                                                                      cols]
        mean_value_large_iteration = mean(value_channel,
                                          disk(disk_diameter_large))
        mean_value_large[rows, cols] = mean_value_large_iteration[rows, cols]
        #mean- small
        mean_red_intensity_iteration = mean(red_channel, disk(disk_diameter))
        mean_red_intensity[rows, cols] = mean_red_intensity_iteration[rows,
                                                                      cols]
        mean_green_intensity_iteration = mean(green_channel,
                                              disk(disk_diameter))
        mean_green_intensity[rows, cols] = mean_green_intensity_iteration[rows,
                                                                          cols]
        mean_blue_intensity_iteration = mean(blue_channel, disk(disk_diameter))
        mean_blue_intensity[rows, cols] = mean_blue_intensity_iteration[rows,
                                                                        cols]
        mean_hue_iteration = mean(hue_channel, disk(disk_diameter))
        mean_hue[rows, cols] = mean_hue_iteration[rows, cols]
        mean_saturation_iteration = mean(saturation_channel,
                                         disk(disk_diameter))
        mean_saturation[rows, cols] = mean_saturation_iteration[rows, cols]
        mean_value_iteration = mean(value_channel, disk(disk_diameter))
        mean_value[rows, cols] = mean_value_iteration[rows, cols]
        #minimum- large
        minimum_red_intensity_iteration = minimum(red_channel,
                                                  disk(disk_diameter))
        minimum_red_intensity[rows,
                              cols] = minimum_red_intensity_iteration[rows,
                                                                      cols]
        minimum_green_intensity_iteration = minimum(green_channel,
                                                    disk(disk_diameter))
        minimum_green_intensity[rows,
                                cols] = minimum_green_intensity_iteration[rows,
                                                                          cols]
        minimum_blue_intensity_iteration = minimum(blue_channel,
                                                   disk(disk_diameter))
        minimum_blue_intensity[rows,
                               cols] = minimum_blue_intensity_iteration[rows,
                                                                        cols]
        minimum_hue_iteration = minimum(hue_channel, disk(disk_diameter))
        minimum_hue[rows, cols] = minimum_hue_iteration[rows, cols]
        minimum_saturation_iteration = minimum(saturation_channel,
                                               disk(disk_diameter))
        minimum_saturation[rows, cols] = minimum_saturation_iteration[rows,
                                                                      cols]
        minimum_value_iteration = minimum(value_channel, disk(disk_diameter))
        minimum_value[rows, cols] = minimum_value_iteration[rows, cols]
        #minimum- small
        minimum_red_intensity_large_iteration = minimum(
            red_channel, disk(disk_diameter_large))
        minimum_red_intensity_large[
            rows, cols] = minimum_red_intensity_large_iteration[rows, cols]
        minimum_green_intensity_large_iteration = minimum(
            green_channel, disk(disk_diameter_large))
        minimum_green_intensity_large[
            rows, cols] = minimum_green_intensity_large_iteration[rows, cols]
        minimum_blue_intensity_large_iteration = minimum(
            blue_channel, disk(disk_diameter_large))
        minimum_blue_intensity_large[
            rows, cols] = minimum_blue_intensity_large_iteration[rows, cols]
        minimum_hue_large_iteration = minimum(hue_channel,
                                              disk(disk_diameter_large))
        minimum_hue_large[rows, cols] = minimum_hue_large_iteration[rows, cols]
        minimum_saturation_large_iteration = minimum(saturation_channel,
                                                     disk(disk_diameter_large))
        minimum_saturation_large[
            rows, cols] = minimum_saturation_large_iteration[rows, cols]
        minimum_value_large_iteration = minimum(value_channel,
                                                disk(disk_diameter_large))
        minimum_value_large[rows, cols] = minimum_value_large_iteration[rows,
                                                                        cols]
        #maximum- large
        maximum_red_intensity_large_iteration = maximum(
            red_channel, disk(disk_diameter_large))
        maximum_red_intensity_large[
            rows, cols] = maximum_red_intensity_large_iteration[rows, cols]
        maximum_green_intensity_large_iteration = maximum(
            green_channel, disk(disk_diameter_large))
        maximum_green_intensity_large[
            rows, cols] = maximum_green_intensity_large_iteration[rows, cols]
        maximum_blue_intensity_large_iteration = maximum(
            blue_channel, disk(disk_diameter_large))
        maximum_blue_intensity_large[
            rows, cols] = maximum_blue_intensity_large_iteration[rows, cols]
        maximum_hue_large_iteration = maximum(hue_channel,
                                              disk(disk_diameter_large))
        maximum_hue_large[rows, cols] = maximum_hue_large_iteration[rows, cols]
        maximum_saturation_large_iteration = maximum(saturation_channel,
                                                     disk(disk_diameter_large))
        maximum_saturation_large[
            rows, cols] = maximum_saturation_large_iteration[rows, cols]
        maximum_value_large_iteration = maximum(value_channel,
                                                disk(disk_diameter_large))
        maximum_value_large[rows, cols] = maximum_value_large_iteration[rows,
                                                                        cols]
        #maximum- small
        maximum_red_intensity_iteration = maximum(red_channel,
                                                  disk(disk_diameter))
        maximum_red_intensity[rows,
                              cols] = maximum_red_intensity_iteration[rows,
                                                                      cols]
        maximum_green_intensity_iteration = maximum(green_channel,
                                                    disk(disk_diameter))
        maximum_green_intensity[rows,
                                cols] = maximum_green_intensity_iteration[rows,
                                                                          cols]
        maximum_blue_intensity_iteration = maximum(blue_channel,
                                                   disk(disk_diameter))
        maximum_blue_intensity[rows,
                               cols] = maximum_blue_intensity_iteration[rows,
                                                                        cols]
        maximum_hue_iteration = maximum(hue_channel, disk(disk_diameter))
        maximum_hue[rows, cols] = maximum_hue_iteration[rows, cols]
        maximum_saturation_iteration = maximum(saturation_channel,
                                               disk(disk_diameter))
        maximum_saturation[rows, cols] = maximum_saturation_iteration[rows,
                                                                      cols]
        maximum_value_iteration = maximum(value_channel, disk(disk_diameter))
        maximum_value[rows, cols] = maximum_value_iteration[rows, cols]
        #std-large
        #std red
        mean_red_intensity_large_iteration1 = mean(red_channel**2,
                                                   disk(disk_diameter_large))
        mean_red_intensity_large1[
            rows, cols] = mean_red_intensity_large_iteration1[rows, cols]
        mean_red_intensity_large_potency_iteration = mean(
            red_channel, disk(disk_diameter_large))
        mean_red_intensity_large_potency[
            rows, cols] = mean_red_intensity_large_potency_iteration[rows,
                                                                     cols]**2
        std_red = mean_red_intensity_large_potency - mean_red_intensity_large1
        std_red = np.abs(std_red)
        std_red_final = np.sqrt(std_red)
        #std green
        mean_green_intensity_large_iteration1 = mean(green_channel**2,
                                                     disk(disk_diameter_large))
        mean_green_intensity_large1[
            rows, cols] = mean_green_intensity_large_iteration1[rows, cols]
        mean_green_intensity_large_potency_iteration = mean(
            green_channel, disk(disk_diameter_large))
        mean_green_intensity_large_potency[
            rows, cols] = mean_green_intensity_large_potency_iteration[rows,
                                                                       cols]**2
        std_green = mean_green_intensity_large_potency - mean_green_intensity_large1
        std_green = np.abs(std_green)
        std_green_final = np.sqrt(std_green)
        #std Blue
        mean_blue_intensity_large_iteration1 = mean(blue_channel**2,
                                                    disk(disk_diameter_large))
        mean_blue_intensity_large1[
            rows, cols] = mean_blue_intensity_large_iteration1[rows, cols]
        mean_blue_intensity_large_potency_iteration = mean(
            blue_channel, disk(disk_diameter_large))
        mean_blue_intensity_large_potency[
            rows, cols] = mean_blue_intensity_large_potency_iteration[rows,
                                                                      cols]**2
        std_blue = mean_blue_intensity_large_potency - mean_blue_intensity_large1
        std_blue = np.abs(std_blue)
        std_blue_final = np.sqrt(std_blue)
        #std hue
        mean_hue_large_iteration1 = mean(hue_channel**2,
                                         disk(disk_diameter_large))
        mean_hue_large1[rows, cols] = mean_hue_large_iteration1[rows, cols]
        mean_hue_large_potency_iteration = mean(hue_channel,
                                                disk(disk_diameter_large))
        mean_hue_large_potency[rows, cols] = mean_hue_large_potency_iteration[
            rows, cols]**2
        std_hue = mean_hue_large_potency - mean_hue_large1
        std_hue = np.abs(std_hue)
        std_hue_final = np.sqrt(std_hue)
        #std saturation
        mean_saturation_large_iteration1 = mean(saturation_channel**2,
                                                disk(disk_diameter_large))
        mean_saturation_large1[rows,
                               cols] = mean_saturation_large_iteration1[rows,
                                                                        cols]
        mean_saturation_large_potency_iteration = mean(
            saturation_channel, disk(disk_diameter_large))
        mean_saturation_large_potency[
            rows, cols] = mean_saturation_large_potency_iteration[rows,
                                                                  cols]**2
        std_saturation = mean_saturation_large_potency - mean_saturation_large1
        std_saturation = np.abs(std_saturation)
        std_saturation_final = np.sqrt(std_saturation)
        #std Value
        mean_value_large_iteration1 = mean(value_channel**2,
                                           disk(disk_diameter_large))
        mean_value_large1[rows, cols] = mean_value_large_iteration1[rows, cols]
        mean_value_large_potency_iteration = mean(value_channel,
                                                  disk(disk_diameter_large))
        mean_value_large_potency[
            rows, cols] = mean_value_large_potency_iteration[rows, cols]**2
        std_value = mean_value_large_potency - mean_value_large1
        std_value = np.abs(std_value)
        std_value_final = np.sqrt(std_value)
        #std-small
        #std red
        mean_red_intensity_iteration1 = mean(red_channel**2,
                                             disk(disk_diameter))
        mean_red_intensity_1[rows, cols] = mean_red_intensity_iteration1[rows,
                                                                         cols]
        mean_red_intensity_potency_iteration = mean(red_channel,
                                                    disk(disk_diameter))
        mean_red_intensity_potency[
            rows, cols] = mean_red_intensity_potency_iteration[rows, cols]**2
        std_red_small = mean_red_intensity_potency - mean_red_intensity_1
        std_red_small = np.abs(std_red_small)
        std_red_final_small = np.sqrt(std_red_small)
        #std green
        mean_green_intensity_iteration1 = mean(green_channel**2,
                                               disk(disk_diameter))
        mean_green_intensity_1[rows,
                               cols] = mean_green_intensity_iteration1[rows,
                                                                       cols]
        mean_green_intensity_potency_iteration = mean(green_channel,
                                                      disk(disk_diameter))
        mean_green_intensity_potency[
            rows, cols] = mean_green_intensity_potency_iteration[rows, cols]**2
        std_green_small = mean_green_intensity_potency - mean_green_intensity_1
        std_green_small = np.abs(std_green_small)
        std_green_final_small = np.sqrt(std_green_small)
        #std Blue
        mean_blue_intensity_iteration1 = mean(blue_channel**2,
                                              disk(disk_diameter))
        mean_blue_intensity_1[rows,
                              cols] = mean_blue_intensity_iteration1[rows,
                                                                     cols]
        mean_blue_intensity_potency_iteration = mean(blue_channel,
                                                     disk(disk_diameter))
        mean_blue_intensity_potency[
            rows, cols] = mean_blue_intensity_potency_iteration[rows, cols]**2
        std_blue_small = mean_blue_intensity_potency - mean_blue_intensity_1
        std_blue_small = np.abs(std_blue_small)
        std_blue_final_small = np.sqrt(std_blue_small)
        #std hue
        mean_hue_iteration1 = mean(hue_channel**2, disk(disk_diameter))
        mean_hue_1[rows, cols] = mean_hue_iteration1[rows, cols]
        mean_hue_potency_iteration = mean(hue_channel, disk(disk_diameter))
        mean_hue_potency[rows, cols] = mean_hue_potency_iteration[rows,
                                                                  cols]**2
        std_hue_small = mean_hue_potency - mean_hue_1
        std_hue_small = np.abs(std_hue_small)
        std_hue_final_small = np.sqrt(std_hue_small)
        #std saturation
        mean_saturation_iteration1 = mean(saturation_channel**2,
                                          disk(disk_diameter))
        mean_saturation_1[rows, cols] = mean_saturation_iteration1[rows, cols]
        mean_saturation_potency_iteration = mean(saturation_channel,
                                                 disk(disk_diameter))
        mean_saturation_potency[
            rows, cols] = mean_saturation_potency_iteration[rows, cols]**2
        std_saturation_small = mean_saturation_potency - mean_saturation_1
        std_saturation_small = np.abs(std_saturation_small)
        std_saturation_final_small = np.sqrt(std_saturation_small)
        #std Value
        mean_value_iteration1 = mean(value_channel**2, disk(disk_diameter))
        mean_value_1[rows, cols] = mean_value_iteration1[rows, cols]
        mean_value_potency_iteration = mean(value_channel, disk(disk_diameter))
        mean_value_potency[rows, cols] = mean_value_potency_iteration[rows,
                                                                      cols]**2
        std_value_small = mean_value_potency - mean_value_1
        std_value_small = np.abs(std_value_small)
        std_value_final_small = np.sqrt(std_value_small)

        #print(mean_intensity)
        print(i, ':', disk_diameter)
    return mean_red_intensity_large, mean_green_intensity_large, mean_blue_intensity_large, mean_hue_large, mean_saturation_large, mean_value_large, mean_red_intensity, mean_green_intensity, mean_blue_intensity, mean_hue, mean_saturation, mean_value, minimum_red_intensity_large, minimum_green_intensity_large, minimum_blue_intensity_large, minimum_hue_large, minimum_saturation_large, minimum_value_large, minimum_red_intensity, minimum_green_intensity, minimum_blue_intensity, minimum_hue, minimum_saturation, minimum_value, maximum_red_intensity_large, maximum_green_intensity_large, maximum_blue_intensity_large, maximum_hue_large, maximum_saturation_large, maximum_value_large, maximum_red_intensity, maximum_green_intensity, maximum_blue_intensity, maximum_hue, maximum_saturation, maximum_value, std_red_final, std_green_final, std_blue_final, std_hue_final, std_saturation_final, std_value_final, std_red_final_small, std_green_final_small, std_blue_final_small, std_hue_final_small, std_saturation_final_small, std_value_final_small
Exemple #38
0
    height = bbox[2] - bbox[0]
    return max([width / height, height / width])


color_map = {0: 50, 1: 100, 2: 150, 3: 200, 4: 250}


def change_colours_for_clusters(labeled_img, k_means_labels,
                                amount_of_objects):
    for i_object in range(1, amount_of_objects + 1):
        np.place(labeled_img, labeled_img == i_object,
                 color_map[k_means_labels[i_object - 1]])


img = img_as_float(imread('P0001460.jpg'))
binary_img = rank.maximum(rank.minimum(image_to_binary(rgb2grey(img)),
                                       selem=disk(2)),
                          selem=disk(2))

show_image(img)
show_image(binary_img)

labeled_array, num_features = ndimage.label(binary_img)

properties = regionprops(labeled_array, coordinates='xy')

k_means_list = list(
    map(
        lambda x: [
            x.area, x.perimeter, x.perimeter**2 / x.area,
            calculate_elongation(x.bbox), x.orientation, x.extent
        ], properties))