|
| 1 | +function [res, orientList] = imDirectionalGranulo(img, nOrients, grType, LMax, varargin) |
| 2 | +% Directional granulometries for several orientations. |
| 3 | +% |
| 4 | +% Usage: |
| 5 | +% RES = imDirectionalGranulo(IMG, NORIENT, GRTYPE, LMAX) |
| 6 | +% |
| 7 | +% Input parameters: |
| 8 | +% IMG: input image, 2D gray-level |
| 9 | +% NORIENT: the number of orientations to consider |
| 10 | +% GRTYPE: the type of granulomtry (only 'opening' is supported for now) |
| 11 | +% LMAX: the maximum size of line |
| 12 | +% |
| 13 | +% |
| 14 | +% Example |
| 15 | +% imDirectionalGranulo |
| 16 | +% |
| 17 | +% See also |
| 18 | +% orientedLineStrel |
| 19 | +% |
| 20 | +% Reference |
| 21 | +% The methodology is described in the following article: |
| 22 | +% "Oriented granulometry to quantify fibre orientation distributions in |
| 23 | +% synthetic and plant fibre composite preforms", by V. Gager, D. Legland, |
| 24 | +% A. Bourmaud, A. Le Duigou, F. Pierre, K. Behlouli and C. Baley. (2020), |
| 25 | +% Industrial Crops and Products 152, p. 112548. |
| 26 | +% doi: https://doi.org/10.1016/j.indcrop.2020.112548 |
| 27 | +% |
| 28 | + |
| 29 | + |
| 30 | +% |
| 31 | + |
| 32 | +% ------ |
| 33 | +% Author: David Legland |
| 34 | + |
| 35 | +% Created: 2018-12-18, using Matlab 9.5.0.944444 (R2018b) |
| 36 | +% Copyright 2018 INRA - Cepia Software Platform. |
| 37 | + |
| 38 | + |
| 39 | +%% Input arguments |
| 40 | + |
| 41 | +if ~strcmp(grType, 'opening') |
| 42 | + error('Only ''opening'' granulometry type is currently supported'); |
| 43 | +end |
| 44 | + |
| 45 | + |
| 46 | +%% Initialization |
| 47 | + |
| 48 | +dim = size(img); |
| 49 | + |
| 50 | +% create the list of angles |
| 51 | +orientList = linspace(0, 180, nOrients+1); |
| 52 | +orientList(end) = []; |
| 53 | + |
| 54 | +% create the list of line diameters |
| 55 | +% (consider only odd values to ensure symetry of the strel) |
| 56 | +diamList = 1:2:LMax; |
| 57 | +nSteps = length(diamList); |
| 58 | + |
| 59 | +% allocate memory for global result |
| 60 | +res = zeros([dim nOrients], 'double'); |
| 61 | + |
| 62 | +% allocate memory for intermediate results |
| 63 | +resOp = zeros([dim nSteps+1], 'double'); |
| 64 | + |
| 65 | +% image for normalizing granulometry curves |
| 66 | +refImage = double(img); |
| 67 | +refImage(img <= 0) = 1; |
| 68 | + |
| 69 | + |
| 70 | +%% Main processing |
| 71 | + |
| 72 | +% iterate over orientations |
| 73 | +for iOrient = 1:nOrients |
| 74 | + disp(sprintf('Orient: %d/%d', iOrient, nOrients)); %#ok<DSPS> |
| 75 | + |
| 76 | + % angles from horizontal, in degrees, in CW order |
| 77 | + % (correspond to CCW when visualizing image results) |
| 78 | + theta = -orientList(iOrient); |
| 79 | + |
| 80 | + % iterate over granulometry steps to create a stack of results |
| 81 | + for i = 1:nSteps |
| 82 | + se = orientedLineStrel(diamList(i), theta); |
| 83 | + resOp(:,:,i) = imopen(img, se); |
| 84 | + end |
| 85 | + |
| 86 | + % compute granulometry curve for each pixel |
| 87 | + gr = bsxfun(@rdivide, cat(3, zeros(dim), diff(-resOp, 1, 3)), refImage) * 100; |
| 88 | + |
| 89 | + % compute mean size for each position |
| 90 | + meanSizes = granuloMeanSize(reshape(gr, [numel(img) nSteps+1]), [diamList LMax]); |
| 91 | + |
| 92 | + % stores the mean size for the current orientation |
| 93 | + res(:,:,iOrient) = reshape(meanSizes, size(img)); |
| 94 | +end |
| 95 | + |
0 commit comments