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

Behavior of limits #101

Closed
lucasb-eyer opened this issue Jun 7, 2014 · 4 comments
Closed

Behavior of limits #101

lucasb-eyer opened this issue Jun 7, 2014 · 4 comments

Comments

@lucasb-eyer
Copy link
Collaborator

Continuing the discussion at #100 because it got off-topic.

limits still leaves a bitter taste, because of behavior like the following:

julia> img = convert(Image, Uint8[1 240; 10 128])
Gray Image with:
  data: 2x2 Array{Uint8,2}
  properties:
    timedim: 0
    colorspace: Gray
    colordim: 0
    spatialorder:  y x
    pixelspacing:  1.0 1.0
    limits: (0x00,0xff)

julia> img * 2
Gray Image with:
  data: 2x2 Array{Uint8,2}
  properties:
    timedim: 0
    colorspace: Gray
    colordim: 0
    spatialorder:  y x
    pixelspacing:  1.0 1.0
    limits: (0,510)

julia> data(img * 2)
2x2 Array{Uint8,2}:
 0x02  0xe0
 0x14  0x00

I'm not sure on how to best handle this, esp. in the case of Uint16 images filling only 12 bits for example.

@timholy
Copy link
Member

timholy commented Jun 7, 2014

Yikes, I didn't know about that. In my personal view, the problem is not limits per se, the problem is the inconsistency in the element type between how limits is treated and Julia's rules for array arithmetic.

See if you like the solution in #102. What else?

timholy added a commit that referenced this issue Jun 7, 2014
@lucasb-eyer
Copy link
Collaborator Author

Sweet implementation :)

I cannot really put my finger on what exactly it is that leaves a bitter taste. I keep wondering whether it's sensible/worth the effort to follow OpenCV and use saturation-arithmetics instead of overflow-arithmetics. And if so, whether it should clamp at the typemin/typemax or at the limit. I'm thinking of a 12bit image stored in an Image{Uint16} for example, should img*2 clamp to 4096 or raise the limit to 8092, but arbitrarily stop raising the limit when it reaches 65536?

@timholy
Copy link
Member

timholy commented Jun 7, 2014

I haven't implemented this yet, but here's a mock-up that shows another way of thinking about this (carefully note the element types, and if you've used SIUnits the basic concepts should be familiar):

julia> img = imread("img.nrrd")
Gray Image with:
  data: 512x512 Array{Count{Uint16},2}
  properties:
    colorspace: Gray
    spatialorder:  x y
    limits: (0x0000 Count,0x0fff Count)
    gain: 3.8 Photons/Count

julia> imgp = img["gain"] * img
Gray Image with:
  data: 512x512 Array{Photons{Float64},2}
  properties:
    colorspace: Gray
    spatialorder:  x y
    limits: (0.0 Photons,15561.0 Photons)
    gain: 3.8 Photons/Count

Once you attach physical units to the intensities, it seems clearer to me that the limits should scale along with the values.

@lucasb-eyer
Copy link
Collaborator Author

The taste is gone, thanks.

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

No branches or pull requests

2 participants