mantidproject / mantidimaging

Graphical toolkit for neutron imaging.
https://mantidproject.github.io/mantidimaging
GNU General Public License v3.0
12 stars 6 forks source link

ROI speed up #2076

Open samtygier-stfc opened 6 months ago

samtygier-stfc commented 6 months ago

Moving the ROIs in spectrum viewer can be slow with big datasets, because a mean is being calculate over a large amount of data. Investigate if something clever can be done to speed it up.

This is likely to be memory bound so probably can't be improved much with threading or vectorisation.

Some related work has already been done #1708 and in #1828

Potential Solutions / Ideas (solution may be a mix of these):

Partial recalculation Through Caching

If we have calculated the mean for and ROI (0,0,100,100) and it gets resized to (0,0,100,90) then maybe we can use the previous result and only calculate the difference (0,90,100,100). Needs some design thought to avoid complexity, avoid accumulating error, and clear cached values when the image stack is modified.

Delayed Recalculation of Spectrum ROI Post-Move

Only recalculate when use ROI move is complete, rather than updating in realtime. Or do realtime updates in a way that does not effect interactivity.

We would probably need to alter the transparency of the spectrum plot during the recalculation to indicate something is happening to the user where the spectrum may not yet be up to date with the ROI. We could also begin redrawing the spectrum line as it is being calculated displaying the newly drawn sections without any transparency applied to distinguish between updated sections and out of date section of the line plot.

Update spectrum plot in segments, so user can see that something is happening.

https://github.com/mantidproject/mantidimaging/assets/32413847/00e3869c-178e-4a41-aba6-5bc4a887986c

JackEAllen commented 6 months ago

my preference for the order in which this should be tackled would be implementing the delayed recalculation, then exploring partial recalculation through caching to get something into main quickly. Caching could potentially be quite a large change to the existing codebase compared to delaying the recalculation.

samtygier-stfc commented 6 months ago

https://pyqtgraph.readthedocs.io/en/latest/api_reference/graphicsItems/roi.html One thing to look at would be the difference between sigRegionChanged and sigRegionChangeFinished. Might be a quick improvement by switching.