can anyone please help me solve the accuracy verification issue with region props? is the performance optimal for measurements? has it been converted to square microns?

3 次查看(过去 30 天)
in my current code the user makes a perfect circle over the completely black region in the image. From the edges of the circle 12 equally distributed "bins" or regions are segmented to the edges of the image. however i would like to verify that the emasuremnts being performed are accurate.
for m = 1:numfiles
fprintf('Processing file #%d of %d : "%s".\n', m, numfiles, allFileNames{m});
MyRGBImage = fullfile(pwd, allFileNames{m});
% Read in image.
imageData = imread(MyRGBImage);
MI = imread(MyRGBImage,1); %%AI channel mitochondria
AI = imread(MyRGBImage,2); %%BI channel LD
LD = imread(MyRGBImage,3); %% just actin
% % % actin, mitochondria and lipids
grayImg = MI + LD + AI;
[rows, columns, numberOfColorChannels] = size(grayImg);
%% Mask for dark regions removal
zgrayImg = im2double(grayImg);
II = zscore(zgrayImg);
% remove speckle
D = wiener2(II,[55,55],10000000/6);
DD = imbinarize(D,-0.2);
%% Uncomment when measuring mitochondria
%% Change between channels by replacing MI, LD or AI as desired, Apply background subtraction, initialized at 25
bg = imopen(MI, strel('disk', 25));
imgNoBg = MI - bg; % change this to the channel to be measured
imgContrast = imadjust(imgNoBg);
% For mitochondria channel
edges = edge(imgContrast,'Canny');
se = strel('disk', 1);
edgesClean = imclose(edges, se);
edgesClean = imfill(edgesClean, 'holes');
for k = 1:numZones
% Create a binary mask for this zone
% zoneMask = (sqrt((X - center(1)).^2 + (Y - center(2)).^2) >= radius(k)) & (sqrt((X - center(1)).^2 + (Y - center(2)).^2) < radius(k+1));
% areaOfEachZone(k) = sum(zoneMask, 'all') * pixelSize^2;
if k == 1
% Create a mask for the first zone based on distance from center
zoneMask = sqrt((X - centerc(1)).^2 + (Y - centerc(2)).^2) < radii(1);
else
% Create a mask for this zone based on distance from center
zoneMask = (sqrt((X - centerc(1)).^2 + (Y - centerc(2)).^2) > radii(k-1)) & (sqrt((X - centerc(1)).^2 + (Y - centerc(2)).^2) < radii(k));
end
% Apply functional mask to the binary mask for this zone
% zoneMask = zoneMask .* im2double(edgesClean) .* DD;
areaOfEachZone(k) = sum(zoneMask, 'all') * pixelSize^2;
zoneMask = zoneMask .* im2double(edgesClean) .* DD;
% Calculate connected components in this zone
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) = areaOfEachZone(k);
% 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.MajorAxisLength];
avgFeret(k) = mean(ferets) * pixelSize;
minFerets = [statscc.MinorAxisLength];
avgMinFeret(k) = mean(minFerets) * pixelSize;
end
end

回答(1 个)

Image Analyst
Image Analyst 2023-4-22
You didn't post the complete file. Can you attach it? What is numZones? 12? Perhaps the other zones are off the end of the image.
  1 个评论
Laura
Laura 2023-4-25
@Image Analyst Attached and below. For the last three months or so I have been trying to verify the measurements of my code are accurate. i set the pixelsize to 1 and then later i convert the measurements to square microns. How can i very that my codes measurements are accurate of the images being measured?
for m = 1:numfiles
fprintf('Processing file #%d of %d : "%s".\n', m, numfiles, allFileNames{m});
MyRGBImage = fullfile(pwd, allFileNames{m});
% Read in image.
imageData = imread(MyRGBImage);
MI = imread(MyRGBImage,1); %%AI channel mitochondria
AI = imread(MyRGBImage,2); %%BI channel LD
LD = imread(MyRGBImage,3); %% just actin
% % % actin, mitochondria and lipids
grayImg = MI + LD + AI;
[rows, columns, numberOfColorChannels] = size(grayImg);
%% Mask for acinus removal
zgrayImg = im2double(grayImg);
II = zscore(zgrayImg);
% remove speckle
D = wiener2(II,[55,55],10000000/6);
DD = imbinarize(D,-0.2);
%% Uncomment when measuring mitochondria
%% Change between channels by replacing MI, LD or AI as desired, Apply background subtraction, initialized at 25
bg = imopen(MI, strel('disk', 25));
imgNoBg = MI - bg; % change this to the channel to be measured
imgContrast = imadjust(imgNoBg);
% For mitochondria channel
edges = edge(imgContrast,'Canny');
se = strel('disk', 1);
edgesClean = imclose(edges, se);
edgesClean = imfill(edgesClean, 'holes');
for k = 1:numZones
% Create a binary mask for this zone
% zoneMask = (sqrt((X - center(1)).^2 + (Y - center(2)).^2) >= radius(k)) & (sqrt((X - center(1)).^2 + (Y - center(2)).^2) < radius(k+1));
% areaOfEachZone(k) = sum(zoneMask, 'all') * pixelSize^2;
if k == 1
% Create a mask for the first zone based on distance from center
zoneMask = sqrt((X - centerc(1)).^2 + (Y - centerc(2)).^2) < radii(1);
else
% Create a mask for this zone based on distance from center
zoneMask = (sqrt((X - centerc(1)).^2 + (Y - centerc(2)).^2) > radii(k-1)) & (sqrt((X - centerc(1)).^2 + (Y - centerc(2)).^2) < radii(k));
end
% Apply functional mask to the binary mask for this zone
% zoneMask = zoneMask .* im2double(edgesClean) .* DD;
areaOfEachZone(k) = sum(zoneMask, 'all') * pixelSize^2;
zoneMask = zoneMask .* im2double(edgesClean) .* DD;
% Calculate connected components in this zone
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) = areaOfEachZone(k);
% 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.MajorAxisLength];
avgFeret(k) = mean(ferets) * pixelSize;
minFerets = [statscc.MinorAxisLength];
avgMinFeret(k) = mean(minFerets) * pixelSize;
end
end
Greatly appreciate it @Image Analyst

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Image Segmentation and Analysis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by