Layer Thickness measurement (in pixels) on images
Show older comments
I want to determine the average thickness (in pixels) of a layer I have segmented, such as shown in the figure below:

What I would prefer is to:
- Determine boundary pixels (this would be boundaries = bwboundaries(bwImage) or bwperim(bwImage) which gives you the binary of just the boundary pixels)
- Determine the pixels of the outer (or inner) edge
- Select a number of evenly spaced boundary pixels of the outer (or inner) edge
- Determine in each of these pixels the slope of the edge by using a minimum number of nearest neighbor pixels belonging to the edge and making a linear fit.
- Determine the distance between the corresponding pixel and the nearest neighbor along the normal (perpendicular) of the slope in each of the pixels of step 3.
- Average all distances and plot the tangents constituting the measured distances on the image (~ 50 measurements)
I've tried to explain the steps in the image given below:

But I don't how to translate this to code (espesially step 2).
1 Comment
Jelle Van Eyken
on 3 Mar 2022
Answers (1)
Image Analyst
on 3 Mar 2022
Edited: Image Analyst
on 3 Mar 2022
One way to do it is to call bwperim(). Then erase the pixels on the top row or right column. Then erase below whatever line you want to erase the slightly wavy bottom edge of the thing. Something like
edgeImage = bwperim(mask);
% Erase top row
edgeImage(1, :) = false;
% Erase right column
edgeImage(:, end) = false;
% Erase below some line
edgeImage(bottomRow : end, :) = false; % You need to define bottomRow in advance.
% Now label each curve
labeledImage = bwlabel(edgeImage, 4);
% Extract left/top edge
leftEdge = ismember(labeledImage, 1);
% Extract right/bottom edge
rightEdge = ismember(labeledImage, 2);
% Then use find to get the coordinates of each
[y1, x1] = find(leftEdge);
[y2, x2] = find(rightEdge);
% Get distances to each
distances = pdist2([x1, y1], [x2, y2]);
% Find the min distance to curve 2 from curve 1
minDistances = min(distances, 2);
% Get average thickness
meanThickness = mean(minDistances);
2 Comments
Jelle Van Eyken
on 7 Mar 2022
Image Analyst
on 7 Mar 2022
Edited: Image Analyst
on 7 Mar 2022
OK, if one side is wavy and you want the width to go "perpendicular" from the opposite side, you can do it your way. Did you do it yet? You can
- use bwboundaries to get the (x,y) coordinates of the edges,
- then smooth the lower edge with something like movmean() or sgolayfilt() (demo attached),
- compute endpoints for a line segment,
- then use improfile() to extract the pixel values along that line,
- then look for the first non-zero pixel.
Categories
Find more on Descriptive Statistics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!