Help Understanding groundTruth for CNN segmentation.

2 次查看(过去 30 天)
I am attempting binary xray segementation using convolutional neural networks in matlab. I have a folder of the preoprocessed images, and a folder of binary segementations which match those images.
The segmentaions are binary so they have two class outputs denoted by a 0 and 1 respectively, "Background", "Cervical_Masks".
My problem stems from using the groundTruth function in matlab.
imds=imageDatastore('Stringtofiles', 'FileExtensions', '.tif', 'IncludeSubfolders', 0, 'LabelSource', 'foldernames');
imds_Masks=imageDatastore('/Stringtofiles', 'FileExtensions', '.tif', 'IncludeSubfolders', 0, 'LabelSource', 'foldernames');
groundT=groundTruthDataSource(imds);
ldc = labelDefinitionCreator();
addLabel(ldc,'Cervical_Masks',labelType.PixelLabel);
addLabel(ldc,'Background',labelType.PixelLabel, PixeWhenlLabelID.0);
labelDefs = create(ldc);
labelData=table(imds_Masks.Files, 'VariableNames', {'PixelLabelData'});
gTruth = groundTruth(groundT,labelDefs,labelData);
[imds,pxds] = pixelLabelTrainingData(gTruth);
After this point my data is wrong.
Simply checking it for any subject reveals that the pxds file which should represent the mask is incorrect.
subject=22
I = readimage(imds,subject);
C = readimage(pxds,subject);
imshowpair(I,uint8(C),'montage')
I think this is because I am not using the labeling correct.
Could someone please help?
Thanks!

回答(2 个)

Anshika Chaurasia
Anshika Chaurasia 2021-9-17
编辑:Anshika Chaurasia 2021-9-17
Hi,
On looking the provided code, the possible reason for incorrect label could be in following line:
addLabel(ldc,'Background',labelType.PixelLabel, PixeWhenlLabelID.0);
I am not sure about "PixeWhenlLabelID.0".
It would be better if you can share the images or some test code. It would be easy for us to reproduce your issue at our end.
Refer to the following blog:

yanqi liu
yanqi liu 2021-9-28
sir,please check the follow code to get some information
clc; clear all; close all;
% image file
data = load('stopSignsAndCars.mat');
imageFilenames = data.stopSignsAndCars.imageFilename(1:2)
imageFilenames = 2×1 cell array
{'stopSignImages/image001.jpg'} {'stopSignImages/image002.jpg'}
imageFilenames = fullfile(toolboxdir('vision'),'visiondata',imageFilenames);
dataSource = groundTruthDataSource(imageFilenames);
% label
ldc = labelDefinitionCreator();
addLabel(ldc,'stopSign',labelType.Rectangle);
addLabel(ldc,'carRear',labelType.Rectangle);
labelDefs = create(ldc)
labelDefs = 2×5 table
Name Type LabelColor Group Description ____________ _________ __________ ________ ___________ {'stopSign'} Rectangle {0×0 char} {'None'} {' '} {'carRear' } Rectangle {0×0 char} {'None'} {' '}
% add target
stopSignTruth = {[856 318 39 41];[445 523 52 54]};
carRearTruth = {[398 378 315 210];[332 633 691 287]};
% make label
labelNames = {'stopSign';'carRear'};
labelData = table(stopSignTruth,carRearTruth,'VariableNames',labelNames)
labelData = 2×2 table
stopSign carRear _________________ ___________________ {[856 318 39 41]} {[398 378 315 210]} {[445 523 52 54]} {[332 633 691 287]}
% display
gTruth = groundTruth(dataSource,labelDefs,labelData)
gTruth =
groundTruth with properties: DataSource: [1×1 groundTruthDataSource] LabelDefinitions: [2×5 table] LabelData: [2×2 table]
figure; imshow(gTruth.DataSource.Source{1});
hold on;
rectangle('Position', gTruth.LabelData.stopSign{1}, 'EdgeColor', 'g', 'LineWidth', 2);
rectangle('Position', gTruth.LabelData.carRear{1}, 'EdgeColor', 'c', 'LineWidth', 2);

类别

Help CenterFile Exchange 中查找有关 Image and Video Ground Truth Labeling 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by