Remove small grains from grain reconstruction

1,172 views
Skip to first unread message

Oyak

unread,
Sep 21, 2015, 5:56:07 AM9/21/15
to MTEX
Hello,

I just switched from MTEX 3.5 to 4.1 and have some trouble with adapting my code to the new syntax.

I want to remove grains with a number of measurement points lower than 20 from the grain reconstruction. With MTEX 3.5 the code below did exactly what I wanted to do.

Now the command "grainSize" seems not to work.

Can anyone help and tell me how to modify the code for MTEX 4.1?

Many thanks,
Oyak

% specify crystal and specimen symmetry
CS = crystalSymmetry('m-3m');
SS = specimenSymmetry('-1');
% specify file name
FileName = '*.txt';
% load EBSD data
setMTEXpref('xAxisDirection','North');
setMTEXpref('zAxisDirection','IntoPlane');
ebsd = loadEBSD(FileName,CS,SS,'interface','generic',...
  'ColumnNames', {'Phase' 'x' 'y' 'Euler 1' 'Euler 2' 'Euler 3' 'Mad'},...
  'ignorePhase', 0, 'Bunge', 'Degree');
% restrict to region
region = [xmin ymin xmax-xmin ymax-ymin];
ebsd_region = ebsd(inpolygon(ebsd,region));
% perform grain reconstruction
grains = calcGrains(ebsd_region,'angle',(5*degree));
% remove all grains with less than 20 measurements
grains = grains(grainSize(grains) >= 20);
% perform new grain reconstruction
grains_cleaned = calcGrains(grains,'angle',(5*degree));

Ralf Hielscher

unread,
Sep 21, 2015, 6:02:11 AM9/21/15
to MTEX
just replace the last line by

ebsd_cleaned = ebsd(grains)
grains_cleaned
= calcGrains(ebsd,'angle',(5*degree));

the point is that the ebsd data are not longer stored inside the grains variable. Thus you have to remove the small grains from the ebsd data first and the compute from those cleaned ebsd data new grains.

I hope this helps,

Ralf.

Oyak

unread,
Sep 21, 2015, 6:50:43 AM9/21/15
to MTEX
Hi again,

I did the modification as you suggested. But I get an error message already in the code line

grains = grains(grainSize(grains) >= 20);

Undefined function or variable 'grainSize'.
Error in (line 249)

grains = grains(grainSize(grains) >= 20);

Regards,
Oyak 

ruediger Kilian

unread,
Sep 21, 2015, 7:44:54 AM9/21/15
to mtex...@googlegroups.com
Hi Oyak,
it’s now grains.grainSize, so it would be large_grains = grains(grains.grainSize >=20)

See also https://mtex-toolbox.github.io/files/doc/changelog.html for most other syntax changes.

All the best,
Rüdiger
> --
> If you want to reduce the number of emails you get through this forum login to https://groups.google.com/forum/?fromgroups=#!forum/mtexmail, click "My membership" and select "Don't send me email updates". You can still get emails on selected topics by staring them.
> ---
> You received this message because you are subscribed to the Google Groups "MTEX" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to mtexmail+u...@googlegroups.com.
> Visit this group at http://groups.google.com/group/mtexmail.
> For more options, visit https://groups.google.com/d/optout.

signature.asc

Oyak

unread,
Sep 21, 2015, 8:02:19 AM9/21/15
to MTEX
Hello, sorry to bother you again,

I did what Ralf and Rüdiger suggested, but I still have problems to run the code.

Error message:
Error using subsind (line 56)
There is no grainId stored within your EBSD data. You should compute grains by the command
 
[grains,ebsd.grainId] = calcGrains(ebsd)
Error in EBSD/subsref (line 12)
  ind
= subsind(ebsd,s(1).subs);
Error in untitled (line 258)
ebsd_cleaned
= ebsd(large_grains);


Below again the whole code:

% specify crystal and specimen symmetry
CS
= crystalSymmetry('m-3m');
SS
= specimenSymmetry('-1');
% specify file name
FileName = '*.txt';
% load EBSD data
setMTEXpref
('xAxisDirection','North');
setMTEXpref
('zAxisDirection','IntoPlane');
ebsd
= loadEBSD(FileName,CS,SS,'interface','generic',...
 
'ColumnNames', {'Phase' 'x' 'y' 'Euler 1' 'Euler 2' 'Euler 3' 'Mad'},...
 
'ignorePhase', 0, 'Bunge', 'Degree');
% restrict to region
region
= [xmin ymin xmax-xmin ymax-ymin];
ebsd_region
= ebsd(inpolygon(ebsd,region));
% perform grain reconstruction
grains
= calcGrains(ebsd_region,'angle',(5*degree));
% remove all grains with less than 20
measurements
large_grains
= grains(grains.grainSize >= 20);
% perform new grain reconstruction
ebsd_cleaned
= ebsd(large_grains);
grains_cleaned
= calcGrains(ebsd_cleaned,'angle',(5*degree));








Ralf Hielscher

unread,
Sep 21, 2015, 2:45:19 PM9/21/15
to MTEX
Hi Oyak,

sorry I overlooked this. You should exactly do what the error message suggests: 


%// perform grain reconstruction
[grains, ebsd_region.grainId] = calcGrains(ebsd_region,'angle',5*degree);

% remove all grains with less than 20
measurements
large_grains
= grains(grains.grainSize >= 20);


%// perform new grain reconstruction
ebsd_cleaned
= ebsd_region(large_grains);
[grains_cleaned, ebsd_cleaned.grainId] = calcGrains(ebsd_cleaned,'angle',5*degree);

Ralf.

davisola

unread,
Nov 17, 2015, 12:11:53 PM11/17/15
to MTEX
Hi, I had the same problem trying to clean my ebsd data.
As the helper advice, I loaded the ebsd data of the large grains using the GrainsID list, something like:

% perform grain reconstruction
[grains,GrainsID]
= calcGrains(ebsd_region,'angle',(5*degree));

% remove all grains with less than 20
measurements
large_grains
= GrainsID(grains.grainSize >= 20);
% perform new grain reconstruction
ebsd_cleaned
= ebsd(large_grains);

grains_cleaned
= calcGrains(ebsd_cleaned,'angle',(5*degree
));

It works, however the results are not so good, The ebsd data loaded seems incomplete, as the size of the file created is equal to the number of grains found by the condition:
large_grains = GrainsID(grains.grainSize >= 20);


So, I also didn't achieve good results using this cleaning procedure.


Luiz Morales

unread,
Nov 17, 2015, 12:21:05 PM11/17/15
to mtex...@googlegroups.com
Hi Davison


Try to modify the following (from David Mainprice) for your own samples. It works quite well for me, when comparinf the maps with FSE images


cheers


Luiz



%% Grain modelling
%**************************************************************************
%
% You can loop over this cell changing segmentation angle and the
% the 'keepNotIndexed' options
% You should compared the resulting grain map with EBSD (pixel) phase
% or orientation (pixel) map or Band Contrast map
%**************************************************************************
%
%
disp(' ')
disp(' Grain segmentation angle option ')
disp(' Choose a high angle typically between 15 to 10 degrees for geological samples')
disp(' OR choose low angle of 2 degrees if you want to detect sub-grains')
segmentation_angle = input('The segmentation angle (e.g. 2-15):');
segAngle = segmentation_angle*degree;
%
disp(' ')
disp(' Keep non-indexed points option ')
disp('*1= Scientifically correct, not extrapolating raw indexed data')
disp('    model grains BUT keep non-index points : Default in MTEX 4')
disp(' 2= May be more geologically correct in some cases, use with care')
disp('    model grains AND include non-index points within grains boundaries')
disp('    N.B. this option does NOT ADD map pixels with neighbouring ORIENTATIONS')
non_indexed_option = input('Option an integer  (1-2):');
%
% keep non-indexed in now default in MTEX4
if(non_indexed_option == 1)
    [grains,ebsd.grainId,ebsd.mis2mean] = calcGrains(ebsd,'angle',segAngle)
end
% remove non-indexed points, restrict to indexed points only
if(non_indexed_option == 2)
    [grains,ebsd.grainId,ebsd.mis2mean] = calcGrains(ebsd('indexed'),'angle',segAngle)
end
% number of grains all phases 
number_of_calcGrains = grains.length
% plot 'grain' phase map
figure
% Correct MatLab problem with colour buffer
set(gcf,'renderer','zbuffer')
% Default phase map
plot(grains,'figSize','large')

 

saveFigure('/Users/luizfgmorales/Matlab_programs/serpentinite_987/987-X/987_X_phase_map_grains.tif')
%
%**************************************************************************
%% Removing small grains - not representative small grains, may be errors
%**************************************************************************
%
% You can loop over this cell changing number of indexed points per grain
% You should compared the resulting grain map with EBSD (pixel) phase
% or orientation (pixel) map
%**************************************************************************
%
disp(' ')
disp(' Small grains option ')
disp(' Remove small grains containing less than a critical')
disp(' number of indexed points as they error prone or ')
disp(' If you require an accurate grain size and shape analysis')
disp(' the recommended minimum number indexed points per grain size is 10')
disp(' You can decide to keep all grain by accepting all grains with 0')
small_grains_option = input('Indexed points per grain an integer (e.g. 0-10):');
%
% remove grains containing less than critical number of indexed points, 
selected_grains = grains(grains.grainSize > small_grains_option);
% number of small grains removed from all phase
number_of_small_grains_removed = number_of_calcGrains - selected_grains.length
%n_Olivine_grains = selected_grains('Olivine').length
figure
% Correct MatLab problem with colour buffer
set(gcf,'renderer','zbuffer')
% MTEX 4 default map is phase map
plot(selected_grains,'figSize','large')

 

saveFigure('/Users/luizfgmorales/Matlab_programs/serpentinite_987/987-X/987_X_phase_map_grains_with_removed.tif')


Ralf Hielscher

unread,
Nov 17, 2015, 5:12:59 PM11/17/15
to MTEX
Hi Davisola,

maybe should explain a bit more in detail why you are unsatisfied with the result and what you actually want to achieve. 

By you commands above you removed all EBSD data that belong to small grains. Hence, you should expect the data to look incomplete. Maybe you want to fill them?

Ralf.

davisola

unread,
Nov 20, 2015, 11:39:51 AM11/20/15
to MTEX
Ok, I will explain.
that is my ebsd data:
ebsd = EBSD (show methods, plot)
 
 Phase  Orientations     Mineral       Color  Symmetry  Crystal reference frame
    -1   21716 (26%)  notIndexed                                              
     0   61159 (74%)              light blue       432                        
 
 Properties: confidenceindex, fit, imagequality, semsignal, x, y
 Scan unit : um

{ plot(ebsd('0'),ebsd('0').orientations);
% ('0') is the group of indexed points }



then I proceed with the reconstruction of grains
{ [grains,grainsID] = calcGrains(ebsd,'angle',15*degree) };

that is the grains and grainsID file:

grains = grain2d (show methods, plot)
 
 Phase  Grains  Pixels     Mineral  Symmetry  Crystal reference frame
    -1    2764   21716  notIndexed                                  
     0    1372   61159                   432                        
 
 Properties: GOS, meanRotation

The grainsID is a double class file with size 82857x1 ( the same size of ebsd file)

Then, I select only those grains with grainSize bigger than 10 pixels

{ valid_grains = grainsID( grains.grainSize > 10); }

It results in a double class file with size 865x1 ( remarkably smaller than the grainsID file)
If I gather only the ebsd data of these file:

{ ebsd_clean = ebsd(valid_grains); }
It results in a EBSD class file with the same size of the valid_grains file. It is not possible to plot this data because the mtex said: there is no indexed points in these file.

I hope It become understandable now.

Auto Generated Inline Image 1

Rüdiger Kilian

unread,
Nov 21, 2015, 1:32:41 AM11/21/15
to mtex...@googlegroups.com
Hi,
how about: valid_grains = grains( grains.grainSize > 10); ?
Cheers,
Rüdiger




From: mtex...@googlegroups.com [mtex...@googlegroups.com] on behalf of davisola [davis...@gmail.com]
Sent: Friday, November 20, 2015 5:39 PM
To: MTEX
Subject: {MTEX} Re: Remove small grains from grain reconstruction

davisola

unread,
Nov 22, 2015, 5:00:26 PM11/22/15
to MTEX, ruedige...@unibas.ch
Ebsd data aren't loaded from files of the grain2d class, at least in my Mtex 4.1

Ralf Hielscher

unread,
Nov 22, 2015, 5:11:44 PM11/22/15
to MTEX
Hi davisola,

your code has a logical error. You should do

[grains, ebsd.grainId] = calcGrains(ebsd,'angle',15*degree)

valid_grains
= grains( grains.grainSize > 10);

ebsd_clean
= ebsd(valid_grains);

Ralf.

davisola

unread,
Nov 23, 2015, 10:34:09 AM11/23/15
to MTEX
It doesn't work. I can select only large grains by:

valid_grains = grains( grains.grainSize >= 10);

However, I can't load the ebsd data because when I type the comand:

ebsd_clean = ebsd(valid_grains);

The follow message appear on the Matlab prompt:


"Error using subsind (line 56)
There is no grainId stored within your EBSD data. You should compute grains by the command

  [grains,ebsd.grainId] = calcGrains(ebsd)


Error in EBSD/subsref (line 12)
  ind = subsind(ebsd,s(1).subs);"


So, the same problem quoted by our friend above.

ruediger Kilian

unread,
Nov 23, 2015, 10:38:52 AM11/23/15
to mtex...@googlegroups.com
Hi Davisola,
what is the output of ebsd? Does it have grainId?
Cheers,
Rüdiger
signature.asc

Ralf Hielscher

unread,
Nov 23, 2015, 10:40:04 AM11/23/15
to MTEX
Hi davisola ,

the error message gives you exactly the reason what you probably did wrong. In you first post you did

[grains, grainIds] = calcGrains(ebsd,'angle',15*degree)

whereas in my post I suggested you to do (and what also the error message tells you to do)

[grains, ebsd.grainId] = calcGrains(ebsd,'angle',15*degree)

after this 

ebsd(grains(1))

should give you all EBSD data that belong to grain 1.

Ralf.

davisola

unread,
Nov 24, 2015, 6:30:51 AM11/24/15
to mtex...@googlegroups.com
Now I got It!

I did not get good results before, using "ebsd.grainId".
Now I tested it typing:
" [grains,ebsd.grainId] = calcGrains(ebsd,'angle',15*degree); "
and it works!  a new property was created on the ebsd file.

Possibly there was an syntax mistake before. I'm sure it will works now.

Danke schön!

Reply all
Reply to author
Forward
0 new messages