Skip to content
Snippets Groups Projects
Commit bc0b7181 authored by Nicola Vigano's avatar Nicola Vigano
Browse files

EBSD/Figures: fixes and new map reading function

parent 0ca368f9
No related branches found
No related tags found
No related merge requests found
function [rot_angle, rot_axis, rot_tensor] = gtDefCalibrateEBSDMap(EBSD_r_map, points, gr, symm)
function [rot_angle, rot_axis, rot_tensor, rot_vec] = gtDefCalibrateEBSDMap(EBSD_r_map, points, gr, symm)
if (~exist('symm', 'var'))
symm = gtCrystGetSymmetryOperators();
end
num_points = numel(gr);
for ii = 1:num_points
% ref_e_vec = extract_from_map(EBSD_e_map, points{ii});
% ref_r_vec = gtMathsEuler2RodInFundZone(ref_e_vec', symm);
ref_r_vec = extract_from_map(EBSD_r_map, points{ii});
ref_r_vec = gtMathsRod2RodInFundZone(ref_r_vec', symm);
% Sometimes the axes definition is not the same
% ref_r_vec = [-ref_r_vec(2), ref_r_vec(3), -ref_r_vec(1)];
gr_r_vec = gr(ii).R_vector;
gr_r_vec = gtMathsRod2RodInFundZone(gr_r_vec', symm);
[rot_vec(ii, :)] = get_angle_axis(ref_r_vec, gr_r_vec, symm); %#ok<AGROW>
% [rot_angle(ii), rot_axis(ii, :)] = get_angle_axis(ref_r_vec, gr_r_vec, symm); %#ok<AGROW>
% Sometimes the axes definition is not the same
% ref_r_vec = [-ref_r_vec(2), ref_r_vec(3), -ref_r_vec(1)];
for ii = num_points:-1:1
ref_r_vec(:, ii) = extract_from_map(EBSD_r_map, points{ii});
gr_r_vec(:, ii) = gr(ii).R_vector;
end
% rot_angle = sum(rot_angle) / num_points;
% rot_axis = sum(rot_axis, 1) / num_points;
% rot_axis = rot_axis / norm(rot_axis);
ref_r_vec = gtMathsRod2RodInFundZone(ref_r_vec, symm);
gr_r_vec = gtMathsRod2RodInFundZone(gr_r_vec, symm);
for ii = num_points:-1:1
rot_vec(ii, :) = get_angle_axis(ref_r_vec(:, ii), gr_r_vec(:, ii), symm);
end
rot_vec = sum(rot_vec, 1) / num_points;
rot_angle = 2 * atand(norm(rot_vec));
......@@ -33,7 +30,9 @@ function [rot_angle, rot_axis, rot_tensor] = gtDefCalibrateEBSDMap(EBSD_r_map, p
end
function r_vec_3 = get_angle_axis(r_vec_1, r_vec_2, symm)
% function [angle, axis] = get_angle_axis(r_vec_1, r_vec_2, symm)
% gtDisorientation should be used, but it seems to be buggy, at least
% for small rotations
% [angle, axis] = gtDisorientation(r_vec_1', r_vec_2', symm);
g1 = gtMathsRod2OriMat(r_vec_1);
......@@ -43,8 +42,6 @@ function r_vec_3 = get_angle_axis(r_vec_1, r_vec_2, symm)
r_vec_3 = gtMathsOriMat2Rod(M);
r_vec_3 = gtMathsRod2RodInFundZone(r_vec_3, symm);
% angle = 2 * atand(norm(r_vec_3));
% axis = r_vec_3 ./ norm(r_vec_3);
end
function r_vec = extract_from_map(EBSD_r_map, points)
......
function EBSD_mask = gtReadEBSDMapIndexingTSVFile(filename)
c = tic();
fprintf('Reading from file: "%s"..', filename);
fid = fopen(filename);
% Skipping the first line
fgets(fid);
input = textscan(fid, ['%d' '\t' '%s' ...
'\t' '%f' '\t' '%f' '\t' '%f' '\t' '%f' '\t' '%f' '\t' '%f' ...
'\t' '%d' '\t' '%d' '\t' '%d' '\t' '%d']);
fclose(fid);
EBSD_mask = cellfun(@(x)strcmpi(x, 'Halite'), input{2});
fprintf('\b\b, Done in %f seconds.\n', toc(c));
end
\ No newline at end of file
......@@ -16,6 +16,8 @@ function gt6DMakePhaseFigureForPaper( phase_mat, phase_id, varargin )
%
conf = struct( ...
'lims_u', [], ...
'lims_v', [], ...
'ipf_plane_normal', [], ...
'use_dmvol', true, ...
'abs_vol', [], ...
......@@ -75,6 +77,20 @@ function gt6DMakePhaseFigureForPaper( phase_mat, phase_id, varargin )
slice_G(~slice_mask) = slice_abs(~slice_mask);
slice_B(~slice_mask) = slice_abs(~slice_mask);
if (~isempty(conf.lims_u))
% Note the inversion between x/y because of matlab's transpose problem
slice_R = slice_R(conf.lims_u(1):conf.lims_u(2), :, :);
slice_G = slice_G(conf.lims_u(1):conf.lims_u(2), :, :);
slice_B = slice_B(conf.lims_u(1):conf.lims_u(2), :, :);
end
if (~isempty(conf.lims_v))
% Note the inversion between x/y because of matlab's transpose problem
slice_R = slice_R(:, conf.lims_v(1):conf.lims_v(2), :);
slice_G = slice_G(:, conf.lims_v(1):conf.lims_v(2), :);
slice_B = slice_B(:, conf.lims_v(1):conf.lims_v(2), :);
end
% Note the inversion between lr/up because of matlab's transpose problem
if (conf.flip_ud)
slice_R = fliplr(slice_R);
......@@ -87,16 +103,19 @@ function gt6DMakePhaseFigureForPaper( phase_mat, phase_id, varargin )
slice_B = flipud(slice_B);
end
final_slice_RGB = cat(3, slice_R', slice_G', slice_B');
f = figure();
ax = axes('Parent', f);
im = imagesc(cat(3, slice_R', slice_G', slice_B'), 'Parent', ax);
im = imagesc(final_slice_RGB, 'Parent', ax);
if (~isempty(conf.clims))
set(ax, 'CLim', conf.clims)
end
set(f, 'Units', 'centimeters')
img_size = size(slice_ids) * conf.pixel_to_cm;
img_size = size(final_slice_RGB) * conf.pixel_to_cm;
img_size = img_size([2 1]);
if (strcmpi(conf.borders, 'no'))
position = [0, 0, img_size];
set(f, 'Position', position)
......
function gt6DRenderEBSDMapIPF(EBSD_r_map, phase_id, varargin)
conf = struct( ...
'mask', [], ...
'ipf_plane_normal', [], ...
'flip_ud', false, ...
'flip_lr', false, ....
'clims', [], ...
'lims_x', [], ...
'lims_u', [], ...
'lims_v', [], ...
'scale', [], ...
'pixel_to_cm', 0.05, ...
'borders', 'no', ...
'colorbar', 'no' );
conf = parse_pv_pairs(conf, varargin);
if (~isempty(conf.lims_x))
if (~isempty(conf.lims_u))
% Note the inversion between x/y because of matlab's transpose problem
EBSD_r_map = EBSD_r_map(:, conf.lims_x(1):conf.lims_x(2), :);
EBSD_r_map = EBSD_r_map(:, conf.lims_u(1):conf.lims_u(2), :);
end
if (~isempty(conf.lims_v))
% Note the inversion between x/y because of matlab's transpose problem
EBSD_r_map = EBSD_r_map(conf.lims_v(1):conf.lims_v(2), :, :);
end
if (~isempty(conf.scale))
% Note the inversion between x/y because of matlab's transpose problem
EBSD_r_map = imresize(EBSD_r_map, 'nearest', 'scale', conf.scale);
end
slice_ids = all(EBSD_r_map ~= 0, 3);
......@@ -31,6 +45,23 @@ function gt6DRenderEBSDMapIPF(EBSD_r_map, phase_id, varargin)
slice_G(indx) = cmap(:, 2);
slice_B(indx) = cmap(:, 3);
if (~isempty(conf.mask))
slice_mask = conf.mask;
if (~isempty(conf.lims_u))
% Note the inversion between x/y because of matlab's transpose problem
slice_mask = slice_mask(:, conf.lims_u(1):conf.lims_u(2), :);
end
if (~isempty(conf.lims_v))
% Note the inversion between x/y because of matlab's transpose problem
slice_mask = slice_mask(conf.lims_v(1):conf.lims_v(2), :, :);
end
slice_R(~slice_mask) = 0;
slice_G(~slice_mask) = 0;
slice_B(~slice_mask) = 0;
end
if (conf.flip_lr)
slice_R = fliplr(slice_R);
slice_G = fliplr(slice_G);
......@@ -47,7 +78,7 @@ function gt6DRenderEBSDMapIPF(EBSD_r_map, phase_id, varargin)
im = imagesc(cat(3, slice_R, slice_G, slice_B), 'Parent', ax);
set(f, 'Units', 'centimeters')
img_size = size(slice_ids) * conf.pixel_to_cm;
img_size = size(slice_ids) .* conf.pixel_to_cm;
img_size = img_size([2 1]);
if (strcmpi(conf.borders, 'no'))
position = [0, 0, img_size];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment