mtex-toolbox / mtex

MTEX is a free Matlab toolbox for quantitative texture analysis. Homepage:
http://mtex-toolbox.github.io/
GNU General Public License v2.0
278 stars 183 forks source link

Speed up calcGrains by removing setSubset #1808

Closed nyyssont closed 1 year ago

nyyssont commented 1 year ago

calcGrains is quite slow for maps with large amounts (over 100 000) grains due to calling setSubset so many times. The patch stores the quaternion values and replaces all the meanRotation values after the loop is concluded. This speeds up calcGrains significantly for large datasets.

ralfHielscher commented 1 year ago

Hi Tuomo,

thank you for pointing this out. I was not aware, that the computation of the mean orientations is indeed a big factor in the grain computation. I always thought the Voronoi decomposition is the most time consuming part. This seems to depend on the microstructure.

Now, that I understood it is important and cleared the TODO and implemented the accumarray approach to the grain mean orientation computation. It should be significantly faster. Interestingly, it provides also "better" mean orientations, in the sense that the GOS is not smaller.

All the best, Ralf.

kilir commented 1 year ago

Hi, I think speeding up calcgrains is a great thing. I just did some test and do not see any real difference, so probably it depends highly on the situation.

% ebsd dataset 232783 (5.2%) notIndexed
4214773 (95%) Quartz

% "original" calcGrains" grains: 158393 time: 552.0249 s

% "Tuomos calcGrains" grains: 158393 time: 555.7652 s

% "accumarray version" grains: 158393 time: 501.8330 s

Profiling the calcGrains, 96% of the execution time goes to spatialDecompostion / voronoiDiagram.

Cheers, Rüdiger

Cheers, Rüdiger

nyyssont commented 1 year ago

Ralf's changes are very fast! Thank you for this new calcGrains with significantly improved performance for my (martensite) datasets.

ralfHielscher commented 1 year ago

Tuomo,

can you tell me what time goes in your data sets for (1) spatialDecomposition (2) calcPolygons (3) the rest

Ralf.

nyyssont commented 1 year ago

Starting data:

ebsd = EBSD

 Phase   Orientations     Mineral         Color  Symmetry  Crystal reference frame
     0   569204 (23%)  notIndexed                                                 
     1  1960336 (77%)      Fe-BCC  LightSkyBlue      m-3m                         
     2   9 (0.00036%)      Fe-FCC  DarkSeaGreen      m-3m                         

 Properties: bands, bc, bs, error, mad, x, y, grainId
 Scan unit : um

Command:

[grains,ebsd.grainId] = calcGrains(ebsd('indexed'),'angle',3*degree,'qhull')

Accumarray implementation: (1) 24.1 s (2) 4 s (3) 9 s Output 116653 grains

MTEX 5.8.2 (1) 25.5 s (2) 5.4 s (3) 79 s Output 116653 grains

The accumarray implementation is approximately three times as fast for this type of data.