From 076f53b32a0dfa1fcff15856babbc7c5499be65e Mon Sep 17 00:00:00 2001 From: Timothy Sipkens Date: Tue, 31 Oct 2023 11:46:48 -0400 Subject: [PATCH] Add sharpness to analyze_binary + A binner function. --- +agg/analyze_binary.m | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/+agg/analyze_binary.m b/+agg/analyze_binary.m index 00444da..79175f1 100644 --- a/+agg/analyze_binary.m +++ b/+agg/analyze_binary.m @@ -216,6 +216,15 @@ % The degree of being far from a circle (1: circle, 0: straight line). Aggs0(jj).circularity = 4 * pi * Aggs0(jj).area / (Aggs0(jj).perimeter ^ 2); % circularity + %-- Gradient and sharpness --% + bw = 5; % bandwith on border to gather pixels + [gx, gy] = gradient(double(imgaussfilt(img, 3))); + grad = sqrt(gx.^2 + gy.^2); % norm of gradient + + [grad, ds] = binner(img_binary, grad); + Aggs0(jj).sharp = log10(mean(grad(ds <= bw))) - ... + log10(mean((grad(ds > bw) + eps))); % "+eps" avoids div. by zero + %-- Optical depth --% agg_grayscale = img(Aggs0(jj).binary); % the selected agg's grayscale pixel values gray_extent = max(max(max(img)), 1) - min(min(img)); @@ -304,7 +313,6 @@ - %== GET_PERIMETER2 =============================================================% % An updated method to get the perimeter of the aggregate. % Uses midpoint of straight segments and connects them. @@ -354,6 +362,29 @@ end + +%== BINNER ===============================================================% +% Bin the pixels from the boundary inwards and the report a quantity as a +% function of those bins. Note that statistics will be poor in the center +% of the particle do to a limit number of pixels. +% +% AUTHOR: Timothy Sipkens, Hamed. Nikookar, 2023-10-27 +function [xo, ds] = binner(img_binary, xi) + +d = bwdist(~imdilate(img_binary, ... % distance to outside + strel('disk', 1))); % expand by one pixel to capture some of outside + +ds = 1:max(max(d)); +xo = ones(size(ds)); +for ii=ds + fl = and(d <= ii, d > (ii - 1)); % flag pixels within a unit distance + xo(ii) = mean(xi(fl)); % take the mean of this distance from the outside +end + +end + + + % Order vertices in clockwise order. function [x, y] = poly2cw(x, y)