mtex icon indicating copy to clipboard operation
mtex copied to clipboard

Median grain orientation and the mean grain orientation using the "cluster" function

Open AzdiarGazder opened this issue 6 years ago • 2 comments

Dear All,

I am computing the average orientation of a grain using 2 different methods - both of which use a loop (given below). When this code is applied to an EBSD map containing thousands of grains, the computation time is rather large for both methods and the second method throws an error.

With this in mind, I was wondering if there was a way to : (1) compute median and cluster-based mean orientations of grains as functions (i.e. - without using loops). (2) make the "cluster" function work consistently without error.

The first method 1 computes the median orientation of a grain. It works without error but takes a long time to execute. The code is as follows:

for ii = 1:length(grains)
    % Method 1 (The median grain orientation)
    o_phi1 = median(ebsd(grains(ii)).orientations.phi1);
    o_Phi = median(ebsd(grains(ii)).orientations.Phi);
    o_phi2 = median(ebsd(grains(ii)).orientations.phi2);
    ori(ii) = orientation('Euler',o_phi1, o_Phi, o_phi2, cs,ss);
end

The second method 2 uses the cluster command to compute the mean orientation of a grain. Although it is in a loop, it is faster to execute but throws errors. The code is as follows:

for ii = 1:length(grains)
    [c,o] = cluster(ebsd(grains(ii)).orientations,'numCluster',1);
    ori(ii) = transformReferenceFrame(o,cs,ss);
end

This second method is preferable compared to the median method 1 and already contains the additional check suggested by Ruediger Killian in the following web-link (https://github.com/mtex-toolbox/mtex/issues/245). However, it routinely throws errors as follows:

Error using eig Input to EIG must not contain NaN or Inf.

Error in quaternion/mean (line 23) [V, lambda] = eig(T);

Error in quaternion/mean (line 41) [qm,lambda, V] = mean(q.subSet(id),varargin{:});

Error in orientation/mean (line 42) [q_mean, lambda, eigv] = mean(q,varargin{:});

Error in orientation/cluster (line 124) m = mean(ori.subSet(weights>0),weights(weights>0),'robust');

Thank you in advance.

Regards, Azdi

AzdiarGazder avatar Aug 30 '17 00:08 AzdiarGazder

May I ask why you do not like grains.meanOrientation

Ralf.

ralfHielscher avatar Aug 30 '17 07:08 ralfHielscher

Hi Ralf,

Thank you for looking into this.

The grains.meanOrientation function is perfect when most pixels within a grain comprise orientations that are closely clustered together.

However, when a grain is accommodating deformation heterogeneously during the very early stages of deformation, a median or cluster -based approach to approximating that grain's original orientation is, in my mind, a more reasonable approach to take. For instance, and for the purposes such an approach would be used for, it de-emphasises individual pixels comprising orientations that can be considered as outliers (to serve as an example but not limited to pixels at a grain's boundary/at junctions and/or other small localised areas within a grain) in favour of the majority of other pixels whose orientations remain more closely clustered together.

I hope that the above explanation helps provide you with some justification as to why I am requesting a median/cluster -based approach to computing a grain's orientation.

As I mentioned earlier, I was wondering if:

  • the median value of grains could be available as a function (for example, as grains.medianOrientation) and,
  • if the cluster function could also be available as a function such that it works consistently without throwing an error. (I could be wrong here but I think it throws an error when it encounters the same orientations within a grain.)

Having the median and cluster functions would greatly reduce the computation time taken by a loop.

Thank you again and I look forward to hearing from you.

Regards, Azdi

AzdiarGazder avatar Aug 30 '17 11:08 AzdiarGazder