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

Support units #103

Merged
merged 10 commits into from
Jun 27, 2021
Merged

Support units #103

merged 10 commits into from
Jun 27, 2021

Conversation

JeffFessler
Copy link
Owner

The goal here is to relax Real to Number for quantities like image pixel sizes and circle radii to support Unitful.

@JeffFessler JeffFessler marked this pull request as draft June 24, 2021 12:01
@codecov
Copy link

codecov bot commented Jun 24, 2021

Codecov Report

Merging #103 (fa7b8e9) into master (0c60351) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #103   +/-   ##
=======================================
  Coverage   99.81%   99.81%           
=======================================
  Files          44       44           
  Lines        2172     2181    +9     
=======================================
+ Hits         2168     2177    +9     
  Misses          4        4           
Impacted Files Coverage Δ
src/fbp/ellipse_im.jl 100.00% <100.00%> (ø)
src/fbp/ellipsoid_im.jl 100.00% <100.00%> (ø)
src/fbp/image_geom.jl 100.00% <100.00%> (ø)
src/fbp/rect_im.jl 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0c60351...fa7b8e9. Read the comment docs.

throw(DimensionMismatch("mask size $(size(mask)) vs dims $dims"))
new{D}(dims, Float32.(deltas), Float32.(offsets), mask)
end
struct ImageGeom{D, S <: NTuple{D,Number}}
Copy link
Owner Author

Choose a reason for hiding this comment

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

@johnnychen94 If you have a chance to skim these changes I would be interested in your feedback.
The deltas here are pixel sizes and originally I made them all Float32 but recently I've been interested in trying to use physical units more via Unitful, so I've relaxed the type to Number. (Unfortunately that also allows complex numbers but so it goes.) I know I could use a Union of Real and Unitful.Quantity but I'd rather not add Unitful as a dependency because maybe there are/will be other units packages and I prefer to keep it general.
BTW, for a video the we might have units of (m, m, s) for 2D+time so I want to allow deltas to be a general Tuple of numbers.
Anyway, one specific question for you is whether you think that including the type S of the Tuple as part of this struct parameter is useful or not. I definitely can dispatch on the dimension D but I'm not sure that I will dispatch on the type of the deltas Tuple. Any thoughts on this or anything else here?
I plan on making more such changes elsewhere in the package to support units so now is the best time to prod me in a good direction :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like ImageGeom still uses the old object-oriented design, is it possible to instead embrace the array interface here?

I don't know the usage of mask here, but it seems that the other fields dims, deltas, offsets can be replaced by OffsetArrays.

For unitful arrays, perhaps AxisArrays.jl is a handful concept (although I never tried it)

Copy link
Owner Author

Choose a reason for hiding this comment

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

Thanks for the comments. The offsets here are non-integer so OffsetArrays is inapplicable. But AxisArrays looks useful!
I realize now that I need to add documentation to explain what this type does. So I might get back to you with another question after I do that. (This is not an array type; it is a description of the pixel geometry for image reconstruction.) More later - thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

it is a description of the pixel geometry for image reconstruction

This isn't a very distinctive definition to me. I see array properties like ndim, zeros, ones, but that could be replaced by ndims(im), zeros(size(im)), ones(size(im)). How much of it will be left if we 1) separate it into a lazy array 2) remove unnecessary wrapper (e.g., im.plot, im.shape)?

Maybe we can start by deprecating the old usage in favor of the functional julian way? That could possibly reduce some complexities and simplify the code design.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I have a lot of legacy code that uses this "matlab" struct style and properties so it will be a while before I am ready to start deprecating. But I have added documentation about ImageGeom in the latest push so hopefully that will deploy and clarify. I still have a lot of other code that I want to upgrade to support units and that will be a higher priority for a while. But thanks for steering me towards the Julia way :)

Copy link
Owner Author

Choose a reason for hiding this comment

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

@johnnychen94 fyi i took your comments to heart and created a new "functional" version here:
https://github.com/JuliaImageRecon/ImageGeoms.jl
See the docs (via Literate) for an explanation.
Eventually I will deprecate a lot here.

@JeffFessler JeffFessler marked this pull request as ready for review June 27, 2021 12:07
@JeffFessler JeffFessler merged commit b66be11 into master Jun 27, 2021
@JeffFessler
Copy link
Owner Author

I am merging in hopes that it will trigger the docs deploy, but not tagging yet because more changes planned.

@JeffFessler JeffFessler deleted the unit branch June 27, 2021 13:31
@JeffFessler JeffFessler restored the unit branch June 27, 2021 13:32
@JeffFessler JeffFessler deleted the unit branch July 15, 2021 02:18
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.

2 participants