Skip to content

Commit

Permalink
Merge c651a48 into c52fdc7
Browse files Browse the repository at this point in the history
  • Loading branch information
elaubsch committed Jun 2, 2022
2 parents c52fdc7 + c651a48 commit c6f2013
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
8 changes: 2 additions & 6 deletions deepcell_spots/image_alignment.py
Expand Up @@ -150,21 +150,17 @@ def align_images(image_dict, reference_dict):

keypoints1, descriptors1 = orb.detectAndCompute(im1, None)

# Match features.
# Match features
matcher = cv2.DescriptorMatcher_create(cv2.DESCRIPTOR_MATCHER_BRUTEFORCE_HAMMING)
matches = matcher.match(descriptors1, descriptors2, None)

# Sort matches by score
matches.sort(key=lambda x: x.distance, reverse=False)
matches = sorted(matches, key=lambda x: x.distance, reverse=False)

# Remove not so good matches
numGoodMatches = int(len(matches) * GOOD_MATCH_PERCENT)
matches = matches[:numGoodMatches]

# Draw top matches
imMatches = cv2.drawMatches(reference_im, keypoints2, im1, keypoints1, matches, None)
cv2.imwrite("matches.jpg", imMatches)

# Extract location of good matches
points1 = np.zeros((len(matches), 2), dtype=np.float32)
points2 = np.zeros((len(matches), 2), dtype=np.float32)
Expand Down
36 changes: 24 additions & 12 deletions deepcell_spots/image_alignment_test.py
Expand Up @@ -29,21 +29,33 @@
import numpy as np
from tensorflow.python.platform import test

from deepcell_spots.image_alignment import crop_images
from deepcell_spots.image_alignment import crop_images, align_images


def pad_with(vector, pad_width, iaxis, kwargs):
pad_value = kwargs.get('padder', 0)
vector[:pad_width[0]] = pad_value
vector[-pad_width[1]:] = pad_value


class TestImageAlignment(test.TestCase):
# def test_align_images(self):
# im = np.random.random((1, 10, 10, 1)) > 0.9
# im = im*65535
# im_dict = {}
# ref_dict = {}
# for i in range(10):
# im_dict[i] = im
# ref_dict[i] = im
# aligned_dict = align_images(im_dict, ref_dict)

# self.assertEqual(np.shape(im_dict.values()), np.shape(aligned_dict.values()))
def test_align_images(self):
im_size = 100
shift = 5

im_dict = {}
ref_dict = {}
for i in range(10):
im = np.random.random((1, im_size, im_size, 1)) * 65535
shift_im = np.expand_dims(np.pad(im[0, ..., 0],
shift,
pad_with)[:im_size, :im_size], axis=[0, -1])

im_dict[i] = im
ref_dict[i] = shift_im
aligned_dict = align_images(im_dict, ref_dict)

self.assertEqual(np.shape(im_dict.values()), np.shape(aligned_dict.values()))

def test_crop_images(self):
# With padding
Expand Down

0 comments on commit c6f2013

Please sign in to comment.