Ejemplo n.º 1
0
def mainProcess(image_original, image_transformed):
    global pathIn
    global keypoints_original_blob
    global keypoints_transformed_blob
    image_gray = rgb2gray(image_transformed)
    img_path_original = skimage.io.imread(pathIn)
    img_original = rgb2gray(image_original)

    blobs_doh = blob_doh(img_original,
                         min_sigma=1,
                         max_sigma=30,
                         num_sigma=10,
                         threshold=0.01,
                         overlap=0.5,
                         log_scale=False)
    keypoints_original_blob = blobs_doh

    blobs_doh2 = blob_doh(image_gray,
                          min_sigma=1,
                          max_sigma=30,
                          num_sigma=10,
                          threshold=0.01,
                          overlap=0.5,
                          log_scale=False)
    keypoints_transformed_blob = blobs_doh2

    return blobs_doh, blobs_doh2
Ejemplo n.º 2
0
    def _detect_specimens(self,
                          reconstructed_wave,
                          propagation_distance,
                          margin=100,
                          kernel_radius=4.0,
                          save_png_to_disk=None):
        cropped_img = reconstructed_wave.phase[margin:-margin, margin:-margin]
        best_convolved_phase = convolve_fft(cropped_img,
                                            MexicanHat2DKernel(kernel_radius))

        best_convolved_phase_copy = best_convolved_phase.copy(order='C')

        # Find positive peaks
        blob_doh_kwargs = dict(threshold=0.00007, min_sigma=2, max_sigma=10)
        blobs = blob_doh(best_convolved_phase_copy, **blob_doh_kwargs)

        # Find negative peaks
        negative_phase = -best_convolved_phase_copy
        negative_phase += (np.median(best_convolved_phase_copy) -
                           np.median(negative_phase))
        negative_blobs = blob_doh(negative_phase, **blob_doh_kwargs)

        all_blobs = []
        for blob in blobs:
            if blob.size > 0:
                all_blobs.append(blob)

        for neg_blob in negative_blobs:
            if neg_blob.size > 0:
                all_blobs.append(neg_blob)

        if len(all_blobs) > 0:
            all_blobs = np.vstack(all_blobs)

        # If save pngs:
        if save_png_to_disk is not None:
            path = "{0}/{1:.4f}.png".format(save_png_to_disk,
                                            propagation_distance)
            save_scaled_image(reconstructed_wave.phase, path, margin,
                              all_blobs)

        # Blobs get returned in rows with [x, y, radius], so save each
        # set of blobs with the propagation distance to record z

        # correct blob positions for margin:
        all_blobs = np.float64(all_blobs)
        if len(all_blobs) > 0:
            all_blobs[:, 0] += margin
            all_blobs[:, 1] += margin
            all_blobs[:, 2] = propagation_distance
            return all_blobs
        else:
            return None
Ejemplo n.º 3
0
    def _detect_specimens(self, reconstructed_wave, propagation_distance,
                         margin=100, kernel_radius=4.0, save_png_to_disk=None):
        cropped_img = reconstructed_wave.phase[margin:-margin, margin:-margin]
        best_convolved_phase = convolve_fft(cropped_img,
                                            MexicanHat2DKernel(kernel_radius))

        best_convolved_phase_copy = best_convolved_phase.copy(order='C')

        # Find positive peaks
        blob_doh_kwargs = dict(threshold=0.00007,
                               min_sigma=2,
                               max_sigma=10)
        blobs = blob_doh(best_convolved_phase_copy, **blob_doh_kwargs)

        # Find negative peaks
        negative_phase = -best_convolved_phase_copy
        negative_phase += (np.median(best_convolved_phase_copy) -
                           np.median(negative_phase))
        negative_blobs = blob_doh(negative_phase, **blob_doh_kwargs)

        all_blobs = []
        for blob in blobs:
            if blob.size > 0:
                all_blobs.append(blob)

        for neg_blob in negative_blobs:
            if neg_blob.size > 0:
                all_blobs.append(neg_blob)

        if len(all_blobs) > 0:
            all_blobs = np.vstack(all_blobs)

        # If save pngs:
        if save_png_to_disk is not None:
            path = "{0}/{1:.4f}.png".format(save_png_to_disk,
                                            propagation_distance)
            save_scaled_image(reconstructed_wave.phase, path, margin, all_blobs)

        # Blobs get returned in rows with [x, y, radius], so save each
        # set of blobs with the propagation distance to record z

        # correct blob positions for margin:
        all_blobs = np.float64(all_blobs)
        if len(all_blobs) > 0:
            all_blobs[:, 0] += margin
            all_blobs[:, 1] += margin
            all_blobs[:, 2] = propagation_distance
            return all_blobs
        else:
            return None
Ejemplo n.º 4
0
def blob_image_multiscale2(image, type=0, scale=2):
    # function that return a list of blob_coordinates, 0 = dog, 1 = doh, 2 = log
    list = []
    image = norm.normalize(image)
    for z, slice in tqdm(enumerate(image)):
        # init list of different sigma/zoom blobs
        featureblobs = []
        # x = 0,1,2,3,4
        if scale == 2:
            # for x in xrange(0,6):
            #     if type == 0:
            #         featureblobs.append(feature.blob_dog(slice, 2**x, 2**x))
            #     if type == 1:
            #         featureblobs.append(feature.blob_doh(slice, 2**x, 2**x))
            #     if type == 2:
            #         featureblobs.append(feature.blob_log(slice, 2**x, 2**x))
            for x in xrange(0, 5):
                if type == 0:
                    featureblobs.append(
                        feature.blob_dog(slice, 2**x, 2**(x + 1)))
                if type == 1:
                    featureblobs.append(
                        feature.blob_doh(slice, 2**x, 2**(x + 1)))
                if type == 2:
                    featureblobs.append(
                        feature.blob_log(slice, 2**x, 2**(x + 1), 16, .1))
        else:
            for x in xrange(0, 4):
                if type == 0:
                    featureblobs.append(feature.blob_dog(slice, 3**x, 3**x))
                if type == 1:
                    featureblobs.append(feature.blob_doh(slice, 3**x, 3**x))
                if type == 2:
                    featureblobs.append(feature.blob_log(slice, 3**x, 3**x))
        # init list of blob coords
        blob_coords = []
        #print featureblobs
        # start at biggest blob size
        for featureblob in reversed(featureblobs):
            # for every blob found of a blobsize

            for blob in enumerate(featureblob):
                # if that blob is not within range of another blob, add it
                blob = blob[1]
                if not within_range(blob, blob_coords):
                    blob_coords.append([z, blob[0], blob[1], blob[2]])
        list.append(blob_coords)
    return list
Ejemplo n.º 5
0
def create_blob_sequence(image):
    """
    Apply multiple blob detection algorithms to compare them
    
    :param image: image to be analysed
    :return: squenece containing the blobs, colors and titles
    """
    blobs_log = blob_log(image,
                         min_sigma=15,
                         max_sigma=40,
                         num_sigma=10,
                         overlap=1)

    # Compute radii in the 3rd column.
    blobs_log[:, 2] = blobs_log[:, 2] * sqrt(2)

    blobs_dog = blob_dog(image, min_sigma=5, max_sigma=40, overlap=1)
    blobs_dog[:, 2] = blobs_dog[:, 2] * sqrt(2)

    blobs_doh = blob_doh(image, min_sigma=5, max_sigma=40, overlap=1)

    blobs_list = [blobs_log, blobs_dog, blobs_doh]
    colors = ["yellow", "green", "black", "blue"]
    titles = [
        "Laplacian of Gaussian",
        "Difference of Gaussian",
        "Determinant of Hessian",
    ]
    sequence = zip(blobs_list, colors, titles)

    return sequence
Ejemplo n.º 6
0
    def scikit_blob(frame):
        h, w = frame.shape[:2]
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        rois = []
        if config.L_GAUSSIAN_DETECTION:
            blobs_log = blob_log(gray,
                                 max_sigma=config.L_GAUSSIAN_MAX_SIGMA,
                                 num_sigma=config.L_GAUSSIAN_NUM_SIGMA,
                                 threshold=config.L_GAUSSIAN_THRESHOLD)
            blobs_log[:, 2] = blobs_log[:, 2] * sqrt(2)
            rois.extend(blobs_log)

        if config.D_GAUSSIAN_DETECTION:
            blobs_dog = blob_dog(gray,
                                 max_sigma=config.D_GAUSSIAN_MAX_SIGMA,
                                 threshold=config.D_GAUSSIAN_THRESHOLD)
            blobs_dog[:, 2] = blobs_dog[:, 2] * sqrt(2)
            rois.extend(blobs_dog)

        if config.HESSIAN_DETECTION:
            blobs_doh = blob_doh(gray,
                                 max_sigma=config.HESSIAN_MAX_SIGMA,
                                 min_sigma=config.HESSIAN_MIN_SIGMA,
                                 threshold=config.HESSIAN_THRESHOLD)
            rois.extend(blobs_doh)

        candidates = []
        for roi in rois:
            (y, x, r) = roi
            r = 2.5 * r
            candidates.append([x, y, 2 * r, 2 * r])
        return candidates
Ejemplo n.º 7
0
def find_blobs(filename):
    feature = ""
    raw_image = io.imread(filename)
    for channel in range(0, 4):
        if channel < 3:
            image = raw_image[:,:,channel]
        image_gray = rgb2gray(image)

        # Smoothing
        image_gray = img_as_ubyte(image_gray)
        image_gray = mean_bilateral(image_gray.astype(numpy.uint16), disk(20), s0=10, s1=10)

        # Increase contrast
        image_gray = exposure.equalize_adapthist(image_gray, clip_limit=0.03)

        # Find blobs
        blobs_doh = blob_doh(image_gray, min_sigma=1, max_sigma=20, threshold=.005)
        count = 0
        for blob in blobs_doh:
            y, x, r = blob
            if (x-400)**2 + (y-400)**2 > distance:
                continue
            count = count + 1
        feature = feature + " " + str(channel + 1) + ":" + str(count)
    return feature
Ejemplo n.º 8
0
def main():
    numberOfImages = 11

    # TODO: AUTOMATICALLY GET NUMBER OF IMAGES
    # Get number of images. Remeber to divide by 2 as for every relevant image,
    # theres also the comparison image.
    # if ".DS_Store" in os.listdir("Wheat_ROIs"):
    #     numberOfImages = (len(os.listdir("Wheat_ROIs")) - 1)/2;
    # else:
    #     numberOfImages = len(os.listdir("Wheat_ROIs"))/2;

    # For each ROI image in folder
    for i in tqdm.tqdm(range(1, numberOfImages + 1)):
        # Load image
        filename = "../Wheat_ROIs/{:03d}_ROI.png".format(i)
        img = misc.imread(filename)
        img_gray = rgb2gray(img)

        # Detect blobs. See http://scikit-image.org/docs/dev/api/skimage.feature.html#skimage.feature.blob_doh
        # for function documentation
        blobs = blob_doh(img_gray, min_sigma=1, max_sigma=100, threshold=.01)

        # Display blobs on image and save image
        fig, ax = plt.subplots()
        plt.title("Number of Blobs Detected: {}".format(blobs.shape[0]))
        plt.grid(False)
        ax.imshow(img, interpolation='nearest')
        for blob in blobs:
            y, x, r = blob
            c = plt.Circle((x, y), r, color='red', linewidth=2, fill=False)
            ax.add_patch(c)
        fig.savefig("../Wheat_ROIs/{:03d}_Blob.png".format(i))
Ejemplo n.º 9
0
def blob_detections(image):
    
    image_gray = rgb2gray(image).astype('float64')/255
    
    blobs_log = blob_log(1-image_gray, max_sigma=20, num_sigma=10, threshold=0.15)
    
    # Compute radii in the 3rd column.
    blobs_log[:, 2] = blobs_log[:, 2] * sqrt(2)
    
    blobs_dog = blob_dog(1-image_gray, max_sigma=20, threshold=0.5)
    blobs_dog[:, 2] = blobs_dog[:, 2] * sqrt(2)
    
    blobs_doh = blob_doh(1-image_gray, max_sigma=20, threshold=.002)
    
    blobs_list = [blobs_log, blobs_dog, blobs_doh]
    colors = ['yellow', 'lime', 'red']
    titles = ['Laplacian of Gaussian', 'Difference of Gaussian',
              'Determinant of Hessian']
    sequence = zip(blobs_list, colors, titles)
    
    fig, axes = plt.subplots(1, 3, figsize=(9, 3), sharex=True, sharey=True,
                             subplot_kw={'adjustable': 'box-forced'})
    ax = axes.ravel()
    
    for idx, (blobs, color, title) in enumerate(sequence):
        ax[idx].set_title(title)
        ax[idx].imshow(image, interpolation='nearest', cmap='gray')
        for blob in blobs:
            y, x, r = blob
            c = plt.Circle((x, y), r, color=color, linewidth=2, fill=False)
            ax[idx].add_patch(c)
        ax[idx].set_axis_off()
    
    plt.tight_layout()
    plt.show()
Ejemplo n.º 10
0
def hlpr(image):
    image = data.hubble_deep_field()[0:500, 0:500]
    image_gray = rgb2gray(image)

    blobs_log = blob_log(image_gray, max_sigma=30, num_sigma=10, threshold=.1)
    # Compute radii in the 3rd column.
    blobs_log[:, 2] = blobs_log[:, 2] * sqrt(2)

    blobs_dog = blob_dog(image_gray, max_sigma=30, threshold=.1)
    blobs_dog[:, 2] = blobs_dog[:, 2] * sqrt(2)

    blobs_doh = blob_doh(image_gray, max_sigma=30, threshold=.01)

    blobs_list = [blobs_log, blobs_dog, blobs_doh]
    colors = ['yellow', 'lime', 'red']
    titles = [
        'Laplacian of Gaussian', 'Difference of Gaussian',
        'Determinant of Hessian'
    ]
    sequence = zip(blobs_list, colors, titles)

    for blobs, color, title in sequence:
        fig, ax = plt.subplots(1, 1)
        ax.set_title(title)
        ax.imshow(image, interpolation='nearest')
        for blob in blobs:
            y, x, r = blob
            c = plt.Circle((x, y), r, color=color, linewidth=2, fill=False)
            ax.add_patch(c)

    plt.show()
Ejemplo n.º 11
0
    def circles(self, filename):
        image = cv2.imread(filename, 0)
        image_gray = rgb2gray(image)

        blobs_log = blob_log(image_gray, max_sigma=30, num_sigma=10, threshold=.1)

        # Compute radii in the 3rd column.
        blobs_log[:, 2] = blobs_log[:, 2] * sqrt(2)

        blobs_dog = blob_dog(image_gray, max_sigma=30, threshold=.1)
        blobs_dog[:, 2] = blobs_dog[:, 2] * sqrt(2)

        blobs_doh = blob_doh(image_gray, max_sigma=30, threshold=.01)

        blobs_list = [blobs_log, blobs_doh]
        colors = ['yellow', 'red']
        titles = ['Laplacian of Gaussian', 'Determinant of Hessian']
        sequence = zip(blobs_list, colors, titles)

        fig, axes = plt.subplots(1, 2, sharex=True, sharey=True, subplot_kw={'adjustable': 'box-forced'})
        axes = axes.ravel()

        for blobs, color, title in sequence:
            ax = axes[0]
            axes = axes[1:]
            ax.set_title(title)
            ax.imshow(image, interpolation='nearest')
            for blob in blobs:
                y, x, r = blob
                c = plt.Circle((x, y), r, color=color, linewidth=2, fill=False)
                ax.add_patch(c)

        plt.savefig('output.png')
        plt.show()
def flowerCount(image_tuple):

    (key, value) = image_tuple

    global flower_area_mask

    # Get flower mask for this image
    ImageFile.LOAD_TRUNCATED_IMAGES = True

    image_value = np.array(value)
    img = image_value[:, :, ::-1]

    # Highlight flowers
    # 77 is the begining of the image name after removing file path
    img_flowers = getFlowerHighlight(img, key[77:], segm_dist_from_zerocross=8)

    try:

        # Get number of flowers using blob counter on the B channel
        blobs = blob_doh(img_flowers, max_sigma=5, min_sigma=3)

        return key[77:], len(blobs), blobs

    except(IndexError) as e:

        pass
Ejemplo n.º 13
0
def test_blob_doh_2d(shape, blobs, min_sigma, max_sigma, num_sigma, overlap,
                     threshold, log_scale):
    a = generate_blobimage(shape, blobs)
    chunks = [e // 2 for e in shape]
    d = da.from_array(a, chunks=chunks)
    ski_r = ski_feat.blob_doh(
        a,
        min_sigma=min_sigma,
        max_sigma=max_sigma,
        num_sigma=num_sigma,
        threshold=threshold,
        overlap=overlap,
        log_scale=log_scale,
    )

    da_r = da_feat.blob_doh(
        d,
        min_sigma=min_sigma,
        max_sigma=max_sigma,
        num_sigma=num_sigma,
        threshold=threshold,
        overlap=overlap,
        log_scale=log_scale,
    )

    ski_r = sort_array(ski_r)
    da_r = sort_array(da_r)
    print(ski_r)
    print(da_r)
    # coordinates are sometimes off by 1 when using the determinant
    coord_diff = (ski_r - da_r)[:, :a.ndim]
    sigma_diff = (ski_r - da_r)[:, a.ndim:]
    assert np.all(coord_diff <= 1)
    assert np.all(np.abs(sigma_diff) <= 0.01)
Ejemplo n.º 14
0
def main():
    numberOfImages = 11;

    # TODO: AUTOMATICALLY GET NUMBER OF IMAGES
    # Get number of images. Remeber to divide by 2 as for every relevant image,
    # theres also the comparison image.
    # if ".DS_Store" in os.listdir("Wheat_ROIs"):
    #     numberOfImages = (len(os.listdir("Wheat_ROIs")) - 1)/2;
    # else:
    #     numberOfImages = len(os.listdir("Wheat_ROIs"))/2;

    # For each ROI image in folder
    for i in tqdm.tqdm(range(1, numberOfImages+1)):
        # Load image
        filename = "../Wheat_ROIs/{:03d}_ROI.png".format(i);
        img = misc.imread(filename);
        img_gray = rgb2gray(img);

        # Detect blobs. See http://scikit-image.org/docs/dev/api/skimage.feature.html#skimage.feature.blob_doh
        # for function documentation
        blobs = blob_doh(img_gray, min_sigma=1, max_sigma=100, threshold=.01)

        # Display blobs on image and save image
        fig, ax = plt.subplots()
        plt.title("Number of Blobs Detected: {}".format(blobs.shape[0]))
        plt.grid(False)
        ax.imshow(img, interpolation='nearest')
        for blob in blobs:
            y, x, r = blob
            c = plt.Circle((x, y), r, color='red', linewidth=2, fill=False)
            ax.add_patch(c)
        fig.savefig("../Wheat_ROIs/{:03d}_Blob.png".format(i))
Ejemplo n.º 15
0
    def computeFlowerCount(self, images):
        print("Computing flower count")

        for image in tqdm(images, file=sys.stdout):
            try:
                # Initialize dictionary to store number of flowers per image
                n_flowers = {}
                # Get flower mask for this image
                PIL.ImageFile.LOAD_TRUNCATED_IMAGES = True
                pil_image = PIL.Image.open(image).convert('RGB')
                open_cv_image = np.array(pil_image)
                img = open_cv_image[:, :, ::-1].copy()

                # Highlight flowers
                img_flowers = self.getFlowerHighlight(
                    img, image, segm_dist_from_zerocross=6)

                # Apply flower area mask
                img_flowers[self.flower_area_mask == 0] = 0

                # Get number of flowers using blob counter on the B channel
                blobs = blob_doh(img_flowers, max_sigma=5, min_sigma=3)

                # Append result
                n_flowers[image] = len(blobs)

            except IndexError:
                n_flowers[image] = []

            # Save to object
        self.flower_count = n_flowers
        self.flower_count_estimate = n_flowers
Ejemplo n.º 16
0
 def doh(self):
     image = np.asfarray(self.image, dtype=np.double)
     # skimage.feature.blob_doh(image, min_sigma=1, max_sigma=30,
     #     num_sigma=10, threshold=0.01, overlap=0.5, log_scale=False)
     blobs = feature.blob_doh(image, **self.blob_ka, **self.doh_ka)
     # Here, radius is approx. equal to sigma.
     return blobs
def detect_cells(image):
    image_gray = rgb2gray(image)

    blobs_log = blob_log(image_gray, max_sigma=30, num_sigma=10, threshold=.1)
    # Compute radii in the 3rd column.
    blobs_log[:, 2] = blobs_log[:, 2] * sqrt(2)

    blobs_dog = blob_dog(image_gray, max_sigma=30, threshold=.1)
    blobs_dog[:, 2] = blobs_dog[:, 2] * sqrt(2)

    blobs_doh = blob_doh(image_gray, max_sigma=30, threshold=.01)

    blobs_list = [blobs_log, blobs_dog, blobs_doh]
    colors = ['yellow', 'lime', 'red']
    titles = ['Laplacian of Gaussian', 'Difference of Gaussian',
          'Determinant of Hessian']
    sequence = zip(blobs_list, colors, titles)

    for blobs, color, title in sequence:
        fig, ax = plt.subplots(1, 1)
        ax.set_title(title)
        ax.imshow(image, interpolation='nearest')
        for blob in blobs:
            y, x, r = blob
            c = plt.Circle((x, y), r, color=color, linewidth=2, fill=False)
            ax.add_patch(c)

    plt.show()
Ejemplo n.º 18
0
def blob_detector(imIn, overlap, threshold, min_sigma, max_sigma, log_scale):
    """

    :param imIn:        Inverted Image grayscale patch
    :param:             Hyper-Parameters for blob detector
        :overlap
        :threshold
        :min_sigma
        :max_sigma
        log_scale
    :return:
    """
    # Initialize and Invoke DoH blob detector
    blobs_doh = blob_doh(imIn, overlap=overlap, threshold=threshold, min_sigma=min_sigma,
                         max_sigma=max_sigma, log_scale=log_scale)
    #blobs_y, blobs_x, blobs_r = [],[],[]
    blobs_y = blobs_doh[:,0]
    blobs_x = blobs_doh[:,1]
    blobs_r = blobs_doh[:,2]
    """for blob in blobs_doh:
        y, x, r = blob # This code can be made better
        blobs_y.append(y)
        blobs_x.append(x)
        blobs_r.append(r)"""
    return blobs_y, blobs_x, blobs_r
Ejemplo n.º 19
0
def test_blob_overlap():
    img = np.ones((256, 256), dtype=np.uint8)

    xs, ys = circle(100, 100, 20)
    img[xs, ys] = 255

    xs, ys = circle(120, 100, 30)
    img[xs, ys] = 255

    blobs = blob_doh(img,
                     min_sigma=1,
                     max_sigma=60,
                     num_sigma=10,
                     threshold=.05)

    assert len(blobs) == 1

    r1, r2 = 7, 6
    pad1, pad2 = 11, 12
    blob1 = ellipsoid(r1, r1, r1)
    blob1 = util.pad(blob1, pad1, mode='constant')
    blob2 = ellipsoid(r2, r2, r2)
    blob2 = util.pad(blob2, [(pad2, pad2), (pad2 - 9, pad2 + 9), (pad2, pad2)],
                     mode='constant')
    im3 = np.logical_or(blob1, blob2)

    blobs = blob_log(im3, min_sigma=2, max_sigma=10, overlap=0.1)
    assert len(blobs) == 1

    # Two circles with distance between centers equal to radius
    overlap = _blob_overlap(np.array([0, 0, 10 / math.sqrt(2)]),
                            np.array([0, 10, 10 / math.sqrt(2)]))
    assert_almost_equal(
        overlap, 1. / math.pi * (2 * math.acos(1. / 2) - math.sqrt(3) / 2.))
    def flowerCount(self, imageRDD):
        (key, value) = imageRDD
        # Trace
        print "Computing flower count"

        # Get flower mask for this image
        ImageFile.LOAD_TRUNCATED_IMAGES = True
        #pil_image = PIL.Image.open(value).convert('RGB')
        open_cv_image = np.array(value)
        img = open_cv_image[:, :, ::-1]

        # Highlight flowers
        img_flowers = self.getFlowerHighlight(img,
                                              key,
                                              segm_dist_from_zerocross=6)

        # Apply flower area mask
        img_flowers[self.flower_area_mask == 0] = 0

        try:
            # Get number of flowers using blob counter on the B channel
            blobs = blob_doh(img_flowers, max_sigma=5, min_sigma=3)

            n_blobs = len(blobs)

            return key, n_blobs

        except (IndexError) as e:
            pass
def flowerCount(input):
    
    (key, value) = input

    #global flower_area_mask_accum
    global flower_area_mask
    
    # Get flower mask for this image
    ImageFile.LOAD_TRUNCATED_IMAGES = True
    
    open_cv_image = np.array(value)
    img = open_cv_image[:, :, ::-1]

    # Highlight flowers
    img_flowers = getFlowerHighlight(img, key, segm_dist_from_zerocross=8)

    # Apply flower area mask
    img_flowers[flower_area_mask == 0] = 0

    try:
        # Get number of flowers using blob counter on the B channel
        blobs = blob_doh(img_flowers, max_sigma=5, min_sigma=1)
   
        n_blobs = len(blobs)

        return key, n_blobs

    except (IndexError) as e:
        
        pass
Ejemplo n.º 22
0
def srf_detector(image):
    if_detected = False
    mask = create_bg1_mask(image)
    image_cropped_1, bbox = crop_to_mask(image, mask)
    image_cropped = rgb2gray(image_cropped_1)
    image_cropped = denoise_bilateral(image_cropped,
                                      sigma_spatial=2,
                                      multichannel=False)
    image_cropped = equalize_adapthist(image_cropped)

    x = numpy.arange(image_cropped.shape[1])
    first_notmask_x = [first_notmask(i, mask, bbox, image_cropped) for i in x]
    plotted = ransac(x, first_notmask_x, image_cropped)

    if plotted:
        result = 'No SRF detected'
        fig, ax = plt.subplots(1, 1, figsize=(9, 3), sharex=True, sharey=True)
        ax.set_title('Cropped Image')
        ax.imshow(image_cropped, cmap=plt.cm.gray, interpolation='nearest')

    if plotted == False:
        #only if no line can be fitted will the function try to find blobs
        x_tot, y_tot = image_cropped.shape[0], image_cropped.shape[1]

        blobs_doh = blob_doh(image_cropped, max_sigma=50, threshold=.0045)

        plt.rcParams['image.cmap'] = 'gray'
        result = 'No SRF detected'
        fig, ax = plt.subplots(1, 1, figsize=(9, 3), sharex=True, sharey=True)
        for blob in blobs_doh:
            ax.set_title('Detected SRF in red')
            ax.imshow(image_cropped, cmap=plt.cm.gray, interpolation='nearest')
            y, x, r = blob
            c = plt.Circle((x, y), r, color='blue', linewidth=2, fill=False)
            ax.add_patch(c)
            p = True
            f_x = first_notmask(int(x), mask, bbox, image_cropped)
            if (r > 1) and (r < 20) and (x > 30) and (x < y_tot - 30) and (
                    y > 50) and (y < x_tot - 50) and is_dark(
                        image_cropped, x,
                        y) and (y > f_x + (1 / 4) *
                                (image_cropped.shape[0] - x)):
                for i in range(-int(r) - 3, int(r) + 1 + 3):
                    for j in range(-int(r) - 3, int(r) + 1 + 3):
                        if (mask[int(y) + bbox[1] + i,
                                 int(x) + bbox[0] + j] == 0):
                            p = False
                if p:
                    c = plt.Circle((x, y),
                                   r,
                                   color='red',
                                   linewidth=2,
                                   fill=False)
                    ax.add_patch(c)
                    result = 'SRF detected'
                    if_detected = True
    print(result)
    plt.show()
    return if_detected
Ejemplo n.º 23
0
def detect_blobs(preds):
    blobs = blob_doh(np.nan_to_num(preds), max_sigma=30, threshold=.05)
    if blobs.shape[0] > 0:
        #detected = pd.DataFrame(blobs_doh[blobs_doh[:,2] > 0], columns = ['x','y','r'])
        detected = pd.DataFrame(blobs, columns=['x', 'y', 'r'])
    else:
        detected = pd.DataFrame(columns=['x', 'y', 'r'])
    return detected
Ejemplo n.º 24
0
def detect_cell_boundary(img, sel_cmap):
    """Detect cell boundary and overlay the results on images, using blob
    detection algorithms: Laplacian of Gaussian, Difference of Gaussian,
    and Determinant of Hessian

    Args:
        img: input image

    Returns:
        blobs_list: list of detected blobs using different methods, following
            this order: log, dog, and doh. Each item is a sublist of blobs,
            where each sub-list item is x, y, and radius of a blob
    """
    # dummy = np.copy(img)
    dummy = util.invert(img)

    # Laplacian of Gaussian
    blobs_log = feature.blob_log(dummy, max_sigma=30, num_sigma=10,
                                 threshold=0.01)
    # Compute radii in the 3rd column.
    blobs_log[:, 2] = blobs_log[:, 2] * np.sqrt(2)

    # Difference of Gaussian
    blobs_dog = feature.blob_dog(dummy, max_sigma=30, threshold=0.01)
    blobs_dog[:, 2] = blobs_dog[:, 2] * np.sqrt(2)

    # Determinant of Hessian
    blobs_doh = feature.blob_doh(dummy, max_sigma=30, threshold=0.00065)

    # concatenate all results
    blobs_list = [blobs_log, blobs_dog, blobs_doh]
    colors = ['red', 'green', 'blue']
    titles = ['Laplacian of Gaussian', 'Difference of Gaussian',
              'Determinant of Hessian']

    # plot results
    fig, axes = plt.subplots(1, 3, figsize=(12, 4), sharex=True, sharey=True)
    ax = axes.ravel()
    for i in range(3):
        ax[i].set_title(titles[i])
        ax[i].imshow(img, sel_cmap)
        for blob in blobs_list[i]:
            y, x, r = blob
            c = plt.Circle((x, y), r, color=colors[i], linewidth=2, fill=False)
            ax[i].add_patch(c)
        ax[i].set_axis_off()
    plt.suptitle('Detect cell boundary using blob detection')

    # compute cell size
    print('Average cell size (in pixel^2):')
    for i in range(3):
        cell_size = 0.0
        for blob in blobs_list[i]:
            cell_size += np.pi * blob[2]**2
        if cell_size != 0.0:
            cell_size /= len(blobs_list[i])
        print('  - {}: {:.3f}'.format(titles[i], cell_size))
    pass
Ejemplo n.º 25
0
def test_blob_doh(dtype, threshold_type):
    img = np.ones((512, 512), dtype=dtype)

    xs, ys = disk((400, 130), 20)
    img[xs, ys] = 255

    xs, ys = disk((460, 50), 30)
    img[xs, ys] = 255

    xs, ys = disk((100, 300), 40)
    img[xs, ys] = 255

    xs, ys = disk((200, 350), 50)
    img[xs, ys] = 255

    if threshold_type == 'absolute':
        # Note: have to either scale up threshold or rescale the image to the
        #       range [0, 1] internally.
        threshold = 0.05
        if img.dtype.kind == 'f':
            # account for lack of internal scaling to [0, 1] by img_as_float
            ptp = img.ptp()
            threshold *= ptp**2
        threshold_rel = None
    elif threshold_type == 'relative':
        threshold = None
        threshold_rel = 0.5

    blobs = blob_doh(img,
                     min_sigma=1,
                     max_sigma=60,
                     num_sigma=10,
                     threshold=threshold,
                     threshold_rel=threshold_rel)

    radius = lambda x: x[2]
    s = sorted(blobs, key=radius)
    thresh = 4

    b = s[0]
    assert abs(b[0] - 400) <= thresh
    assert abs(b[1] - 130) <= thresh
    assert abs(radius(b) - 20) <= thresh

    b = s[1]
    assert abs(b[0] - 460) <= thresh
    assert abs(b[1] - 50) <= thresh
    assert abs(radius(b) - 30) <= thresh

    b = s[2]
    assert abs(b[0] - 100) <= thresh
    assert abs(b[1] - 300) <= thresh
    assert abs(radius(b) - 40) <= thresh

    b = s[3]
    assert abs(b[0] - 200) <= thresh
    assert abs(b[1] - 350) <= thresh
    assert abs(radius(b) - 50) <= thresh
Ejemplo n.º 26
0
def find2Dcontours(threeDdensity, axis=0, n_cut=100):
    '''

    blobs are assumed to be light on dark background

    each blob found, the method returns its coordinates and the standard deviation of the Gaussian kernel that detected the blob.


    Parameters
    ----------
    threeDdensity: 3D cube
        density cube

    axis: int
        along which axis to flatten in order for skimage to find 2D contours

    n_cut: float or int
        lowest level from which to start looking for contours

    N_cell_min: int
        not implemented at the moment

    overlap: float
        not implemented; between 0 and 1; if the area of two blobs overlaps by a fraction > this, smaller blob is eliminated.

    # min_sigma = 1     # keep it low for smaller blobs
    # max_sigma =       # keep it high to detect large blobs
    # num_sigma =

    '''

    axis = int(axis)

    from skimage.feature import blob_doh
    from skimage.color import rgb2gray

    c_min = n_cut

    # flatten image along some axis
    flattened_image = threeDdensity.sum(axis=axis)
    flattened_image = rgb2gray(flattened_image)

    # plot all contours found
    fig, ax = plt.subplots()
    ax.imshow(np.log10(flattened_image),
              interpolation='nearest',
              cmap=plt.cm.gray)
    coord_sigma = blob_doh(flattened_image, threshold=n_cut)

    for blob in coord_sigma:
        y, x, r = blob
        c = plt.Circle((x, y), r, color='r', linewidth=2, fill=False)
        ax.add_patch(c)
    plt.show(block=False)

    # blob_log(density, min_sigma=min_sigma, max_sigma=max_sigma, )

    return coord_sigma, flattened_image
Ejemplo n.º 27
0
    def precisionRecall(self):
        test_images = []
        test_blobs = []
        X = []
        Y_ground = []

        #Get blobs
        for i in range(500,505):
            file = self.croppedImages[i]
            iter_image = rgb2gray(cv2.imread(file))
            iter_blobs = blob_dog(iter_image, min_sigma=1, max_sigma=25,
                                  sigma_ratio=1.6, threshold=.25, overlap=0.5)
            test_images.append(iter_image)
            test_blobs.append(iter_blobs)
            print("Get blobs: " + str(i) + "/1000")

        #Get X values for testing
        for i in range(0, len(test_images)):
            RadPic = self.RadPIC(10, test_blobs[i], rgb2gray(test_images[i]))
            inputHOG = self.HOG(10, test_blobs[i], rgb2gray(test_images[i]))
            X.extend(self.makeX(RadPic, inputHOG))
            print("X: " + str(i) + "/1000")

        #Get Y ground truth values
        for i in range(500, 505):
            j = i
            tempStr = self.labels[j]

            while tempStr.find("frame" + str(i)) == -1:
                j = j + 1
                tempStr = self.labels[j]

            label_image = cv2.imread((glob.glob(tempStr))[0])
            cropped_image = cv2.imread((glob.glob("cropped_images/frame" + str(i) + ".jpg"))[0])
            cropped_image = rgb2gray(cropped_image)
            blobs = blob_doh(cropped_image, min_sigma=1, max_sigma=25, num_sigma=15, threshold=.001)
            for blob in blobs:
                y, x, r = blob
                if label_image[y,x][0] == 255 & label_image[y,x][1] == 255 & label_image[y,x][2] == 255:
                    Y_ground.append(1)
                else:
                    Y_ground.append(0)
                #print("Ground Truth: " + str(i) + "/1000")

        #Open classifier
        with open('croppedImagesV2.pkl', 'rb') as f:
            forest = pickle.load(f)

        #Precidicions
        Y_classifier = forest.predict(X)

        #Precision-Recall
        precision, recall, thresholds = precision_recall_curve(Y_ground, Y_classifier)

        plt.plot(recall, precision)
        plt.ylabel('Precision')
        plt.xlabel('Recall')
        plt.show()
Ejemplo n.º 28
0
def blob_image_multiscale2(image, type=0,scale=2):
    # function that return a list of blob_coordinates, 0 = dog, 1 = doh, 2 = log
    list = []
    image = norm.normalize(image)
    for z, slice in tqdm(enumerate(image)):
        # init list of different sigma/zoom blobs
        featureblobs = []
        # x = 0,1,2,3,4
        if scale == 2:
            # for x in xrange(0,6):
            #     if type == 0:
            #         featureblobs.append(feature.blob_dog(slice, 2**x, 2**x))
            #     if type == 1:
            #         featureblobs.append(feature.blob_doh(slice, 2**x, 2**x))
            #     if type == 2:
            #         featureblobs.append(feature.blob_log(slice, 2**x, 2**x))
            for x in xrange(0,5):
                if type == 0:
                    featureblobs.append(feature.blob_dog(slice, 2**x, 2**(x+1)))
                if type == 1:
                    featureblobs.append(feature.blob_doh(slice, 2**x, 2**(x+1)))
                if type == 2:
                    featureblobs.append(feature.blob_log(slice, 2**x, 2**(x+1),16,.1))
        else:
            for x in xrange(0,4):
                if type == 0:
                    featureblobs.append(feature.blob_dog(slice, 3**x, 3**x))
                if type == 1:
                    featureblobs.append(feature.blob_doh(slice, 3**x, 3**x))
                if type == 2:
                    featureblobs.append(feature.blob_log(slice, 3**x, 3**x))
        # init list of blob coords
        blob_coords = []
        #print featureblobs
        # start at biggest blob size
        for featureblob in reversed(featureblobs):
            # for every blob found of a blobsize

            for blob in enumerate(featureblob):
                # if that blob is not within range of another blob, add it
                blob = blob[1]
                if not within_range(blob, blob_coords):
                    blob_coords.append([z, blob[0], blob[1], blob[2]])
        list.append(blob_coords)
    return list
Ejemplo n.º 29
0
 def doh(self):
     """Determinant of Hessian."""
     # blob_doh requires double.
     image = np.asfarray(self.image, dtype=np.double)
     # skimage.feature.blob_doh(image, min_sigma=1, max_sigma=30,
     #     num_sigma=10, threshold=0.01, overlap=0.5, log_scale=False)
     blobs = feature.blob_doh(image, **self.blob_ka, **self.doh_ka)
     # Here, radius is approx. equal to sigma.
     return blobs
Ejemplo n.º 30
0
    def _identify_features(self, array):
        array = (array - array.min()) / array.max()
        for time in array.time.values:
            array2D = array.sel(time=time).values
            array2D.shape()
            blobs_doh = blob_doh(array2D, max_sigma=30, threshold=.01)
            print(';a')

        pass
Ejemplo n.º 31
0
    def process_image(self, new_image):
        # Find blobs in the image with scikit-image
        self.blobs = blob_doh(new_image,
                              max_sigma=512,
                              min_sigma=64,
                              threshold=.02)

        # Send the original image data to the image widget
        return new_image
Ejemplo n.º 32
0
def find_blobs(img_path):
    """Find the blobs in an image"""
    from skimage.color import rgb2gray
    from skimage.feature import blob_doh
    from skimage.io import imread

    image = imread(img_path)
    image_gray = rgb2gray(image)
    return image, blob_doh(image_gray, max_sigma=30, threshold=.01)
Ejemplo n.º 33
0
def find_blobs(img_path):
    """Find the blobs in an image"""
    from skimage.color import rgb2gray
    from skimage.feature import blob_doh
    from skimage.io import imread

    image = imread(img_path)
    image_gray = rgb2gray(image)
    return image, blob_doh(image_gray, max_sigma=30, threshold=.01)
Ejemplo n.º 34
0
def get_num_blobs(image):
    blobs_doh = blob_doh(image, min_sigma=1, max_sigma=20, threshold=.005)
    count = 0
    for blob in blobs_doh:
        y, x, r = blob
        if (x-400)**2 + (y-400)**2 > distance:
            continue
        count = count + 1
    return count
Ejemplo n.º 35
0
def get_convex_hull_of_blobs_doh(im):
    """
    Uses the Difference of Hessian blob detection algorithm from scikit-image to identify the laser points and returns
    a ConvexHull of the points found.
    :param im: Image with laser points in
    :return: ConvexHull of points
    """
    # Get blobs using Difference of Hessian
    blobs_doh = blob_doh(im, max_sigma=10, num_sigma=1, threshold=.005)
    # Compute radii in the 3rd column.
    blobs_doh[:, 2] = blobs_doh[:, 2] * sqrt(2) # ToDo: Discount blobs with large radii

    if 0 <= len(blobs_doh) < 4:
        blobs_doh = blob_doh(im, max_sigma=10, num_sigma=1, threshold=.0025)
    elif len(blobs_doh) > 4:
        blobs_doh = blob_doh(im, max_sigma=10, num_sigma=1, threshold=.0075)
    assert len(blobs_doh) == 4, len(blobs_doh)

    return ConvexHull([(blob[0], blob[1]) for blob in blobs_doh])
Ejemplo n.º 36
0
def evaluateDOH(grayImage):
    log = blob_doh(grayImage, max_sigma=30, threshold=.01)
    #log[:, 2] = log[:, 2] * sqrt(2)
    coordinates = np.empty((log.shape[0], 5))
    coordinates[:, 4] = 1
    coordinates[:, 0] = log[:, 1] - log[:, 2]
    coordinates[:, 1] = log[:, 0] - log[:, 2]
    coordinates[:, 2] = log[:, 1] + log[:, 2]
    coordinates[:, 3] = log[:, 0] + log[:, 2]
    return coordinates
Ejemplo n.º 37
0
    def review_methods(self, image: np.array = None):
        """
        Draws a comparison picture of all three methods.
        Doesn't work properly with binarized image.
        :param image: np.array, str
            Image array or image path
        :return:
        """

        if isinstance(image, str):
            image = cv2.imread(image, cv2.COLOR_RGB2GRAY)[..., ::-1]

        image_gray = rgb2gray(image)

        blobs_log = blob_log(image_gray,
                             max_sigma=50,
                             num_sigma=10,
                             threshold=0.1)

        # Compute radii in the 3rd column.
        blobs_log[:, 2] = blobs_log[:, 2] * np.sqrt(2)

        blobs_dog = blob_dog(image_gray, max_sigma=30, threshold=0.1)
        blobs_dog[:, 2] = blobs_dog[:, 2] * np.sqrt(2)

        blobs_doh = blob_doh(image_gray, max_sigma=30, threshold=0.01)

        blobs_list = [blobs_log, blobs_dog, blobs_doh]
        colors = ["yellow", "lime", "red"]
        titles = [
            "Laplacian of Gaussian",
            "Difference of Gaussian",
            "Determinant of Hessian",
        ]
        sequence = zip(blobs_list, colors, titles)

        fig, axes = plt.subplots(1,
                                 3,
                                 figsize=(9, 3),
                                 sharex=True,
                                 sharey=True)
        ax = axes.ravel()

        for idx, (blobs, color, title) in enumerate(sequence):
            ax[idx].set_title(title)
            ax[idx].imshow(image)
            for blob in blobs:
                y, x, r = blob
                c = plt.Circle((x, y), r, color=color, linewidth=2, fill=False)
                ax[idx].add_patch(c)
            ax[idx].set_axis_off()

        plt.tight_layout()
        plt.show()
Ejemplo n.º 38
0
 def get_blobs(self, image):
   blobs_log = blob_log(image, max_sigma=30, num_sigma=10, threshold=.1)
   blobs_log[:, 2] = blobs_log[:, 2] * sqrt(2)
   blobs_dog = blob_dog(image, max_sigma=30, threshold=.1)
   blobs_dog[:, 2] = blobs_dog[:, 2] * sqrt(2)
   blobs_doh = blob_doh(image, max_sigma=30, threshold=.01)
   
   all_blobs = np.vstack([blobs_log, blobs_doh, blobs_dog])
   all_blobs = filter(lambda b: b[2] > 4, all_blobs)
   all_blobs = list(filter(lambda b: b[2] < 60, all_blobs))
   return all_blobs
Ejemplo n.º 39
0
 def preview(self, ips, para):
     grayimg = ips.img if ips.img.ndim == 2 else ips.img.mean(axis=-1)
     grayimg /= grayimg.max()
     pts = blob_doh(grayimg,
                    min_sigma=para['min_sigma'],
                    max_sigma=para['max_sigma'],
                    num_sigma=para['num_sigma'],
                    threshold=para['threshold'],
                    overlap=para['overlap'],
                    log_scale=para['log_scale'])
     ips.mark = mark2shp({'type': 'circles', 'body': pts[:, [1, 0, 2]]})
Ejemplo n.º 40
0
def detect_blobs(data_gray):
    from skimage.feature import blob_dog, blob_log, blob_doh
    from skimage.color import rgb2gray

    # takes grayscale
    blobs = blob_doh(data_gray, min_sigma=10, num_sigma=3, max_sigma=50, threshold=0.1)
    mask = np.zeros(data_gray)
    n, m = mask.shape
    for blob in blobs:
        y, x = np.ogrid[-a : n - a, -b : m - b]
        mask = mask * (x * x + y * y <= r * r)

    return mask
Ejemplo n.º 41
0
def find_blobs(img):
    img = np.copy(img)
    #img[img<0.2*img.max()] = 0
    blobs = blob_doh(img, max_sigma=10)
    true_blobs = []
    for y0, x0, b0 in blobs:
        #print img[y0,x0]
        #print util.neighbour(img, y0, x0, b0)
        #print "---------------------------------"
        #print
        if img[y0,x0] > util.neighbour(img,y0,x0,b0).mean() and b0 >= 2:
            true_blobs.append([y0,x0,b0])
    return true_blobs, blobs, img
Ejemplo n.º 42
0
def test_blob(img, y0, x0, size=40):
    """ Test if blob exist at (y0, x0) in image
    size: inspecting region
    """
    img0 = np.zeros((img.shape[0]+2*size, img.shape[1]+2*size))
    img0[size:size+img.shape[0], size:size+img.shape[1]] = img

    p0 = util.neighbour(img0, y0+size, x0+size, size)
    blobs = blob_doh(p0, max_sigma=10)
    for _y, _x, _b in blobs:
        if _b > 8: continue
        if (_y-size)**2 + (_x-size)**2 <= 4:
            return True
    return False
Ejemplo n.º 43
0
def test_blob_overlap():
    img = np.ones((512, 512), dtype=np.uint8)

    xs, ys = circle(100, 100, 20)
    img[xs, ys] = 255

    xs, ys = circle(120, 100, 30)
    img[xs, ys] = 255

    blobs = blob_doh(
        img,
        min_sigma=1,
        max_sigma=60,
        num_sigma=10,
        threshold=.05)

    assert len(blobs) == 1
Ejemplo n.º 44
0
def blob_feature(image, method='log'):
    if method == 'log':
        blobs = blob_log(image, )
    else:
        blobs = blob_doh(image, )

    blob_image = np.zeros(image.shape)

    #Draw the blobs to an image
    for blob in blobs:
        y,x,sigma = blob
        color = sigma
        size = int(np.sqrt(2*sigma)) if method == 'log' else sigma
        cv2.circle(blob_image, (x, y), size, sigma/1,-1)

    #dataset.show_image(blob_image)
    return blob_image
Ejemplo n.º 45
0
def fun2(fv):
    blobs = [ blob_doh(_f) for _f in fv ]
    blobs = [ item for sublist in blobs for item in sublist ]
    blobs = array(blobs)

    if blobs.size == 0:
        return 0, 0, 0, False, []

    # find maxima
    r0, y0, x0 = hough.find_ring(fv)
    _d = blobs[:,:2] - [y0, x0]
    _d = [ x[0]**2 + x[1]**2 for x in _d ]
    _d = [ i for i in _d if i <= 2 ]
    if len(_d) >= 1:
        check = True
        print y0, x0, r0, 'Yes!'
    else:
        check = False
        print y0, x0, r0, 'No!'
    #fv[r0, y0-1:y0+2, x0-1:x0+2] = 0
    return r0, y0, x0, check, blobs
Ejemplo n.º 46
0
    def detect_blobs(self, min_sigma, max_sigma, num_sigma, threshold):
        blobs = []
        image_gray = rgb2gray(self.original_image)
        r, c = np.shape(image_gray)
        image_gray = image_gray[5:r-5,5:c-5]
        image_gray[1,1] = 1
        if self.method == 'log':
            blobs = blob_log(image_gray, min_sigma=min_sigma,
                             max_sigma=max_sigma, num_sigma=num_sigma, threshold=threshold)
            a = len(blobs[:])
            if a != 0:
                blobs[:, 2] = blobs[:, 2] * sqrt(2)

        elif self.method == 'dog':
            blobs = blobs_dog = blob_dog(image_gray, max_sigma=max_sigma, threshold=threshold)
            a = len(blobs[:])
            if a != 0:
                blobs[:, 2] = blobs[:, 2] * sqrt(2)
        else:
            blobs = blob_doh(image_gray, max_sigma=max_sigma, threshold=threshold)

        return blobs
Ejemplo n.º 47
0
def find_blobs_hessian(img):
    size = 20
    img0 = np.zeros((img.shape[0]+ 2*size, img.shape[1]+ 2*size))
    img0[size:size+img.shape[0], size:size+img.shape[1]] = img

    blobs = blob_doh(img0, max_sigma=10, num_sigma=10)

    true_blobs = []
    for y0, x0, b0 in blobs:
        
        p0 = util.neighbour(img0, y0, x0, 1)
        y, x  = np.unravel_index(p0.argmax(), p0.shape)
        y0 += y - 1
        x0 += x - 1

        p0 = util.neighbour(img0, y0, x0, 2*b0)

        if True:
            # method 1 (hessian diagonal)
            hs0, hs1, hs2 = hessian_matrix(p0, 0.5*b0)
            q0 = 0.5 *(hs0 + hs2)
            if b0 >= 2 \
                and b0 <= 8 \
                and q0[2*b0,2*b0] > 0.95*util.neighbour(q0,2*b0,2*b0,b0).max():
                    true_blobs.append([y0,x0,b0])
        else:
            # method 2 (hessian determinant)
            q0 = hessian_matrix_det(p0, b0)
            print b0, q0[2*b0, 2*b0], util.neighbour(q0, 2*b0,2*b0,b0).max()
            if b0 >= 2 \
                and b0 <= 8 \
                and q0[2*b0,2*b0] > 0.8*util.neighbour(q0,2*b0,2*b0,b0).max():
                    true_blobs.append([y0, x0, b0])
    if len(true_blobs) > 0:
        true_blobs = np.array(true_blobs) - [size, size, 0]
    if len(blobs) > 0:
        blobs = blobs - [size, size, 0]
    return true_blobs, blobs
Ejemplo n.º 48
0
def test_blob_overlap():
    img = np.ones((256, 256), dtype=np.uint8)

    xs, ys = circle(100, 100, 20)
    img[xs, ys] = 255

    xs, ys = circle(120, 100, 30)
    img[xs, ys] = 255

    blobs = blob_doh(
        img,
        min_sigma=1,
        max_sigma=60,
        num_sigma=10,
        threshold=.05)

    assert len(blobs) == 1

    r1, r2 = 7, 6
    pad1, pad2 = 11, 12
    blob1 = ellipsoid(r1, r1, r1)
    blob1 = util.pad(blob1, pad1, mode='constant')
    blob2 = ellipsoid(r2, r2, r2)
    blob2 = util.pad(blob2, [(pad2, pad2), (pad2 - 9, pad2 + 9),
                                           (pad2, pad2)],
                            mode='constant')
    im3 = np.logical_or(blob1, blob2)

    blobs = blob_log(im3,  min_sigma=2, max_sigma=10, overlap=0.1)
    assert len(blobs) == 1

    # Two circles with distance between centers equal to radius
    overlap = _blob_overlap(np.array([0, 0, 10 / math.sqrt(2)]),
                            np.array([0, 10, 10 / math.sqrt(2)]))
    assert_almost_equal(overlap,
                        1./math.pi * (2 * math.acos(1./2) - math.sqrt(3)/2.))
Ejemplo n.º 49
0
def blob_image(image):
    #img_path    =   '../1.3.6.1.4.1.14519.5.2.1.6279.6001.100332161840553388986847034053.mhd'
    # slice = numpy_image[240,:,:]
    # normalized = norm.normalize(return_surrounding([240,240,240],numpy_image, 240))
    # thresholded = threshold_by_histogram(normalized)
    # blobs = label_image(thresholded)
    # show_images([blobs, normalized, thresholded])

    # normalized3d = norm.normalize(numpy_image)
    # thresholded3d = threshold_by_histogram(normalized3d)
    list = []
    image = norm.normalize(image)
    #print "normalized and thresholded"

    for z, slice in tqdm(enumerate(image)):
        blobs = feature.blob_doh(slice)
        #print blobs.shape
        blob_coords = np.zeros((len(blobs),3))
        for i, blob in enumerate(blobs):
            blob_coords[i] = [z, blob[0], blob[1]]
        list.append(blob_coords)

    #print list
    return list
Ejemplo n.º 50
0
from skimage.feature import blob_dog, blob_log, blob_doh
from math import sqrt
from skimage.color import rgb2gray

# image = data.hubble_deep_field()[0:500, 0:500]
image = cv2.resize(img1, (256, 256))
image_gray = rgb2gray(image)

blobs_log = blob_log(image_gray, max_sigma=30, num_sigma=10, threshold=0.1)
# Compute radii in the 3rd column.
blobs_log[:, 2] = blobs_log[:, 2] * sqrt(2)

blobs_dog = blob_dog(image_gray, max_sigma=30, threshold=0.1)
blobs_dog[:, 2] = blobs_dog[:, 2] * sqrt(2)

blobs_doh = blob_doh(image_gray, max_sigma=30, threshold=0.01)

blobs_list = [blobs_log, blobs_dog, blobs_doh]
colors = ["yellow", "lime", "red"]
titles = ["Laplacian of Gaussian", "Difference of Gaussian", "Determinant of Hessian"]
sequence = zip(blobs_list, colors, titles)

for blobs, color, title in sequence:
    fig, ax = plt.subplots(1, 1)
    ax.set_title(title)
    ax.imshow(image, interpolation="nearest")
    for blob in blobs:
        y, x, r = blob
        c = plt.Circle((x, y), r, color=color, linewidth=2, fill=False)
        ax.add_patch(c)
Ejemplo n.º 51
0
test_images = [lensed_image, unlensed_image]

gray_images = [rgb2gray(image) for image in test_images]

blobs_log = [blob_log(image_gray, max_sigma=30, num_sigma=10, threshold=.1) for image_gray in gray_images]

# Compute radii in the 3rd column.
# for bl in blobs_log : 
#     bl[:, 2] = bl[:, 2] * sqrt(2)

# blobs_dog = [blob_dog(image_gray, max_sigma=30, threshold=.1) for image_gray in gray_images]
# for bd in blobs_dog :
#     bd[:, 2] = bd[:, 2] * sqrt(2)

blobs_doh = [blob_doh(image_gray, max_sigma=30, threshold=.01) for image_gray in gray_images]
print('Finished blob detection with Determinant of Hessian')

blobs_list = [#blobs_log, blobs_dog, 
              blobs_doh]
colors = ['yellow', 'lime', 'red']
titles = ['Laplacian of Gaussian', 'Difference of Gaussian',
          'Determinant of Hessian']

sequence = zip(blobs_list, colors, titles)

for i, image in enumerate(['lensed','unlensed']) :
    fig, axes = plt.subplots(1, 3, figsize=(14, 4), sharex=True, sharey=True,
                             subplot_kw={'adjustable': 'box-forced'})
    plt.tight_layout()
Ejemplo n.º 52
0
def create_blobs(url, opt='all'):
    image = imread(url)
    return_dict = dict()
    print 'Image read: {}'.format(url)
    image_gray = rgb2gray(image)

    print 'Greyscale applied'

    if opt=='all':
        blobs_log = blob_log(image_gray, min_sigma=15, max_sigma=50, num_sigma=10, threshold=.1, overlap=0.8) 

        print 'Laplacian of Gaussian computed'
        # Compute radii in the 3rd column.
        blobs_log[:, 2] = blobs_log[:, 2] * sqrt(2)
        return_dict['LoG'] = blobs_log

        blobs_dog = blob_dog(image_gray, max_sigma=30, threshold=.1)
        print 'Difference of Gaussian computed'

        blobs_dog[:, 2] = blobs_dog[:, 2] * sqrt(2)
        return_dict['DoG'] = blobs_dog

        blobs_doh = blob_doh(image_gray, max_sigma=30, threshold=.01)
        print 'Determinant of Hessian computed'

        return_dict['DoH'] = blobs_doh

        blobs_list = [blobs_log, blobs_dog, blobs_doh]
        colors = ['yellow', 'lime', 'red']
        titles = ['LoG', 'DoG',
                  'DoH']
        sequence = zip(blobs_list, colors, titles)
        print 'Sequence created'

    elif opt=='doh':
        print 'DoH only'
        blobs_doh = blob_doh(image_gray, max_sigma=30, threshold=.01)
        return_dict['DoH'] = blobs_doh
        sequence = zip([blobs_doh], ['red'], ['DoH'])

    elif opt=='log':
        print 'LoG only'
        blobs_log = blob_log(image_gray, min_sigma=15, max_sigma=50, num_sigma=10, threshold=.1, overlap=0.8) 

        print 'Laplacian of Gaussian computed'
        # Compute radii in the 3rd column.
        blobs_log[:, 2] = blobs_log[:, 2] * sqrt(2)
        return_dict['LoG'] = blobs_log
        sequence = zip([blobs_log], ['yellow'], ['LoG'])
    print sequence
    
    fig,axes = plt.subplots(1, 3, sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'})
    axes = axes.ravel()

    print 'Matplot initialized'
    print sequence
    for blobs, color, title in sequence:
        ax = axes[0]
        axes = axes[1:]
        ax.set_title(title)
        ax.imshow(image, interpolation='nearest')
        for blob in blobs:
            y, x, r = blob
            c = plt.Circle((x, y), r, color=color, linewidth=2, fill=False)
            ax.add_patch(c)
    plt.show()
    return return_dict
Ejemplo n.º 53
0
                #blobs = blob_doh(image_gray, min_sigma=1, max_sigma=25, num_sigma=15, threshold=.001)
                blobs = blob_dog(image_gray, min_sigma=1, max_sigma=25, sigma_ratio=1.6, threshold=.25, overlap=0.5)
                if(len(blobs) != 0):
                    blobs[:, 2] = blobs[:, 2] * sqrt(2)

                self.all_blobs.append(blobs)
                file_processing = "Processing files: " + str(i+1) + "/" + str(len(self.filenames))
                #print("blobs size: ", len(blobs))
=======
                #image = cv2.imread(glob.glob("cropped_images/" + self.filenames[i]))
                #print("imageName: ", (glob.glob("cropped_images/" + self.filenames[i]))[0])
                image = cv2.imread((glob.glob("cropped_images/*" + self.filenames[i]))[0])
                self.images.append(image)
                image_gray = rgb2gray(image)
                #blobs = blob_doh(image_gray, min_sigma=3, max_sigma=35, num_sigma=30, threshold=.005)
                blobs = blob_doh(image_gray, min_sigma=1, max_sigma=25, num_sigma=15, threshold=.001)
                self.all_blobs.append(blobs)
                file_processing = "Processing files: " + str(i+1) + "/" + str(len(self.filenames))
                print("blobs size: ", len(blobs))
>>>>>>> c1b308ec15ebe3098d38e2f3bd0171bbd669606b
                print(file_processing)



    def sortKey(self, str):
        i = str.find("frame")
        j = str.find(".jpg")
<<<<<<< HEAD
=======
        #print("shortened string: ", str[i+5:j])
>>>>>>> c1b308ec15ebe3098d38e2f3bd0171bbd669606b
Ejemplo n.º 54
0
f1 = copy(f0[0, 100:1100, 50:1050])
f1 = img_as_float(f1)


#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Settings
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bmin = 0.12
bmax = 0.20
rmin = 2
rmax = 65
alpha = 0.5


# detek very bright blob and remove them
blobs = blob_doh(f1, threshold=0.002)
for b in blobs:
    b[2] *= 1.2
    f1[b[0]-b[2]:b[0]+b[2]+1, b[1]-b[2]:b[1]+b[2]+1] = f1.mean()


# downsize
# threholding filter
# sample importance
f2 = rescale(f1, 0.5)
f3 = ifilter.threhold(f2, bmin, bmax)
f4 = ifilter.sample_importance(f3, alpha)


# hough transform
if False:
Ejemplo n.º 55
0


filename = 'C:\\Users\\schan3\\Desktop\\New folder (2)\\'
imgname = 'SBU_2015.01.26_18.21.27_flake_11032_cam_1'


file_processed = 0

for fname in glob.glob(filename + '*.png'):
    count = 0
    print fname
    image = io.imread(fname)
    image_gray = rgb2gray(image)

    blobs_doh = blob_doh(image_gray, max_sigma=1000, min_sigma =40, threshold=.00045, overlap = .25)
    
    blobs_list = [blobs_doh]
    colors = ['red']
    titles = ['Snow flake counts using Determinant of Hessian']
    sequence = zip(blobs_list, colors, titles)
    
    for blobs, color, title in sequence:
        fig, ax = plt.subplots(1, 1)
        ax.set_title(title)
        ax.imshow(image, interpolation='nearest', cmap = cm.Greys_r)
        for blob in blobs:
            y, x, r = blob
            c = plt.Circle((x, y), r, color=color, linewidth=1, fill=False)
    
            ax.add_patch(c)
Ejemplo n.º 56
0
	if flip_v:
		cv2.flip(a,0,a)
	cv2.normalize(a, a, 0, 65535, cv2.NORM_MINMAX)
	np.right_shift(a, 8, a)
	return np.uint8(a)

camera = picamera.PiCamera()

url = "http://52.90.77.195"
# get video from flir or infinite loop
while True:
	cv2.imwrite("wat.jpg", capture())
	image = imread("wat.jpg") # gonna be frame
	image_gray = rgb2gray(image) # convert frame

	blobs_doh = blob_doh(image_gray, min_sigma=20, max_sigma=35, threshold=.01) # detect frame

	if len(blobs_doh):
		file = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10)) + '.jpg'
		camera.capture(file)
		print "request to server here to drone"
		r = requests.get(url + "/intrude")
		if(start < 70):
			start = start + 15
			pwm.ChangeDutyCycle(start)
		else:
			start = 5
			pwm.ChangeDutyCycle(start)
		time.sleep(0.5)
		# potentially move to blob
		y = blobs_doh[0][0]
Ejemplo n.º 57
0
def test_blob_doh():
    img = np.ones((512, 512), dtype=np.uint8)
    img3 = np.ones((5, 5, 5))

    xs, ys = circle(400, 130, 20)
    img[xs, ys] = 255

    xs, ys = circle(460, 50, 30)
    img[xs, ys] = 255

    xs, ys = circle(100, 300, 40)
    img[xs, ys] = 255

    xs, ys = circle(200, 350, 50)
    img[xs, ys] = 255

    blobs = blob_doh(
        img,
        min_sigma=1,
        max_sigma=60,
        num_sigma=10,
        threshold=.05)

    radius = lambda x: x[2]
    s = sorted(blobs, key=radius)
    thresh = 4

    b = s[0]
    assert abs(b[0] - 400) <= thresh
    assert abs(b[1] - 130) <= thresh
    assert abs(radius(b) - 20) <= thresh

    b = s[1]
    assert abs(b[0] - 460) <= thresh
    assert abs(b[1] - 50) <= thresh
    assert abs(radius(b) - 30) <= thresh

    b = s[2]
    assert abs(b[0] - 100) <= thresh
    assert abs(b[1] - 300) <= thresh
    assert abs(radius(b) - 40) <= thresh

    b = s[3]
    assert abs(b[0] - 200) <= thresh
    assert abs(b[1] - 350) <= thresh
    assert abs(radius(b) - 50) <= thresh

    # Testing log scale
    blobs = blob_doh(
        img,
        min_sigma=1,
        max_sigma=60,
        num_sigma=10,
        log_scale=True,
        threshold=.05)

    b = s[0]
    assert abs(b[0] - 400) <= thresh
    assert abs(b[1] - 130) <= thresh
    assert abs(radius(b) - 20) <= thresh

    b = s[1]
    assert abs(b[0] - 460) <= thresh
    assert abs(b[1] - 50) <= thresh
    assert abs(radius(b) - 30) <= thresh

    b = s[2]
    assert abs(b[0] - 100) <= thresh
    assert abs(b[1] - 300) <= thresh
    assert abs(radius(b) - 40) <= thresh

    b = s[3]
    assert abs(b[0] - 200) <= thresh
    assert abs(b[1] - 350) <= thresh
    assert abs(radius(b) - 50) <= thresh

    with pytest.raises(ValueError):
        blob_doh(img3)

    # Testing no peaks
    img_empty = np.zeros((100,100))
    assert blob_doh(img_empty).size == 0
Ejemplo n.º 58
0
plt.imshow(image_gray, cmap='gray')
plt.show()

# blobs_log = feature.blob_log(image_gray, max_sigma=30, num_sigma=10, threshold=.1)
# plt.imshow(blobs_log, cmap='gray')
# plt.show()

blobs_log = feature.blob_log(image_gray, max_sigma=30, num_sigma=10, threshold=.1)

# Compute radii in the 3rd column.
blobs_log[:, 2] = blobs_log[:, 2] * sqrt(2)

blobs_dog = feature.blob_dog(image_gray, max_sigma=30, threshold=.1)
blobs_dog[:, 2] = blobs_dog[:, 2] * sqrt(2)

blobs_doh = feature.blob_doh(image_gray, max_sigma=30, threshold=.01)

blobs_list = [blobs_log, blobs_dog, blobs_doh]
colors = ['yellow', 'lime', 'red']
titles = ['Laplacian of Gaussian', 'Difference of Gaussian', 'Determinant of Hessian']
sequence = zip(blobs_list, colors, titles)

fig, axes = plt.subplots(1, 3, figsize=(14, 4), sharex=True, sharey=True,
                         subplot_kw={'adjustable': 'box-forced'})
plt.tight_layout()

axes = axes.ravel()
for blobs, color, title in sequence:
    ax = axes[0]
    axes = axes[1:]
    ax.set_title(title)