can someone help me to measure the avgferet, avgminferet and area of the edges in my image in this code

1 vue (au cours des 30 derniers jours)
edges = edge(imgContrast,'Canny');
se = strel('disk', 1);
edgesClean = imclose(edges, se);
edgesClean = imfill(edgesClean, 'holes');
zoneMask = zoneMask .* im2double(edgesClean) .* DD;
% Calculate connected components
cc = bwconncomp(zoneMask);
% Calculate region properties for each connected component in this zone
statscc = regionprops(cc, 'Area', 'Centroid', 'Eccentricity', 'Perimeter', 'MajorAxisLength', 'MinorAxisLength','Circularity');
% Calculate features for this zone
numObjects = cc.NumObjects;
if numObjects > 0
areas = [statscc.Area];
profileCounts(k) = numObjects;
totalArea(k) = sum(areas) * pixelSize^2;
zoneArea(k) = sum(zoneMask, 'all') * pixelSize^2;
% Calculate average size of mitochondria for this zone
avgSize(k) = mean(areas) * pixelSize^2;
circularities = [statscc.Circularity];
circularities(circularities > 1) = 1; % Cap circularities greater than 1 at 1
avgCircularity(k) = mean(circularities(isfinite(circularities)));
ferets = [statscc.FeretDiameter];
avgFeret(k) = mean(ferets) * pixelSize;
minFerets = [statscc.MinFeretDiameter];
avgMinFeret(k) = mean(minFerets) * pixelSize;
end
Does this function work? Is this how you properly calculate feret diameters and the other features? Can someone please confirm? Thank you!
  3 commentaires
Chanille
Chanille le 27 Avr 2023
Modifié(e) : Chanille le 27 Avr 2023
@John D'Errico There was a wesite error and I accidentally posted a duplicate question, it was not intentional. Thank you for bringing this to my attention.

Connectez-vous pour commenter.

Réponse acceptée

Kevin Holly
Kevin Holly le 27 Avr 2023
imageData = imread('C1_L1_WDa.jpg');
imshow(imageData)
figure
[rows, columns, numberOfColorChannels] = size(imageData);
if numberOfColorChannels > 1
grayImage = rgb2gray(imageData); % Convert to color.
end
% Apply background subtraction.
grayImage = imtophat(grayImage, strel('disk', 100));
%the lower this number the less lipid droplets
% Apply contrast correction.
grayImage = imadjust(grayImage);
% Apply Gaussian filtering.
grayImage = imgaussfilt(grayImage, 3);
% Apply thresholding.
thresholdValue = graythresh(grayImage);
binaryImage = imbinarize(grayImage, thresholdValue);
% Remove black elongated shapes.
binaryImage = bwareaopen(binaryImage, 200);
binaryImage = imclearborder(binaryImage);
binaryImage = imfill(binaryImage, 'holes');
% mask
% Threshold the image to create a binary mask
gray_img = rgb2gray(imageData); % Convert to color.
threshold = 5;
mask = gray_img > threshold;
% Remove small objects
min_size = 1000;
mask = bwareaopen(mask, min_size);
% Fill holes
mask = imfill(mask, 'holes');
% Erode and dilate the mask to remove noise and smooth edges
se = strel('disk', 5);
mask = imerode(mask, se);
mask = imdilate(mask, se);
% Define the pixel size in square microns
pixelSize = 1;
numZones = 12;
fontSize = 12;
x = 4592.86363636364;
y = 705.954545454545;
% Find out what the max distance will be by computing the distance to each corner.
distanceToUL = sqrt((1-y)^2 + (1-x)^2);
distanceToUR = sqrt((1-y)^2 + (columns-x)^2);
distanceToLL = sqrt((rows-y)^2 + (1-x)^2);
distanceToLR= sqrt((rows-y)^2 + (columns-x)^2);
maxDistance = ceil(max([distanceToUL, distanceToUR, distanceToLL, distanceToLR]));
% Calculate the radius of each zone
radius = linspace(0, maxDistance, numZones+1);
% Preallocate
zonemask = zeros(size(mask,1),size(mask,2),numZones+1);
fig2 = figure;
imshow(mask)
figure(fig2)
c(1) = drawcircle("Center",[x, y],"Radius",radius(1),"LineWidth",1,"Color","b","Visible","off");
% Draw the circles for each zone
for ii = 2:numZones+1
figure(fig2)
c(ii) = drawcircle("Center",[x, y],"Radius",radius(ii),"LineWidth",1,"Color","b","Visible","off");
zonemask(:,:,ii) = createMask(c(ii))-createMask(c(ii-1));
viscircles([x, y], radius(ii), 'LineStyle', '--', 'LineWidth', 1);
total_intensity(ii) = sum(sum(gray_img.*uint8(mask).*uint8(zonemask(:,:,ii)))); % or replace binaryImage with mask
total_zone_pixels(ii) = sum(sum(uint8(mask).*uint8(zonemask(:,:,ii))));
end
mean_intensity_zone = total_intensity./total_zone_pixels
mean_intensity_zone = 1×13
NaN 20.2110 18.5171 18.3373 16.1967 20.3758 21.0019 24.8756 23.1034 23.8200 22.3985 23.9102 16.3538
You need to add 'MaxFeretProperties' and 'MinFeretProperties' as inputs to regionprops
edges = edge(mask,'Canny');
se = strel('disk', 1);
edgesClean = imclose(edges, se);
edgesClean = imfill(edgesClean, 'holes');
zoneMask = mask;
zoneMask = zoneMask .* im2double(edgesClean);% .* DD;
% Calculate connected components
cc = bwconncomp(zoneMask);
% Calculate region properties for each connected component in this zone
statscc = regionprops(zoneMask, 'Area', 'Centroid', 'Eccentricity', 'Perimeter', 'MajorAxisLength', 'MinorAxisLength','Circularity','MaxFeretProperties','MinFeretProperties');
k=1;
statscc
statscc = struct with fields:
Area: 939999 Centroid: [2.3244e+03 851.9382] MajorAxisLength: 5.1200e+03 MinorAxisLength: 1.4472e+03 Eccentricity: 0.9592 Circularity: 1 Perimeter: 0 MaxFeretDiameter: 5.4429e+03 MaxFeretAngle: -164.5824 MaxFeretCoordinates: [2×2 double] MinFeretDiameter: 1462 MinFeretAngle: -90 MinFeretCoordinates: [2×2 double]
% Calculate features for this zone
numObjects = cc.NumObjects;
if numObjects > 0
areas = [statscc.Area];
% profileCounts(k) = numObjects;
totalArea(k) = sum(areas) * pixelSize^2;
zoneArea(k) = sum(zoneMask, 'all') * pixelSize^2;
% Calculate average size of mitochondria for this zone
avgSize(k) = mean(areas) * pixelSize^2;
circularities = [statscc.Circularity];
circularities(circularities > 1) = 1; % Cap circularities greater than 1 at 1
avgCircularity(k) = mean(circularities(isfinite(circularities)));
ferets = [statscc.MaxFeretDiameter];
avgFeret(k) = mean(ferets) * pixelSize;
minFerets = [statscc.MinFeretDiameter];
avgMinFeret(k) = mean(minFerets) * pixelSize;
end
  3 commentaires
Kevin Holly
Kevin Holly le 27 Avr 2023
It looks right to me. I am assuming pixelSize would be a unit conversion and each of these calcuations takes place within a for loop, where the zonemask changes every iteration.
Chanille
Chanille le 28 Avr 2023
I changed how the zones are segmented I think that’s why the circularities are now 1 and the data is behaving stagnant. Can you suggest how to fix this? I’ve attached the full file with picture.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by