Skip to content

Commit

Permalink
Fix corners (#6)
Browse files Browse the repository at this point in the history
Addresses issue #5.

Slicing image.shape with [0:1] only selects the first dimension. So all four elements of the corners array were always scaled by the first dimension of the image, resulting in a potentially incorrect value for maxRadius depending on the center, which also leads to different image sizes for the polar image. Slicing with [0:2] uses both image dimensions and creates accurate corners values and fixes these issues.

I created a test, TestPolarConversion.test_final_radius(), that fails with the old slicing and succeeds with the new. With this particular image, the center used in test_default ([401, 365]) leads to the same value independent of slicing, so I used an arbitrary center of [350, 365] instead.

I noticed all of the tests were failing because the "horizontalLines.png" and "checkerboard.png" images are not included in the repository, so I commented those out.

Also, the indentation of the main function call in "test_polarTransform.py" was indented under theTestPointConversion class, so I don't think all of the tests were running. I changed that as well.
  • Loading branch information
scott-trinkle authored and addisonElliott committed Aug 29, 2018
1 parent 87459ca commit 0216611
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion polarTransform.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ def convertToPolarImage(image, center=None, initialRadius=None, finalRadius=None
# Get four corners (indices) of the cartesian image
# Convert the corners to polar and get the largest radius
# This will be the maximum radius to represent the entire image in polar
corners = np.array([[0, 0], [0, 1], [1, 0], [1, 1]]) * image.shape[0:1]
corners = np.array([[0, 0], [0, 1], [1, 0], [1, 1]]) * image.shape[0:2]
radii, _ = getPolarPoints2(corners[:, 1], corners[:, 0], center)
maxRadius = np.ceil(radii.max()).astype(int)

Expand Down
34 changes: 24 additions & 10 deletions tests/test_polarTransform.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class TestPolarConversion(unittest.TestCase):
def setUp(self):
self.shortAxisApexImage = loadImage('shortAxisApex.png')
self.verticalLinesImage = loadImage('verticalLines.png')
self.horizontalLinesImage = loadImage('horizontalLines.png')
self.checkerboardImage = loadImage('checkerboard.png')
# self.horizontalLinesImage = loadImage('horizontalLines.png')
# self.checkerboardImage = loadImage('checkerboard.png')

self.shortAxisApexPolarImage = loadImage('shortAxisApexPolarImage.png')
self.shortAxisApexPolarImage_centerMiddle = loadImage('shortAxisApexPolarImage_centerMiddle.png')
Expand All @@ -36,6 +36,19 @@ def test_default(self):

np.testing.assert_almost_equal(polarImage, self.shortAxisApexPolarImage)

def test_final_radius(self):
polarImage, ptSettings = polarTransform.convertToPolarImage(self.shortAxisApexImage,
center=np.array([350, 365]))

np.testing.assert_array_equal(ptSettings.center, np.array([350, 365]))
self.assertEqual(ptSettings.initialRadius, 0)
self.assertEqual(ptSettings.finalRadius, 580)
self.assertEqual(ptSettings.initialAngle, 0.0)
self.assertEqual(ptSettings.finalAngle, 2 * np.pi)
self.assertEqual(ptSettings.cartesianImageSize,
self.shortAxisApexImage.shape)
self.assertEqual(ptSettings.polarImageSize, (898, 1600))

def test_defaultCenter(self):
polarImage, ptSettings = polarTransform.convertToPolarImage(self.shortAxisApexImage)

Expand Down Expand Up @@ -145,8 +158,8 @@ class TestCartesianConversion(unittest.TestCase):
def setUp(self):
self.shortAxisApexImage = loadImage('shortAxisApex.png')
self.verticalLinesImage = loadImage('verticalLines.png')
self.horizontalLinesImage = loadImage('horizontalLines.png')
self.checkerboardImage = loadImage('checkerboard.png')
# self.horizontalLinesImage = loadImage('horizontalLines.png')
# self.checkerboardImage = loadImage('checkerboard.png')

self.shortAxisApexPolarImage = loadImage('shortAxisApexPolarImage.png')
self.shortAxisApexPolarImage_centerMiddle = loadImage('shortAxisApexPolarImage_centerMiddle.png')
Expand Down Expand Up @@ -341,8 +354,8 @@ class TestPolarAndCartesianConversion(unittest.TestCase):
def setUp(self):
self.shortAxisApexImage = loadImage('shortAxisApex.png')
self.verticalLinesImage = loadImage('verticalLines.png')
self.horizontalLinesImage = loadImage('horizontalLines.png')
self.checkerboardImage = loadImage('checkerboard.png')
# self.horizontalLinesImage = loadImage('horizontalLines.png')
# self.checkerboardImage = loadImage('checkerboard.png')

self.shortAxisApexPolarImage = loadImage('shortAxisApexPolarImage.png')
self.shortAxisApexPolarImage_centerMiddle = loadImage('shortAxisApexPolarImage_centerMiddle.png')
Expand Down Expand Up @@ -427,8 +440,8 @@ class TestPointConversion(unittest.TestCase):
def setUp(self):
self.shortAxisApexImage = loadImage('shortAxisApex.png')
self.verticalLinesImage = loadImage('verticalLines.png')
self.horizontalLinesImage = loadImage('horizontalLines.png')
self.checkerboardImage = loadImage('checkerboard.png')
# self.horizontalLinesImage = loadImage('horizontalLines.png')
# self.checkerboardImage = loadImage('checkerboard.png')

self.shortAxisApexPolarImage = loadImage('shortAxisApexPolarImage.png')
self.shortAxisApexPolarImage_centerMiddle = loadImage('shortAxisApexPolarImage_centerMiddle.png')
Expand Down Expand Up @@ -491,5 +504,6 @@ def test_cartesianConversion(self):
np.array([[50 * 802 / 543, 0], [35 * 802 / 543, 400], [53 * 802 / 543, 800],
[60 * 802 / 543, 1200]])), np.array([[451, 365], [401, 400], [348, 365], [401, 305]]))

if __name__ == '__main__':
unittest.main()

if __name__ == '__main__':
unittest.main()

0 comments on commit 0216611

Please sign in to comment.