I am trying to measure the Feret diameter of microscopic particles using MATLAB. I have attached the code below, having issue while implementing the MaxFeretProperties
. Please suggest how I can execute to get the particle size distribution? Attached below is the code:
clc
clear all;
img = imread('image.tif');
imshow(img);
img_gray = rgb2gray(img);
imshow(img_gray, [0 150]);
cropped = imcrop(img_gray,[1 1 2040 1418]);%select the top left and bottom right of the rectangle
imshow(cropped);
threshold = 150;
[r,c] = size(cropped);
for i=1:r
for j=1:c
if cropped(i,j)<150
im(i,j)=1;
end
end
end
imshow(im);
bw = imbinarize(im,'adaptive');
bw = imfill(bw,'holes');
cc = bwconncomp(bw);
[L,N] = bwlabel(bw);
%blobs = regionprops(L,'BoundingBox')
stats = regionprops('table', bw, 'Centroid','MajorAxisLength','MinorAxisLength');
ft = regionprops( bw, 'MaxFeretProperties');
The output of this program is as follows:
Error using regionprops>getPropsFromInput (line 1279)
Expected input number 1, PROPERTIES, to match one of these strings:
'Area', 'Centroid', 'BoundingBox', 'SubarrayIdx', 'MajorAxisLength', 'MinorAxisLength', 'Eccentricity',
'Orientation', 'ConvexHull', 'ConvexImage', 'ConvexArea', 'Image', 'FilledImage', 'FilledArea',
'EulerNumber', 'Extrema', 'EquivDiameter', 'Solidity', 'Extent', 'PixelIdxList', 'PixelList',
'Perimeter', 'PerimeterOld', 'PixelValues', 'WeightedCentroid', 'MeanIntensity', 'MinIntensity',
'MaxIntensity'
The input, 'MaxFeretProperties', did not match any of the valid strings.
Error in regionprops>ParseInputs (line 1244)
reqStats = getPropsFromInput(startIdxForProp, ...
Error in regionprops (line 205)
[I,requestedStats,officialStats] = ParseInputs(imageSize, argOffset, varargin{:});
Error in feret (line 25)
ft = regionprops( bw, 'MaxFeretProperties');
I am able to obtain the MajorAxisLength
and MinorAxisLength
.
The error message says “The input, 'MaxFeretProperties', did not match any of the valid strings.” This is a pretty clear indication of what is wrong: you are requesting features that the regionprops
function does not know.
Note that 'MaxFeretProperties' has been introduced very recently as a feature in regionprops
. You likely have a version of MATLAB from before this change. You will need to upgrade your MATLAB version to use this functionality.