Effacer les filtres
Effacer les filtres

Adapting the gTruthtoXY helper function

1 vue (au cours des 30 derniers jours)
Lilly
Lilly le 14 Fév 2023
Commenté : Lilly le 23 Fév 2023
I'm currently trying to implement the "Convert Image Labeler Polygons to Labeled Blocked Image for Semantic Segmentation" tutorial to solve an issue generating masks for hand MRIs (DICOM images) in which polygons have been used to label each individual bones with each of the 10 bones labelled being considered a seperate class
I need to create masks indicating the position for all bones to train a DL network to segment this automatically. However I'm having a hard time with it considering I've used polygons and I ideally need pixel classification labels. The tutorial seems to outline a way to get the output that I need but I need to modify the help function (gTruthtoXY) to include all 10 classes of bones within the mask. The current helper function only includes 2. How would I go about modifying this helper function?
Supporting Function
gTruthtoXY converts the polygon ROI coordinates and label data stored in the table labelData into cell arrays suitable for input into the polyToBlockedImage function.
function [roiPositions,roiLabels] = gTruthtoXY(labelData)
totalROIs = numel(labelData{1,1}) + numel(labelData{1,2}{:});
roiPositions = cell(totalROIs,1);
roiLabels = zeros(totalROIs,1);
% Obtain label names from the labelData table
labelName = labelData.Properties.VariableNames;
roiIdx = 1; % Initialize ROI index
% Loop through all labels
% Assign a numeric label of 2 to tumor tissue; 1 for normal tissue
for j = 1:numel(labelData)
% All ROIs for a given label
data = labelData{1,j}{:};
if(isequal(labelName{j},"tumor"))
for k = 1:numel(data)
roiLabels(roiIdx) = 2;
roiPositions{roiIdx} = data{k};
roiIdx = roiIdx + 1;
end
else
% For other ROI labels
roiLabels(roiIdx) = 1;
roiPositions{roiIdx} = data;
roiIdx = roiIdx + 1;
end
end
end
Any help much appreciated! Thanks

Réponses (1)

Yuvraj Singh
Yuvraj Singh le 23 Fév 2023
Hi Lily,
To achieve the expected result.
Update the calculation of "totalROIs
You would have to add ROIs for different labels.
%Calculating total ROIs if tumor_type_n is a cell type
totalROIs_tumor_type_n = numel(labelData{1,n}{:});
%Calculating total ROIs if tumor_type_n is a double vector
totalROIs_tumor_type_m = numel(labelData{1,m});
totalROIs = totalROIs_tumor_type_1 + totalROIs_tumor_type_2 ....
+ totalROIs_tumor_type_10
Add additional condition in for loop for different label types.
if(isequal(labelName{j},"tumor_type_1"))
elseif(isequal(labelName{j},"tumor_type_2"))
.
.
.
.
.
.
elseif(isequal(labelName{j},"tumor_type_9"))
else
end
Add labelling code in the if condition. It varies if label is a double vector or a cell.
%Code inside if condition for tumor_type_n if it is cell type
for k = 1:numel(data)
roiLabels(roiIdx) = n;
roiPositions{roiIdx} = data{k};
roiIdx = roiIdx + 1;
end
%Code inside if condition for tumor_type_m if it is a double vector
roiLabels(roiIdx) = m;
roiPositions{roiIdx} = data;
roiIdx = roiIdx + 1;
  1 commentaire
Lilly
Lilly le 23 Fév 2023
Thank you so much for your answer, I'll implement this and let you know how it goes

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by