Commit 74d27a59 authored by Jean-Yves TINEVEZ's avatar Jean-Yves TINEVEZ
Browse files

Revamp plotting methods.

We want to trim the fat.
parent d7f5a8e5
......@@ -71,8 +71,17 @@ dpr = deproj.from_heightmap( ...
%% Plot morphological parameters.
close all
plot_sizes( dpr );
plot_fit_plane( dpr );
plot_fit_ellipse( dpr );
plot_curvatures( dpr );
plot_distorsions( dpr );
fprintf( 'Plotting the cell sizes.\n' )
dpr.figure_cell_sizes;
fprintf( 'Plotting the tissue orientation.\n' )
dpr.figure_tissue_orientation;
fprintf( 'Plotting the cell elongation and direction.\n' )
dpr.figure_cell_elongation;
fprintf( 'Plotting the impact of projection distorsion.\n' )
dpr.figure_distorsions;
fprintf( 'Finished.\n' )
......@@ -48,8 +48,17 @@ dpr = deproj.from_bellaiche( ...
%% Plot morphological parameters.
close all
plot_sizes( dpr );
plot_fit_plane( dpr );
plot_fit_ellipse( dpr );
plot_curvatures( dpr );
plot_distorsions( dpr );
fprintf( 'Plotting the cell sizes.\n' )
dpr.figure_cell_sizes;
fprintf( 'Plotting the tissue orientation.\n' )
dpr.figure_tissue_orientation;
fprintf( 'Plotting the cell elongation and direction.\n' )
dpr.figure_cell_elongation;
fprintf( 'Plotting the impact of projection distorsion.\n' )
dpr.figure_distorsions;
fprintf( 'Finished.\n' )
function hts = add_ellipse_variable( obj, values, cmap, ax )
%ADD_ELLIPSE_VARIABLE Plots the ellipses, colored by the specified values.
epicells = obj.epicells;
n_objects = numel( epicells );
hts = NaN( 2 * n_objects, 1 );
minv = min( values );
maxv = max( values );
colors = colormap( cmap );
if n_objects > 1000, lw = 1; else, lw = 2; end
idx = @(v) 1 + round( (v - minv)/(maxv - minv) * ( size( colors, 1 ) - 1 ) );
for i = 1 : n_objects
o = epicells( i );
h1 = o.plot_ellipse_3d( 23, ax );
h2 = o.plot_ellipse_3d( 3, ax );
hts( 2 * i - 1 ) = h1;
hts( 2 * i ) = h1;
val = values( i );
j = idx( val );
set( [ h1 h2 ], ...
'Color', colors( j, : ), ...
'LineWidth', lw )
end
set( ax, 'CLim', [ minv maxv ] )
end
function hts = add_plot_area( obj, ax )
%ADD_PLOT_AREA Add the tissue plot colored with the cell area.
epicells = obj.epicells;
areas = vertcat( epicells.area );
hts = add_plot_variable( obj, areas, ax );
end
function hts = add_plot_curvature_gauss( obj, ax )
%ADD_PLOT_CURVATURE_GAUSS Add the tissue plot colored with the Gaussian curvature.
epicells = obj.epicells;
curvs = vertcat( epicells.curvatures );
gauss_curv = curvs( :, 2 );
hts = add_plot_variable( obj, gauss_curv, ax );
end
function hts = add_plot_curvature_k1( obj, ax )
%ADD_PLOT_CURVATURE_K1 Add the tissue plot colored with the first principal curvature.
epicells = obj.epicells;
curvs = vertcat( epicells.curvatures );
k1_curv = curvs( :, 3 );
hts = add_plot_variable( obj, k1_curv, ax );
end
function hts = add_plot_curvature_k2( obj, ax )
%ADD_PLOT_CURVATURE_K2 Add the tissue plot colored with the first principal curvature.
epicells = obj.epicells;
curvs = vertcat( epicells.curvatures );
k2_curv = curvs( :, 4 );
hts = add_plot_variable( obj, k2_curv, ax );
end
function hts = add_plot_curvature_mean( obj, ax )
%ADD_PLOT_CURVATURE_MEAN Add the tissue plot colored with the mean curvature.
epicells = obj.epicells;
curvs = vertcat( epicells.curvatures );
mean_curv = curvs( :, 1 );
hts = add_plot_variable( obj, mean_curv, ax );
end
function hts = add_plot_distorsion_area( obj, ax )
%ADD_PLOT_DISTORSION_AREA Add the tissue plot colored with the error on
%cell area caused by the projection.
epicells = obj.epicells;
areas = vertcat( epicells.area );
uncorr_areas = vertcat( epicells.uncorrected_area );
err = 1 - uncorr_areas ./ areas;
hts = add_plot_variable( obj, 100. * err, ax );
end
function hts = add_plot_distorsion_perimeter( obj, ax )
%ADD_PLOT_DISTORSION_PERIMETER Add the tissue plot colored with the error on
%cell perimeter caused by the projection.
epicells = obj.epicells;
perims = vertcat( epicells.perimeter );
uncorr_perims = vertcat( epicells.uncorrected_perimeter );
err = 1 - uncorr_perims ./ perims;
hts = add_plot_variable( obj, 100. * err, ax );
end
function hts = add_plot_euler_alpha( obj, ax )
%ADD_PLOT_EULER_ALPHA Add the tissue plot colored with the 1st euler angle.
epicells = obj.epicells;
angles = vertcat( epicells.euler_angles );
alphas = rad2deg( angles( :, 1 ) );
% Wrap back to 0 - 180º.
neg_alphas = alphas < 0;
alphas( neg_alphas ) = 180 + alphas( neg_alphas );
hts = add_plot_variable( obj, alphas, ax );
end
function hts = add_plot_euler_beta( obj, ax )
%ADD_PLOT_EULER_BETA Add the tissue plot colored with the 2nd euler angle.
epicells = obj.epicells;
angles = vertcat( epicells.euler_angles );
betas = rad2deg( angles( :, 2 ) );
% Wrap back to 0 - 90º.
large_betas = betas > 90;
betas( large_betas ) = 180 - betas( large_betas );
hts = add_plot_variable( obj, betas, ax );
end
function hts = add_plot_euler_gamma( obj, ax )
%ADD_PLOT_EULER_GAMMA Add the tissue plot colored with the 3rd euler angle.
epicells = obj.epicells;
angles = vertcat( epicells.euler_angles );
gammas = rad2deg( angles( :, 3 ) );
neg_gammas = gammas < 0;
gammas( neg_gammas ) = 180 + gammas( neg_gammas );
hts = add_plot_variable( obj, gammas, ax );
end
function hts = add_plot_id( obj, ax )
%ADD_PLOT_ID Add the epicell ids to the specified plot axes.
function hts = add_plot_ids( obj, ax )
%ADD_PLOT_IDS Add the epicell ids to the specified plot axes.
epicells = obj.epicells;
n_objects = numel( epicells );
......
function hts = add_plot_perimeter( obj, ax )
%ADD_PLOT_PERIMETER Add the tissue plot colored with the cell perimeter.
epicells = obj.epicells;
perims = vertcat( epicells.perimeter );
hts = add_plot_variable( obj, perims, ax );
end
......@@ -33,69 +33,35 @@ classdef deproj
%% Generate figures.
% Figure with the local plan orientation for a collection of epicells.
[ hf, ax1, ax2, ax3 ] = plot_fit_plane( obj, scale_bar_length )
% Figure with the local tissue orientation for a collection of epicells.
[ hf, ax1, ax2, ax3 ] = figure_tissue_orientation( obj, scale_bar_length )
% Plot the 2D ellipses on the tissue surface.
[ hf, hc, he ] = plot_fit_ellipse( obj, scale_bar_length )
% Plot the cell elongation and 2D orientation with cells as 2D ellipses.
[ hf, ax1, ax2 ] = figure_cell_elongation( obj, scale_bar_length )
% Figure with the local curvaure for a collection of epicells.
[ hf, ax1, ax2, ax3 ] = plot_curvatures( obj, scale_bar_length )
[ hf, ax1, ax2, ax3 ] = figure_curvatures( obj, scale_bar_length )
% Figure with the cells area and perimeter.
[ hf, ax1, ax2 ] = plot_sizes( obj, scale_bar_length )
[ hf, ax1, ax2 ] = figure_cell_sizes( obj, scale_bar_length )
% Figure with the error on uncorrected cells area and perimeter.
[ hf, ax1, ax2 ] = plot_distorsions( obj, scale_bar_length )
[ hf, ax1, ax2 ] = figure_distorsions( obj, scale_bar_length )
%% Helpers.
% They are public in case of.
% Add the tissue plot colored with the 1st euler angle.
hts = add_plot_euler_alpha( obj, ax )
% Add the tissue plot colored with the 2nd euler angle.
hts = add_plot_euler_beta( obj, ax )
% Add the tissue plot colored with the 3rd euler angle.
hts = add_plot_euler_gamma( obj, ax )
% Add the epicell ids to the specified plot axes.
hts = add_plot_id( obj, ax )
hts = add_plot_ids( obj, ax )
% Add a scale-bar to the plot.
[ hsb, ht ] = add_plot_scalebar( obj, length, ax )
% Plots the boundaries as patches, colored by the specified values.
hts = add_plot_variable( obj, values, ax )
%Plots the ellipses, colored by the specified values.
hts = add_ellipse_variable( obj, values, cmap, ax )
% Add the tissue plot colored with the mean curvature.
hts = add_plot_curvature_mean( obj, ax )
% Add the tissue plot colored with the Gaussian curvature.
hts = add_plot_curvature_gauss( obj, ax )
% Add the tissue plot colored with the first principal curvature.
hts = add_plot_curvature_k1( obj, ax )
% Add the tissue plot colored with the second principal curvature.
hts = add_plot_curvature_k2( obj, ax )
% Add the tissue plot colored with the cell area.
hts = add_plot_area( obj, ax )
% Add the tissue plot colored with the cell perimeter.
hts = add_plot_perimeter( obj, ax )
% Add the tissue plot colored with the error on cell area caused by the projection.
hts = add_plot_distorsion_area( obj, ax )
% Add the tissue plot colored with the error on cell perimeter caused by the projection.
hts = add_plot_distorsion_perimeter( obj, ax )
% Plot the tissue with the cell exact contours, colored by the specified values.
hts = plot_values_contour( obj, values, ax )
% Plot the tissue with cells as ellipses, colored by the specified values.
hts = plot_values_ellipse( obj, values, cmap, ax, min_val_col, max_val_col )
end
......
function [ hf, ax1, ax2 ] = figure_cell_elongation( obj, scale_bar_length )
%FIGURE_CELL_ORIENTATION Plot the cell elongation and 2D orientation with cells as 2D ellipses.
if nargin < 2
scale_bar_length = 10;
end
hf = figure( 'Position', [ 1204 20 600 650 ] );
%% Direction.
ax1 = subplot( 2, 1, 1 );
cmap1 = 'hsv';
colormap( cmap1 )
hold on
axis equal
values1 = rad2deg( [ obj.epicells.proj_direction ]' );
obj.plot_values_ellipse( values1, cmap1, ax1, -90, 90 );
axis( ax1, 'off' )
colorbar( ax1 )
title( ax1, 'Main orientation of cell (º)', ...
'FontWeight', 'normal' )
%% Elongation.
ax2 = subplot( 2, 1, 2 );
hold on
axis equal
values2 = [ obj.epicells.eccentricity ]';
cmap2 = 'parula';
obj.plot_values_ellipse( values2, cmap2, ax2, 0, 1 );
axis( ax2, 'off' )
colorbar( ax2 )
title( ax2, 'Eccentricity', ...
'FontWeight', 'normal' )
add_plot_scalebar( obj, scale_bar_length, ax2 );
end
function [ hf, ax1, ax2 ] = plot_sizes( obj, scale_bar_length )
%PLOT_SIZES Figure with the cells area and perimeter.
function [ hf, ax1, ax2 ] = figure_cell_sizes( obj, scale_bar_length )
%FIGURE_CELL_SIZES Figure with the cells area and perimeter.
if nargin < 2
scale_bar_length = 10;
end
epicells = obj.epicells;
hf = figure( 'Position', [ 1204 20 600 650 ] );
ax1 = subplot( 2, 1, 1 );
hold on
axis equal
add_plot_area( obj, ax1 );
areas = vertcat( epicells.area );
obj.plot_values_contour( areas, ax1 );
colorbar
ax2 = subplot( 2, 1, 2 );
hold on
axis equal
add_plot_perimeter( obj, ax2 );
perims = vertcat( epicells.perimeter );
obj.plot_values_contour( perims, ax2 );
colorbar
add_plot_scalebar( obj, scale_bar_length, ax2 );
......
function [ hf, ax1, ax2, ax3 ] = plot_curvatures( obj, scale_bar_length )
%PLOT_CURVATURES Figure with the local curvature for a collection of epicells.
function [ hf, ax1, ax2, ax3 ] = figure_curvatures( obj, scale_bar_length )
%FIGURE_CURVATURES Figure with the local curvature for a collection of epicells.
if nargin < 2
scale_bar_length = 10;
end
epicells = obj.epicells;
curvs = vertcat( epicells.curvatures );
hf = figure( 'Position', [ 1204 20 600 1000 ] );
ax1 = subplot( 3, 1, 1 );
hold on
axis equal
add_plot_curvature_mean( obj, ax1 );
mean_curv = curvs( :, 1 );
obj.plot_values_contour( mean_curv, ax1 );
ax2 = subplot( 3, 1, 2 );
hold on
axis equal
add_plot_curvature_k1( obj, ax2 );
k1_curv = curvs( :, 3 );
obj.plot_values_contour( k1_curv, ax2 );
ax3 = subplot( 3, 1, 3 );
hold on
axis equal
add_plot_curvature_k2( obj, ax3 );
k2_curv = curvs( :, 4 );
obj.plot_values_contour( k2_curv, ax3 );
% Collect min & max.
cl1 = get( ax1, 'CLim' );
......@@ -46,7 +55,7 @@ function [ hf, ax1, ax2, ax3 ] = plot_curvatures( obj, scale_bar_length )
c = colorbar(ax3, 'Location', 'EastOutside' );
c.Label.String = sprintf('Curvature (1/%s)', obj.units );
add_plot_scalebar( obj, scale_bar_length, ax3 );
obj.add_plot_scalebar( scale_bar_length, ax3 );
axis( ax1, 'off' )
axis( ax2, 'off' )
......
function [ hf, ax1, ax2 ] = plot_distorsions( obj, scale_bar_length )
function [ hf, ax1, ax2 ] = figure_distorsions( obj, scale_bar_length )
%PLOT_DISTORSIONS Figure with the error on uncorrected cells area and perimeter.
if nargin < 2
......@@ -7,19 +7,28 @@ function [ hf, ax1, ax2 ] = plot_distorsions( obj, scale_bar_length )
hf = figure( 'Position', [ 1204 20 600 650 ] );
epicells = obj.epicells;
ax1 = subplot( 2, 1, 1 );
hold on
axis equal
add_plot_distorsion_area( obj, ax1 );
areas = vertcat( epicells.area );
uncorr_areas = vertcat( epicells.uncorrected_area );
err = 1 - uncorr_areas ./ areas;
obj.plot_values_contour( 100. * err, ax1 );
colorbar
ax2 = subplot( 2, 1, 2 );
hold on
axis equal
add_plot_distorsion_perimeter( obj, ax2 );
perims = vertcat( epicells.perimeter );
uncorr_perims = vertcat( epicells.uncorrected_perimeter );
err = 1 - uncorr_perims ./ perims;
obj.plot_values_contour( 100. * err, ax2 );
colorbar
add_plot_scalebar( obj, scale_bar_length, ax2 );
obj.add_plot_scalebar( scale_bar_length, ax2 );
axis( ax1, 'off' )
axis( ax2, 'off' )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment