@Kevin Holly I was wondering if you can please help me to determine that this is accuracte measurment of the edges as determined by the code above. Thank you.
can someone help me to measure the avgferet, avgminferet and area of the edges in my image in this code
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Chanille
am 27 Apr. 2023
Kommentiert: Chanille
am 28 Apr. 2023
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 Kommentare
Akzeptierte Antwort
Kevin Holly
am 27 Apr. 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
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
% 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 Kommentare
Kevin Holly
am 27 Apr. 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.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!