Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Add cuboid_phantom #1446

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

adler-j
Copy link
Member

@adler-j adler-j commented Nov 17, 2018

No description provided.

@adler-j
Copy link
Member Author

adler-j commented Feb 6, 2019

Could this get a review please?

@kohr-h
Copy link
Member

kohr-h commented Feb 6, 2019

I'll have a look

Copy link
Member

@kohr-h kohr-h left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of things, please check.

Code reuse is quite low in the module. For instance, the cuboid_phantom function seems to have about 95 % overlap with ellipsoid_phantom (not counting the docstring). And major parts of _cuboid_phantom_2d are copy-pasted from the ellipse case as well.
If you see a possibility, try to factor out the parts that allow it. Otherwise, please add a TODO comment.

else:
# Calculate the points that could possibly be inside the volume
max_radius = np.sqrt([a_squared, b_squared])
idx, shapes = _getshapes_2d(center, max_radius, space.shape)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you have to do this for non-rotated rectangles? Can't you just get the min and max per axis and use those directly as bounding boxes? In other words, can't you directly construct slice objects from the min and max and use those for indexing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OTOH, I can see why you want to use the same kind of logic. Maybe it's okay.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll just leave this as is since the other optimization is relatively minor for most cases. This would only give a notable improvement in the case of slightly rotated and very elongated rectangles, which I'll just leave for now.

# Parentheses to get best order for broadcasting
max_distance = np.maximum(squared_dist[0], squared_dist[1])

# Find the points within the ellipse
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rectangle?

# Find the points within the ellipse
inside = max_distance <= 1

# Add the ellipse intensity to those points
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto


The provided cuboids need to be specified relative to the
reference rectangle ``[-1, -1] x [1, 1]``.
The angles are to be given in radians.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about 3D?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3D is not currently supported, I'll update the rest to reflect this

The phantom is created by adding the values of each cuboid. The
cuboid are defined by a center point
``(center_x, center_y, [center_z])``, the lengths of its principial
axes ``(axis_1, axis_2, [axis_2])``, and a rotation angle ``rotation``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

axis_3

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But since 3D isn't supported, remove 3rd axis stuff.

[ 0., 1., 2., 1., 0.],
[ 1., 2., 2., 2., 1.],
[ 0., 1., 2., 1., 0.],
[ 0., 0., 1., 0., 0.]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something is not right with this example. It doesn't look like a cuboid to me.

Space in which the phantom should be created, must be 2- or
3-dimensional. If ``space.shape`` is 1 in an axis, a corresponding
slice of the phantom is created (instead of squashing the whole
phantom into the slice).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3D is not supported, so this needs an update

space, min_pt=snapped_min_pt, max_pt=snapped_max_pt,
cell_sides=space.cell_sides)

tmp_phantom = _phantom(tmp_space, ellipsoids)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch has obviously never been run, since it cannot work.

@pep8speaks
Copy link

Checking updated PR...

Line 297:9: E123 closing bracket does not match indentation of opening bracket's line

Copy link
Member

@kohr-h kohr-h left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor thing to fix, after that I guess we can merge.

space = odl.uniform_discr([-1, -1], [1, 1], [300, 300])
ellipses = [[1.0, 0.6, 0.6, 0.0, 0.0, 1.5],
[1.0, 0.1, 0.3, 0.0, 0.0, 0.3]]
cuboid_phantom(space, ellipses).show('cuboid phantom 2d')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use cuboids or cubes instead of ellipses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants