Make calculation on line profile (Intensity) through object on image
Show older comments
Hello, I have an image that I want to approx the size of the central blob.

For this I just create a line profile fo the intensity and just calculate the width corresponding to e.g. 20% of the max-min value (i.e." Y20")
(Data attached)

My function to calc this is below. However it doesn't always perform the caluculation on the correct peak, as in this case. It should be on the more central peak, so the calc I want is the length of the green line and not the blue line.
function [xx,xx2,dx] = calcWidth2(app,scol, AX,frac,mx,mn)
% --------Calcs the 13.5% width (1/e^2), but allows for any
%Outputs x coordinate of 13.5 (or what ever fract) is used
%for the width (dx)
% scol=data (vector)
% AX = axis for plots
% frac= i.e. 0.135 for 13.5% width (1/e^2)
% mx = max(max(scol(:)));
% mn = max(min(scol(:)));
cross=find(scol > val ) % Find values above the Y20 line
% ***********************************************************************
% Perhaps here some logic is required that if there is more
% than 1 peak, use the central one?
%************************************************************************
%Use interp to get better (finer) resolution
n=numel(cross); %get number of point above, then multiply by 20 for finer res
xdataFine=(linspace(cross(1)-1,cross(end)+1,20*n))';
xq=xdataFine; x=1:length(scol); v=scol;
vq2 = interp1(x,v,xq,'linear'); %spline %rloess sgolay
cross=find(vq2 > val );
xx=xdataFine(cross(1));
xx2=xdataFine(cross(end));
dx=xx2-xx;
plot(AX,xdataFine,vq2,'k:','LineWidth',1);
xline(AX,xx,'Color','r','LineStyle','--');
xline(AX,xx2,'Color','r','LineStyle','--');
%text(AX,0.02,0.94,['X',num2str(frac*100),'% = ',num2str(dx,'%.1f'),' pxls'],'Units','normalized','FontSize',11,'Color','r','HorizontalAlignment','left');
hold(AX,'off');
end
I did try this, but it doesn't work if the unwanted peak is at the beginning
cross=find(scol > val )
% Account for multiple peaks
D=diff(cross);
idx=find(D>5);
%size(cross)
cross(idx:end)=[];
Thanks for any help
Accepted Answer
More Answers (1)
Image Analyst
on 11 Mar 2025
To get the size (area), equivalent circular diameter, mean, max, and min intensities of the blob, why not simply threshold and call regionprops. Something like
mask = grayImage > someThreshold;
props = regionprops(mask, 'Area', 'Perimeter', 'MeanIntensity', 'MaxIntensity', 'MinIntensity', 'EquivDiameter');
It's a generic, general purpose demo of how to threshold an image to find blobs, and then measure things about the blobs, and extract certain blobs based on their areas or diameters.
Categories
Find more on Numerical Integration and Differentiation 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!


