-
Notifications
You must be signed in to change notification settings - Fork 47
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
Expand colour histogram past rgba8 #606
Comments
Since we once did it for Rgba8 it was interesting to try it out to make that more abstract https://gist.github.com/awxkee/6bf5ba717365dcfeb32d82486b0dfc08. I'm not sure if this is the best one, but this is what I got. |
Thank you very much! I will have a look at it, as soon as I can! On the first glance it looks awesome! |
Hey @awxkee, I had a look at it. Really good job, I will try to extend it with some additional things:
Thank you very much for providing me this awesome base implementation :) |
Hi, @B-LechCode Glad to hear it helps!
This one might be tricky, because you're using DynamicImage, Transparent color counting is easy, except distinct transparent colors. For distinct transparent colors count you'll have to add 2^8 size to |
@awxkee, I reduced the code a little bit and added transparent color counting, matching the old implementation. Please look at: 087fb74 Edit: I use float images which aren't normalized often, so that's a thing I'd like to consider here :) |
Yes, I believe complex computing won't be autovectorized properly and will hurt performance. OTH iterating by rows creates 2 very simple loops that will likely be exceptionally fast. |
I think if there is some reason to handle not normalized on [0..1] f32 images there is special case will be needed, because this is 2 completely different cases. |
Ah, I see! That's a good point - I will make it work firstly and then I should have a look at godbolt to optimize the code. Since this is really performance critical here that's what I think we should do. Did you compare that initially?
Ahh, I see. Do you think adding one multiplication and one addition would hurt more than using branching inside the loop? |
I think, yes, but I'm already not truly sure :)
Now, Rust always ensures that value fit to impl ArgumentReducer<f32, u16> for ArgumentReducerFloat32 {
#[inline(always)]
fn reduce(&self, a: f32) -> u16 {
(a * (u16::MAX as f32)) as u16
}
} However for passthrough non normalized value you'll probably need to clamp to |
I do not think this is important here, I believe handling values correct here is more important than 2-5% performance drop. In common, if loop will be vectorized properly, there is no real branching, vector could be just tested againts the values, it should be more or less the same. |
Here is some normalization test, if that makes sense /// find if image has too many values not in the range [0...1]
fn deviation_test(image: &[f32]) -> bool {
let mean = image.iter().sum::<f32>() / image.len() as f32;
let variance = image
.iter()
.map(|&v| {
let dm = v - mean;
dm * dm
})
.sum::<f32>()
/ image.len() as f32;
let stddev_scale = 1. / variance.sqrt();
let z_score_outliers = image.iter().filter(|&&v| ((v - mean) * stddev_scale).abs() > 3.0).count();
let outliers_fraction = z_score_outliers as f32 / image.len() as f32;
// if more than 3% is outliers then image is not normalized
outliers_fraction > 0.03
} And this is not ideal . |
Thank you! Why shouldn't we treat images with at least one single value above 1.0 as not normalized, is there something I miss here? |
Thresholding by 1.0 will work if you don’t expect raw HDR content in your image. |
I understand, but if the values are > 1.0 - why should I clip them to 1.0 in the Histogram instead of plotting the Histogram till max value? |
Yes, this is fine, but at first you have to determine that image is still normalized, even if some values higher than 1.0, that’s my point. |
I'd also like to note that such HDR images may appear, but not necessarily will. I don't know what images users are viewing in the app, so handling case with HDR images may not be worth it at all. |
I'm going to say that handling HDR is a must. Excluding these is not an option in my books if HDR is to be supported (which is pretty high on both mine and woelpers list) as this would lead to a relatively half baked implementation. |
@awxkee I think it wouldn't be a problem to show the histogram between [min max] even though the display algorithms will clip them to [0,1]. In my opinion the histogram should be statistics on raw input data, and 65k bins should be sufficient? |
HDR image usually does not have enough headroom to create a human understandable histogram within the range [min, max].
There is also issue with multiplication because bright HDR regions after multiplication will always be clipped to u16::MAX. My initial implementation handled those cases more easily because it treated all images as normalized and ignored the headroom. I think solution here depends on what level of correctness you want. Clipping HDR histogram to [min, max] is an easy one, however, have some drawbacks. |
I believe that regardless we should still show the absolute values for those who desire it as that's what's actually correct. What about a middle point where it can be changed by the user? Currently the histogram can be zoomed in by dragging a selection area and it will zoom into that area, double left click and it resets the zoom. In this case, we could bind a double right click to normalise the histogram and show a notification to inform the user that it has normalised the histogram for this image, double right click again to restore the original and show another notification informing the user of the reset. |
@Stoppedpuma please give me some days to implement what I thought about. Then let's do another iteration whether you think it's ok or not :) |
@B-LechCode https://github.com/awxkee/gainforge |
@B-LechCode could I ask you to look at #647 since you're currently working on the histogram? This seems to have broke some where along the way and doesn't update from filter changes anymore. If you're busy or don't feel like it, no worries! This can always be handled another time or by someone else. |
No description provided.
The text was updated successfully, but these errors were encountered: