-
Notifications
You must be signed in to change notification settings - Fork 616
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
Add ImageVisual gamma and smarter in-shader contrast limits #1844
Add ImageVisual gamma and smarter in-shader contrast limits #1844
Conversation
Nice. You'll have to add docstrings for gamma and stuff. Does it make sense to do gamma on an RGB image at all? |
oh right, will do.
I see no reason why not! :) i just see it as 3 regular monochromatic channels. that said, I can't immediately think of an application. In any case it would be trivial to allow the gamma setter to accept either a float or a 3-tuple, and I don't think it would get in anyone's way. |
@tlambert03 and @djhoese Can this be realized via filters? At least gamma looks like it can be done with filters. |
not sure I follow. what do you mean by filters in this case? accessing a particular sample from a texture? If so, I can't see my way through that one... if not, let me know what i'm missing. |
@tlambert03 Sorry for being short with explanation. Filters can be used to hook shader/code into existing visuals. There are some filters already implemented (see here). The good thing is, that all additional code goes into the filter. This prevents from crowding the Visual with additional kwargs/code, which are only needed for specific cases. The filter can be attached to and removed from the visual. So here there might be a gamma-filter which can be attached to an ImageVisual. |
ah! ok thanks, will read up. |
@tlambert03 This is an example with the Isoline-Filter in action (https://github.com/vispy/vispy/blob/master/examples/basics/scene/contour.py). I might be wrong, but the gamma-stuff looks like it can implemented likewise. |
The color transform happens after the gamma though, isn't that a problem? |
I just finished working my way through filters and hooks and stuff (very cool, glad to know about it), and had the same question. Yeah, we need to apply the gamma prior to the @kmuehlbauer, any tricks on using a filter when you actually need to hook somewhere the middle of the shader? Could the shader itself be rewritten in a way that made it "hookable" prior to |
@tlambert03 I'll have a closer look the next day. IIRC you can specify some position in the shaders, but I have to check first. I'll report back. |
I think you're talking about pre/post which are kind of talked about here: vispy/vispy/visuals/filters/base_filter.py Lines 40 to 43 in cf244a2
So |
@djhoese correct, this is what I'd like to figure out. |
added gamma to docstring. Will wait to hear from @kmuehlbauer as to whether this can be done with filters... but otherwise, I think this is ready to go (from my perspective) |
@tlambert03 Sorry, I did not manage to look at it yet. Please let it sit for another two days, before I finally surrender. This is a very nice addition and should not be hold off too long. |
@tlambert03 I'm currently testing against your branch. But I get the same error as in Travis: using the example in
|
Problem is if |
Ah yep, sorry I missed that before you sat down to take a look. Will fix later today
… On Mar 22, 2020, at 6:04 AM, Kai Mühlbauer ***@***.***> wrote:
Problem is if clim='auto'. Then this string gets propagated to self._texture_limits and this is expanded to range_min, range_max = self._texture_limits in clim_normalized.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
ok, fixed... but let me know if you approve of my approach: |
Does it make sense to scale RGBs ever? I saw this napari issue (napari/napari#130) so I'm curious what @sofroniewn has to say too. Ugh as I'm typing this I realize I have an application that does exactly this but with float textures. For meteorological satellite imagery it is common to combine three (or more) image arrays in to a single RGB/A image and tweak the limits that go in to the RGB. If this wasn't a science visualization library I'd say we shouldn't, but I think we have to. |
@djhoese @tlambert Currently digging into the Anyway from looking at the code we could work the |
Yeah, I think this is exactly the point. I agree that scaling an RGB image (which is already usually pre-scaled) is unusual... but I don't think it's "nonsensical" per se. It's all about visualization afterall, and it's conceivable that someone might want to better visualize shadows/highlights in an RGB image. Here's an example of how napari could work if this PR merged: |
ok, I changed it to put the logic in the I'm not sure I feel that strongly one way or the other.
Let me know what you think |
@tlambert03 I'll have a look tomorrow morning (cet) and report back. Any other comments from @djhoese or others are much appreciated. |
I'm not sure it is any cleaner, but I guess it is more reusable. Could you add some tests for all of this? |
hmm, I might need some guidance here. wasn't sure how you tested shaders, so I took a look at since contrast adjustment will cause clipping on the offscreen buffer, seems like the only way to actually test the shader here is to either add new images for both gamma and clim adjustment to the |
Side note: After a bit of thinking I have to admit that it is more natural to have these changes within the I've had not the time to do a thorough review. The version where the logic is in the Regarding the tests, we would need to add new images AFAICS. In this PR was a short discussion on image comparison and further I mentioned some pitfalls I hit when adding the image to the test-repo. Also @djhoese and @larsoner might help out, if necessary. @tlambert03 Thanks for doing this, this is a great addition to |
@tlambert03 After skimming the referenced PR you might also just compare buffers as @djhoese suggested over there if they are small enough. |
I added some tests. I struggled a bit with rounding error, particularly with gamma... still not quite clear to me why. anyway, I asserted that the post-rendered 8-bit values in the canvas buffer are within 1 of the expected value ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tlambert03 This is looking good to me.
Just one suggestion to change. The second thing is, how to handle the string quotes. There have been some changes in string quoting introduced. I'm not sure vispy has some guidelines, but looking at the code we are using kind of "single quotes for data, double quotes for human-readable strings". We should at least be consistent throughout the code. Thoughts @djhoese?
I've never actually heard of that single/double quote for data/human-readable concept. I'm ok trying to have something like this but would like it defined in a contributor's guide in the docs. And/or we switch to some flake8/black/pep8 auto-checker and fixer. |
I'm OK with any solution. But my main concern is that it should be consistent. |
sure, will change. I use black (which sets these all as double quotes) for almost all my other projects, so I have many times had to undo a muscle-memorized "format document" when working on these files :) |
ok, made the requested changes. Once this is all set to go and approved, I'd love if we could also work |
@djhoese Sorry for my ignorance, but I'm not (yet) adapted to azure. Any idea why the linux build fails? |
It was some weird error about a missing |
Still failing, but found the issue: pypa/manylinux#512 An update to the manylinux docker images is causing it. Not your fault. |
The manylinux image issue was fixed. I restarted the Azure jobs and now they pass. I took today off and am taking Monday off too. Unless I decide to work on VisPy stuff on those days I probably won't look at this and the other PR until later next week. The last time I looked at this code I thought it was good to go. I'll re-review when I come back to this, but I think we can consider this one done. Thanks again @tlambert03! |
This is a companion to #1842. It puts (re)calculation of contrast limits (and adds gamma) to the
ImageVisual
shader. Ifclims
are changed after theImageVisual
has been created, then the texture will only be rebuilt (_need_texture_upload == True
) if the newclims
are outside of the bounds of the previous clims. (note: unlikeVolumeVisual
in #1842,ImageVisual
holds a copy of the data, so rescaling is easier).possible embellishments include: allowing gamma and/or contrast limits to be set per channel (for an rgb image).