matbryan52 / image-viewer

MIT License
3 stars 1 forks source link

"Clip outliers" support #5

Closed sk1p closed 1 year ago

sk1p commented 1 year ago

With some data, it's common to have outliers that will make the automatic histogram stretching almost useless. An option to clip these outliers would be very useful. Maybe this code can be adapted/stolen for this (as I'm the author, I hereby re-license this code as MIT, FWIW):

https://github.com/LiberTEM/LiberTEM-holo/blob/47ddc00aa0fd7deda74d65e4c940bebee396e6ae/src/libertem_holo/base/filters.py#L14-L31

(I'm not sure, maybe this also belongs in the LiberTEM-panel-ui project, just let me know or move it over as you like)

matbryan52 commented 1 year ago

I agree that some form of auto-set for outliers would be good, perhaps tied to a button. I will integrate the holo code upstream.

I assume you've seen the colormap controls in the image toolbox ?

image

The layout of this floatpanel needs some work but it does at least let you adjust the range manually. There will be a way to make outlier clipping the default state, deactivatable by the user, and applicable on command with a button press.

matbryan52 commented 1 year ago

I have an 'Auto-range' button in a branch which works for on-demand outlier correction:

image

Making this automatic is more delicate as computing the mean / std of a big array is fairly costly, and if the image is being updated frequently then this could actually slow down the display. I'm already computing the min/max internally, accounting for NaN data in a 'reasonable' way, and I'd have to do the same for the mean/std. In the case of a static or manually changing image it's perfectly feasible of course, I just need to figure out where to provide some sort of config / toggle to enable it (on the backend).

sk1p commented 1 year ago

I assume you've seen the colormap controls in the image toolbox ?

Yup. It was a bit fiddly to use, as in the specific case, the outliers were way outside of the normal range, so vmin/vmax were very close on the slider, and you have to remember to "freeze color limits" afterwards, as you lose your settings otherwise when navigating/zooming around.

I have an 'Auto-range' button in a branch which works for on-demand outlier correction:

Great!

Making this automatic is more delicate as computing the mean / std of a big array is fairly costly, and if the image is being updated frequently then this could actually slow down the display. I'm already computing the min/max internally, accounting for NaN data in a 'reasonable' way, and I'd have to do the same for the mean/std. In the case of a static or manually changing image it's perfectly feasible of course, I just need to figure out where to provide some sort of config / toggle to enable it (on the backend).

Yeah, I'm already happy with the manual button approach, everything else is more in the nice-to-have category I think.

matbryan52 commented 1 year ago

you have to remember to "freeze color limits" afterwards, as you lose your settings otherwise when navigating/zooming around.

This is definitely undesirable, I will make sure that navigation doesn't change the colour scale, only image updates.

While I'm at it I'll add the colorbar in image-viewer.

matbryan52 commented 1 year ago

It was a bit fiddly to use, as in the specific case, the outliers were way outside of the normal range, so vmin/vmax were very close on the slider

I noticed this too, in the autorange implementation it actually modifies the slider min/max as well as the currently applied range so it's a bit nicer to use!

matbryan52 commented 1 year ago

Closed through upstream PR